-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathtransition-arc.tsx
More file actions
70 lines (65 loc) · 2.54 KB
/
transition-arc.tsx
File metadata and controls
70 lines (65 loc) · 2.54 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { LayoutGroup, motion } from "framer-motion"
import { useState } from "react"
const ITEM_A = { left: 50, top: 200, width: 100, height: 50 }
const ITEM_B = { left: 450, top: 200, width: 100, height: 50 }
const ITEM_B_NEAR = { left: 60, top: 200, width: 100, height: 50 }
export const App = () => {
const params = new URLSearchParams(window.location.search)
const variant = params.get("variant") || "arc"
const [active, setActive] = useState("a")
const isSmall = variant === "small"
const itemB = isSmall ? ITEM_B_NEAR : ITEM_B
/**
* Place arc and ease at the top level so getValueTransition("layout")
* picks them both up (it falls back to the full transition when no
* "layout" key is present). This mirrors how layout.tsx freezes at 50%.
*/
const transition =
variant === "none"
? { duration: 4, ease: () => 0.5 }
: { duration: 4, ease: () => 0.5, arc: { amplitude: 1 } }
return (
<div
id="container"
style={{ position: "relative", width: "100vw", height: "100vh" }}
>
<button
id="toggle"
onClick={() => setActive(active === "a" ? "b" : "a")}
style={{ position: "fixed", top: 16, left: 16 }}
>
Toggle
</button>
<LayoutGroup id="arc-test">
<div id="item-a" style={{ position: "absolute", ...ITEM_A }}>
{active === "a" && (
<motion.div
id="indicator"
layoutId="indicator"
transition={transition}
style={{
width: 100,
height: 100,
background: "red",
}}
/>
)}
</div>
<div id="item-b" style={{ position: "absolute", ...itemB }}>
{active === "b" && (
<motion.div
id="indicator"
layoutId="indicator"
transition={transition}
style={{
width: 100,
height: 100,
background: "red",
}}
/>
)}
</div>
</LayoutGroup>
</div>
)
}