|
| 1 | +# Components |
| 2 | + |
| 3 | +vueuse/motion allows you to implement your animations directly within the template of your components without the need to wrap target elements in any additional components. |
| 4 | + |
| 5 | +These components work similar to the directive `v-motion` usage but work better in projects using server-side rendering. |
| 6 | + |
| 7 | +## `<Motion>` |
| 8 | + |
| 9 | +Example of a `<Motion>` component using a motion preset on a `<p>` element: |
| 10 | + |
| 11 | +```vue |
| 12 | +<template> |
| 13 | + <Motion is="p" preset="slideVisibleLeft">Text in Motion!</Motion> |
| 14 | +</template> |
| 15 | +``` |
| 16 | + |
| 17 | +<MotionComponent></MotionComponent> |
| 18 | + |
| 19 | +## `<MotionGroup>` |
| 20 | + |
| 21 | +The `<MotionGroup>` can be used to apply motion configuration to all of its child elements, this component is renderless by default and can be used as a wrapper by passing a value to the `:is` prop. |
| 22 | + |
| 23 | +```vue |
| 24 | +<template> |
| 25 | + <MotionGroup preset="slideVisibleLeft" :duration="600"> |
| 26 | + <section> |
| 27 | + <h3>Product 1</h3> |
| 28 | + <p>Description text</p> |
| 29 | + </section> |
| 30 | + <section> |
| 31 | + <h3>Product 2</h3> |
| 32 | + <p>Description text</p> |
| 33 | + </section> |
| 34 | + <section> |
| 35 | + <h3>Product 3</h3> |
| 36 | + <p>Description text</p> |
| 37 | + </section> |
| 38 | + </MotionGroup> |
| 39 | +</template> |
| 40 | +``` |
| 41 | + |
| 42 | +<MotionGroupComponent></MotionGroupComponent> |
| 43 | + |
| 44 | + |
| 45 | +## Props |
| 46 | + |
| 47 | +The `<Motion>` and `<MotionGroup>` components allow you to define animation properties (variants) as props. |
| 48 | + |
| 49 | +- **`is`**: What element should rendered (`div` by default for `<Motion>`). |
| 50 | +- **`preset`**: Motion preset to use (expects camel-case string), see [Presets](/features/presets). |
| 51 | + |
| 52 | +### Variant props |
| 53 | + |
| 54 | +- **`initial`**: Properties the element will have before it is mounted. |
| 55 | +- **`enter`**: Properties the element will have after it is mounted. |
| 56 | +- **`visible`**: Properties the element will have whenever it is within view. Once out of view, the `initial` properties are reapplied. |
| 57 | +- **`visible-once`**: Properties the element will have once it enters the view. |
| 58 | +- **`hovered`**: Properties the element will have when hovered. |
| 59 | +- **`focused`**: Properties the element will have when it receives focus. |
| 60 | +- **`tapped`**: Properties the element will have upon being clicked or tapped. |
| 61 | + |
| 62 | +Variants can be passed as an object using the `:variants` prop. |
| 63 | + |
| 64 | +The `:variants` prop combines with other variant properties, allowing for the definition of custom variants from this object. |
| 65 | + |
| 66 | +Additional variant properties can be explored on the [Variants](/features/variants) page. |
| 67 | + |
| 68 | +### Shorthand Props |
| 69 | + |
| 70 | +We support shorthand props for quickly setting transition properties: |
| 71 | + |
| 72 | +- **`delay`** |
| 73 | +- **`duration`** |
| 74 | + |
| 75 | +These properties apply to `visible`, `visible-once`, or `enter` variants if specified; otherwise, they default to the `initial` variant. |
| 76 | + |
| 77 | +```vue |
| 78 | +<template> |
| 79 | + <Motion |
| 80 | + :initial="{ opacity: 0, y: 100 }" |
| 81 | + :enter="{ opacity: 1, y: 0, scale: 1 }" |
| 82 | + :variants="{ custom: { scale: 2 } }" |
| 83 | + :hovered="{ scale: 1.2 }" |
| 84 | + :delay="200" |
| 85 | + :duration="1200" |
| 86 | + > |
| 87 | + Content to animate! |
| 88 | + </Motion> |
| 89 | +</template> |
| 90 | +``` |
| 91 | + |
0 commit comments