@@ -3,9 +3,11 @@ import {
33 type PropType ,
44 type VNode ,
55 computed ,
6+ inject ,
67 nextTick ,
78 onUpdated ,
89 reactive ,
10+ toRaw ,
911} from 'vue'
1012import type { LooseRequired } from '@vue/shared'
1113import defu from 'defu'
@@ -18,20 +20,15 @@ import type {
1820} from '../types/variants'
1921import { useMotion } from '../useMotion'
2022import { variantToStyle } from './transform'
21-
22- /**
23- * Type guard, checks if passed string is an existing preset
24- */
25- const isPresetKey = ( val : string ) : val is keyof typeof presets => val in presets
23+ import { CUSTOM_PRESETS } from './keys'
2624
2725/**
2826 * Shared component props for <Motion> and <MotionGroup>
2927 */
3028export const MotionComponentProps = {
3129 // Preset to be loaded
3230 preset : {
33- type : String as PropType < keyof typeof presets > ,
34- validator : ( val : string ) => isPresetKey ( val ) ,
31+ type : String as PropType < string > ,
3532 required : false ,
3633 } ,
3734 // Instance
@@ -125,10 +122,24 @@ export function setupMotionComponent(
125122 [ key : number ] : MotionInstance < string , MotionVariants < string > >
126123 } > ( { } )
127124
125+ const customPresets = inject < Record < string , Variant > > ( CUSTOM_PRESETS )
126+
128127 // Preset variant or empty object if none is provided
129- const preset = computed ( ( ) =>
130- props . preset ? structuredClone ( presets [ props . preset ] ) : { } ,
131- )
128+ const preset = computed ( ( ) => {
129+ if ( props . preset == null ) {
130+ return { }
131+ }
132+
133+ if ( customPresets != null && props . preset in customPresets ) {
134+ return structuredClone ( toRaw ( customPresets ) [ props . preset ] )
135+ }
136+
137+ if ( props . preset in presets ) {
138+ return structuredClone ( presets [ props . preset as keyof typeof presets ] )
139+ }
140+
141+ return { }
142+ } )
132143
133144 // Motion configuration using inline prop variants (`:initial` ...)
134145 const propsConfig = computed ( ( ) => ( {
@@ -185,6 +196,15 @@ export function setupMotionComponent(
185196
186197 // Replay animations on component update Vue
187198 if ( import . meta. env . DEV ) {
199+ // Validate passed preset
200+ if (
201+ props . preset != null
202+ && presets ?. [ props . preset as keyof typeof presets ] == null
203+ && customPresets ?. [ props . preset ] == null
204+ ) {
205+ console . warn ( `[@vueuse/motion]: Preset \`${ props . preset } \` not found.` )
206+ }
207+
188208 const replayAnimation = ( instance : MotionInstance < any , any > ) => {
189209 if ( instance . variants ?. initial ) {
190210 instance . set ( 'initial' )
0 commit comments