File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
playground/vite/src/views Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ <script setup lang="ts">
2+ import { ref } from ' vue'
3+ // Use local alias for dev, not 'motion-vue'
4+ import { motion } from ' motion-v'
5+
6+ const show = ref (true )
7+ const toggle = () => (show .value = ! show .value )
8+ const variants = {
9+ initial: { y: 20 , opacity: 0 },
10+ visible: { y: 0 , opacity: 1 },
11+ hidden: { y: 0 , opacity: 0.25 },
12+ }
13+ </script >
14+
15+ <template >
16+ <div style =" padding : 40px " >
17+ <button
18+ data-testid =" toggle-btn"
19+ @click =" toggle"
20+ >
21+ Toggle
22+ </button >
23+ <motion .button
24+ data-testid =" motion-btn"
25+ initial =" initial"
26+ :variants =" variants"
27+ :while-in-view =" show ? 'visible' : 'hidden'"
28+ style =" width : 120px ; height : 40px ; margin-top : 20px "
29+ >
30+ CLICK ME
31+ </motion .button >
32+ </div >
33+ </template >
Original file line number Diff line number Diff line change 1+ import { expect , test } from '@playwright/test'
2+
3+ // This test assumes the Vite dev server is running and the route is /dynamic-variant
4+
5+ test . describe ( 'Variant' , ( ) => {
6+ test ( 'should animate opacity when variant changes' , async ( { page } ) => {
7+ await page . goto ( '/dynamic-variant' )
8+ const motionBtn = page . locator ( '[data-testid="motion-btn"]' )
9+ // Initial: visible
10+ await expect ( motionBtn ) . toHaveCSS ( 'opacity' , '1' )
11+ // Click toggle
12+ await page . click ( '[data-testid="toggle-btn"]' )
13+ // After: hidden
14+ await page . waitForTimeout ( 250 )
15+ await expect ( motionBtn ) . toHaveCSS ( 'opacity' , '0.25' )
16+ // Click toggle again
17+ await page . click ( '[data-testid="toggle-btn"]' )
18+ await page . waitForTimeout ( 250 )
19+ await expect ( motionBtn ) . toHaveCSS ( 'opacity' , '1' )
20+ } )
21+ } )
You can’t perform that action at this time.
0 commit comments