-
-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathuseMotion.ts
45 lines (39 loc) · 1.25 KB
/
useMotion.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { MaybeRef } from 'vue'
import type { MotionInstance, MotionVariants, PermissiveTarget, UseMotionOptions } from './types'
import { useMotionControls } from './useMotionControls'
import { useMotionFeatures } from './useMotionFeatures'
import { useMotionProperties } from './useMotionProperties'
import { useMotionVariants } from './useMotionVariants'
/**
* A Vue Composable that put your components in motion.
*
* @docs https://motion.vueuse.js.org
*
* @param target
* @param variants
* @param options
*/
export function useMotion<T extends string, V extends MotionVariants<T>>(
target: MaybeRef<PermissiveTarget>,
variants: MaybeRef<V> = {} as MaybeRef<V>,
options?: UseMotionOptions,
) {
// Reactive styling and transform
const { motionProperties } = useMotionProperties(target)
// Variants manager
const { variant, state } = useMotionVariants<T, V>(variants)
// Motion controls, synchronized with motion properties and variants
const controls = useMotionControls<T, V>(motionProperties, variants)
// Create motion instance
const instance: MotionInstance<T, V> = {
target,
variant,
variants,
state,
motionProperties,
...controls,
}
// Bind features
useMotionFeatures(instance, options)
return instance
}