Skip to content

Commit 81a8105

Browse files
committed
feat: update motion to 12.16.0 & refactor for more method reuse
1 parent 9a87736 commit 81a8105

File tree

6 files changed

+454
-161
lines changed

6 files changed

+454
-161
lines changed

packages/motion/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
},
7575
"dependencies": {
7676
"@vueuse/core": "^10.0.0",
77-
"framer-motion": "12.12.1",
77+
"framer-motion": "12.16.0",
7878
"hey-listen": "^1.0.8"
7979
},
8080
"devDependencies": {

packages/motion/src/framer-motion.d.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ declare module 'motion-value' {
1616

1717
}
1818

19-
declare module 'framer-main-animation' {
20-
import type { animateValue as animateValueF } from 'framer-motion'
21-
22-
export const animateValue: typeof animateValueF
23-
export type MainThreadAnimation = ReturnType<typeof animateValueF>
24-
}
25-
2619
declare module 'framer-motion/dist/es/projection/node/HTMLProjectionNode.mjs' {
2720
import type { IProjectionNode } from 'framer-motion'
2821

playground/vite/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"preview": "vite preview"
1010
},
1111
"dependencies": {
12+
"motion-plus-vue": "0.1.0",
1213
"motion-v": "workspace:*",
1314
"vue": "^3.4.0",
1415
"vue-router": "^4.5.0"

playground/vite/src/views/test.vue

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<script setup lang="tsx">
2+
/** @jsxImportSource vue */
3+
import { AnimateNumber } from 'motion-plus-vue'
4+
import { motion } from 'motion-v'
5+
import { defineComponent, ref } from 'vue'
6+
7+
const monthlyPrice = 19
8+
const yearlyPrice = 199
9+
const isYearly = ref(true)
10+
11+
const Button = defineComponent({
12+
props: {
13+
isSelected: {
14+
type: Boolean,
15+
required: true,
16+
},
17+
onClick: {
18+
type: Function,
19+
required: true,
20+
},
21+
},
22+
setup(props, { slots }) {
23+
return () => (
24+
<button onClick={props.onClick}>
25+
<motion.span
26+
initial={false}
27+
animate={{
28+
color: props.isSelected ? 'var(--background)' : 'var(--text)',
29+
opacity: props.isSelected ? 1 : 0.5,
30+
}}
31+
>
32+
{slots.default?.()}
33+
</motion.span>
34+
{props.isSelected && (
35+
<motion.div
36+
layoutId="selected"
37+
class="selected"
38+
style={{ borderRadius: 25, zIndex: 1 }}
39+
/>
40+
)}
41+
</button>
42+
)
43+
},
44+
})
45+
</script>
46+
47+
<template>
48+
<div class="price-switcher">
49+
<AnimateNumber
50+
:format="{
51+
style: 'currency',
52+
currency: 'USD',
53+
minimumFractionDigits: 0,
54+
maximumFractionDigits: 0,
55+
}"
56+
locales="en-US"
57+
:suffix="isYearly ? '/yr' : '/mo'"
58+
class="number"
59+
:transition="{
60+
visualDuration: 0.6,
61+
type: 'spring',
62+
bounce: 0.25,
63+
opacity: { duration: 0.2, ease: 'linear' },
64+
}"
65+
:value="isYearly ? yearlyPrice : monthlyPrice"
66+
/>
67+
<div class="switch">
68+
<Button
69+
:is-selected="!isYearly"
70+
:on-click="() => isYearly = false"
71+
>
72+
Monthly
73+
</Button>
74+
<Button
75+
:is-selected="isYearly"
76+
:on-click="() => isYearly = true"
77+
>
78+
Yearly
79+
</Button>
80+
</div>
81+
</div>
82+
</template>
83+
84+
<style>
85+
.price-switcher {
86+
display: flex;
87+
flex-direction: column;
88+
align-items: center;
89+
gap: 20px;
90+
}
91+
92+
.number {
93+
font-size: 96px;
94+
letter-spacing: -0.04em;
95+
font-weight: 530;
96+
font-variation-settings: "opsz" 30, "wght" 530;
97+
}
98+
99+
.number-section-post {
100+
font-size: 32px;
101+
opacity: 0.5;
102+
position: relative;
103+
bottom: 15px;
104+
align-self: flex-end;
105+
margin-left: 5px;
106+
letter-spacing: -0.02em;
107+
}
108+
109+
.switch {
110+
display: flex;
111+
gap: 10px;
112+
padding: 6px;
113+
border-radius: 100px;
114+
background-color: rgba(255, 255, 255, 0.05);
115+
}
116+
117+
.switch button {
118+
position: relative;
119+
padding: 8px 12px;
120+
display: flex;
121+
}
122+
123+
.switch button span {
124+
z-index: 2;
125+
position: relative;
126+
color: var(--text);
127+
will-change: opacity;
128+
font-size: 13px;
129+
line-height: 1;
130+
font-variation-settings: "opsz" 20, "wght" 590;
131+
}
132+
133+
.switch .selected {
134+
position: absolute;
135+
top: 0;
136+
left: 0;
137+
right: 0;
138+
bottom: 0;
139+
background-color: #f5f5f5;
140+
will-change: transform;
141+
}
142+
</style>

playground/vite/vite.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { defineConfig } from 'vite'
22
import vue from '@vitejs/plugin-vue'
3+
import jsx from '@vitejs/plugin-vue-jsx'
34

45
export default defineConfig({
5-
plugins: [vue()],
6+
plugins: [vue(), jsx()],
67
server: {
78
port: 5173,
89
},

0 commit comments

Comments
 (0)