@yamatozhen/design_system 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/app/themes/dark-mc 2.css +0 -51
- package/template/app/themes/light 2.css +0 -51
- package/template/app/themes/light-mc 2.css +0 -51
- package/template/app/themes/theme 2.css +0 -272
- package/template/components/tools/CustomScrollbar 2.tsx +0 -107
- package/template/components/tools/Divider 2.tsx +0 -11
- package/template/components/tools/ReduceMotionContext 2.tsx +0 -5
- package/template/components/tools/Sinewave 2.tsx +0 -206
- package/template/components/tools/SinewaveProgress 2.tsx +0 -140
- package/template/components/tools/badge/Badge 2.tsx +0 -28
- package/template/components/tools/flubber.d 2.ts +0 -7
- package/template/components/tools/input/Input 2.tsx +0 -99
- package/template/components/tools/input/Input.module 2.css +0 -45
- package/template/components/tools/label/Icon 2.tsx +0 -39
- package/template/components/tools/label/Label 2.tsx +0 -150
- package/template/components/tools/mobileViewProvider 2.tsx +0 -53
- package/template/components/tools/ripple/ripple 2.css +0 -38
- package/template/components/tools/ripple/ripple 2.tsx +0 -78
- package/template/components/tools/shape/Shape 2.tsx +0 -313
- package/template/components/tools/shape/Shape.module 2.css +0 -21
- package/template/components/tools/shape/ShapeLoader 2.tsx +0 -104
- package/template/components/tools/shape/ShapePaths 2.ts +0 -116
- package/template/components/tools/switch/Switch 2.tsx +0 -48
- package/template/components/tools/switch/Switch.module 2.css +0 -102
- package/template/components/tools/useBodyScrollLock 2.tsx +0 -27
- package/template/components/tools/useImageColor 2.ts +0 -47
- package/template/components/tools/useNavSheetDrag 2.tsx +0 -196
- package/template/public/fonts/material-symbols/MaterialSymbolsRounded-VariableFont_FILL,GRAD,opsz,wght 2.woff2 +0 -0
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import React, { useLayoutEffect, useRef, useState } from "react";
|
|
3
|
-
import {
|
|
4
|
-
motion,
|
|
5
|
-
animate,
|
|
6
|
-
useMotionValue,
|
|
7
|
-
useTransform,
|
|
8
|
-
easeInOut,
|
|
9
|
-
} from "framer-motion";
|
|
10
|
-
import Icon from "./Icon";
|
|
11
|
-
|
|
12
|
-
type LabelProps = {
|
|
13
|
-
label: string;
|
|
14
|
-
systemName?: string;
|
|
15
|
-
reverse?: boolean;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// One 500ms sequence, all on the wrapper: 0%→50% shrinks+blurs the
|
|
19
|
-
// outgoing text, 50%→100% grows+unblurs the incoming one. The displayed
|
|
20
|
-
// text itself flips at the 250ms midpoint (the blur peak), so the actual
|
|
21
|
-
// DOM content change lands inside the most-obscured frame instead of
|
|
22
|
-
// happening instantly at t=0.
|
|
23
|
-
const SWAP_DURATION = 0.5;
|
|
24
|
-
// Tuple, not a plain array — without `as const` this widens to number[],
|
|
25
|
-
// which doesn't satisfy BezierDefinition and makes animate() fall through
|
|
26
|
-
// to an incompatible overload.
|
|
27
|
-
const SWAP_EASE = [0.01, 1.25, 0.23, 1.01] as const;
|
|
28
|
-
const WIDTH_TRANSITION = {
|
|
29
|
-
duration: SWAP_DURATION,
|
|
30
|
-
ease: SWAP_EASE,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const HORIZONTAL_PADDING = 8;
|
|
34
|
-
|
|
35
|
-
export default function Label({
|
|
36
|
-
label,
|
|
37
|
-
systemName,
|
|
38
|
-
reverse = false,
|
|
39
|
-
}: LabelProps) {
|
|
40
|
-
// label never accepts null/undefined — "" is the only way to make it
|
|
41
|
-
// disappear, so the wrapper's width (and padding) collapse to 0 right
|
|
42
|
-
// along with it.
|
|
43
|
-
const hasLabel = label !== "";
|
|
44
|
-
const measureRef = useRef<HTMLSpanElement>(null);
|
|
45
|
-
const width = useMotionValue(0);
|
|
46
|
-
const scale = useMotionValue(1);
|
|
47
|
-
const blurPx = useMotionValue(0);
|
|
48
|
-
const filter = useTransform(blurPx, (v) => `blur(${v}px)`);
|
|
49
|
-
// Tracks the last label actually reacted to — null means "not yet
|
|
50
|
-
// initialized". Compared by value rather than a boolean "have we
|
|
51
|
-
// mounted" flag so it stays correct under Strict Mode's dev-only
|
|
52
|
-
// mount → cleanup → mount replay: that replay re-runs this effect with
|
|
53
|
-
// the *same* label, which this recognizes as already-handled and skips,
|
|
54
|
-
// without needing a cleanup-based reset (a reset would fire before every
|
|
55
|
-
// real subsequent change too, not just the replay, permanently
|
|
56
|
-
// disabling the animation).
|
|
57
|
-
const prevLabelRef = useRef<string | null>(null);
|
|
58
|
-
|
|
59
|
-
const [displayedLabel, setDisplayedLabel] = useState(label);
|
|
60
|
-
|
|
61
|
-
useLayoutEffect(() => {
|
|
62
|
-
const target = hasLabel
|
|
63
|
-
? (measureRef.current?.offsetWidth ?? 0) + HORIZONTAL_PADDING * 2
|
|
64
|
-
: 0;
|
|
65
|
-
|
|
66
|
-
if (prevLabelRef.current === null) {
|
|
67
|
-
prevLabelRef.current = label;
|
|
68
|
-
width.set(target);
|
|
69
|
-
setDisplayedLabel(label);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (prevLabelRef.current === label) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
prevLabelRef.current = label;
|
|
77
|
-
|
|
78
|
-
// animate() picks up from each value's current (possibly still
|
|
79
|
-
// mid-tween) state, so rapid consecutive label changes interrupt
|
|
80
|
-
// cleanly instead of jumping back to a stale start point.
|
|
81
|
-
const widthControls = animate(width, target, WIDTH_TRANSITION);
|
|
82
|
-
animate(scale, [1, 0.94, 1], {
|
|
83
|
-
duration: SWAP_DURATION * 0.9,
|
|
84
|
-
times: [0, 0.5, 1],
|
|
85
|
-
ease: easeInOut,
|
|
86
|
-
});
|
|
87
|
-
animate(blurPx, [0, 8, 0], {
|
|
88
|
-
duration: SWAP_DURATION * 0.9,
|
|
89
|
-
times: [0, 0.5, 1],
|
|
90
|
-
ease: easeInOut,
|
|
91
|
-
});
|
|
92
|
-
const swapTimer = setTimeout(
|
|
93
|
-
() => setDisplayedLabel(label),
|
|
94
|
-
(SWAP_DURATION / 2) * 1000,
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
return () => {
|
|
98
|
-
widthControls.stop();
|
|
99
|
-
clearTimeout(swapTimer);
|
|
100
|
-
};
|
|
101
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
102
|
-
}, [label, hasLabel]);
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
<span
|
|
106
|
-
style={{
|
|
107
|
-
display: "inline-flex",
|
|
108
|
-
alignItems: "center",
|
|
109
|
-
fontWeight: 400,
|
|
110
|
-
flexDirection: reverse ? "row-reverse" : "row",
|
|
111
|
-
}}
|
|
112
|
-
>
|
|
113
|
-
<motion.span
|
|
114
|
-
style={{
|
|
115
|
-
width,
|
|
116
|
-
scale,
|
|
117
|
-
filter,
|
|
118
|
-
boxSizing: "border-box",
|
|
119
|
-
position: "relative",
|
|
120
|
-
minHeight: 28,
|
|
121
|
-
textWrap: "nowrap",
|
|
122
|
-
overflow: "hidden",
|
|
123
|
-
display: "inline-flex",
|
|
124
|
-
paddingBlock: 1,
|
|
125
|
-
}}
|
|
126
|
-
initial={false}
|
|
127
|
-
animate={{
|
|
128
|
-
paddingInline: hasLabel ? HORIZONTAL_PADDING : 0,
|
|
129
|
-
}}
|
|
130
|
-
>
|
|
131
|
-
{/* Hidden measurer — always renders the live (target) label, used
|
|
132
|
-
only to read its natural width as the tween target above. */}
|
|
133
|
-
<span
|
|
134
|
-
ref={measureRef}
|
|
135
|
-
aria-hidden
|
|
136
|
-
style={{
|
|
137
|
-
position: "absolute",
|
|
138
|
-
visibility: "hidden",
|
|
139
|
-
whiteSpace: "nowrap",
|
|
140
|
-
pointerEvents: "none",
|
|
141
|
-
}}
|
|
142
|
-
>
|
|
143
|
-
{label}
|
|
144
|
-
</span>
|
|
145
|
-
{displayedLabel}
|
|
146
|
-
</motion.span>
|
|
147
|
-
{systemName && <Icon systemName={systemName} />}
|
|
148
|
-
</span>
|
|
149
|
-
);
|
|
150
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { useEffect, useSyncExternalStore } from "react";
|
|
4
|
-
|
|
5
|
-
export function useMediaQuery(query: string): boolean {
|
|
6
|
-
// useSyncExternalStore is the correct primitive for subscribing to an
|
|
7
|
-
// external mutable source like matchMedia: getServerSnapshot supplies the
|
|
8
|
-
// SSR-safe default (false) so server and the first client render agree,
|
|
9
|
-
// then getSnapshot takes over on the client. No manual setState-in-effect
|
|
10
|
-
// needed — React handles the transition and re-renders on `change` itself.
|
|
11
|
-
return useSyncExternalStore(
|
|
12
|
-
(onStoreChange) => {
|
|
13
|
-
const media = window.matchMedia(query);
|
|
14
|
-
media.addEventListener("change", onStoreChange);
|
|
15
|
-
return () => media.removeEventListener("change", onStoreChange);
|
|
16
|
-
},
|
|
17
|
-
() => window.matchMedia(query).matches,
|
|
18
|
-
() => false,
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function MobileViewProvider({
|
|
23
|
-
children,
|
|
24
|
-
}: {
|
|
25
|
-
children: React.ReactNode;
|
|
26
|
-
}) {
|
|
27
|
-
const isMobile = useMediaQuery("(max-width: 767px)");
|
|
28
|
-
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
const root = document.documentElement;
|
|
31
|
-
|
|
32
|
-
if (isMobile) {
|
|
33
|
-
root.setAttribute("data-mobile-view", "");
|
|
34
|
-
} else {
|
|
35
|
-
root.removeAttribute("data-mobile-view");
|
|
36
|
-
}
|
|
37
|
-
}, [isMobile]);
|
|
38
|
-
|
|
39
|
-
return <>{children}</>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// mobileViewProvider.tsx
|
|
43
|
-
export const BREAKPOINTS = {
|
|
44
|
-
mobile: "(max-width: 767px)",
|
|
45
|
-
tablet: "(max-width: 1024px)",
|
|
46
|
-
} as const;
|
|
47
|
-
|
|
48
|
-
// convenience hook so components do one call instead of two
|
|
49
|
-
export function useBreakpoints() {
|
|
50
|
-
const isMobile = useMediaQuery(BREAKPOINTS.mobile);
|
|
51
|
-
const isTablet = useMediaQuery(BREAKPOINTS.tablet);
|
|
52
|
-
return { isMobile, isTablet };
|
|
53
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
.ripple-container {
|
|
2
|
-
position: absolute;
|
|
3
|
-
top: 0;
|
|
4
|
-
left: 0;
|
|
5
|
-
right: 0;
|
|
6
|
-
bottom: 0;
|
|
7
|
-
border-radius: inherit;
|
|
8
|
-
|
|
9
|
-
z-index: inherit;
|
|
10
|
-
overflow: hidden;
|
|
11
|
-
display: inline-block;
|
|
12
|
-
width: 100%;
|
|
13
|
-
height: 100%;
|
|
14
|
-
pointer-events: none; /* so it doesn’t block clicks */
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.ripple {
|
|
18
|
-
opacity: 0.25;
|
|
19
|
-
inset: 0;
|
|
20
|
-
position: absolute;
|
|
21
|
-
border-radius: 50%;
|
|
22
|
-
background-color: var(--rippleColor, currentColor);
|
|
23
|
-
transform: scale(0);
|
|
24
|
-
animation: ripple-animation 700ms linear;
|
|
25
|
-
pointer-events: none;
|
|
26
|
-
will-change: transform, opacity;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@keyframes ripple-animation {
|
|
30
|
-
to {
|
|
31
|
-
transform: scale(4);
|
|
32
|
-
opacity: 0;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
[data-reduce-motion="true"] .ripple {
|
|
37
|
-
animation-duration: 1ms;
|
|
38
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import React, {
|
|
4
|
-
forwardRef,
|
|
5
|
-
useEffect,
|
|
6
|
-
useImperativeHandle,
|
|
7
|
-
useRef,
|
|
8
|
-
} from "react";
|
|
9
|
-
import "./ripple.css";
|
|
10
|
-
|
|
11
|
-
export interface RippleHandle {
|
|
12
|
-
triggerRipple: (e: React.MouseEvent) => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface RippleProps {
|
|
16
|
-
rippleColor?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const Ripple = forwardRef<RippleHandle, RippleProps>(({ rippleColor }, ref) => {
|
|
20
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
21
|
-
const rippleColorRef = useRef(rippleColor);
|
|
22
|
-
// Ripple spans are created/removed imperatively (outside React's render
|
|
23
|
-
// tree) so their lifetimes need explicit tracking — otherwise a ripple
|
|
24
|
-
// still mid-animation when this component unmounts (Fast Refresh, the
|
|
25
|
-
// host re-rendering, etc.) fires its `animationend` listener against a
|
|
26
|
-
// container React has already torn down, which is what throws
|
|
27
|
-
// "parentNode.removeChild" on a null parent.
|
|
28
|
-
const activeRipplesRef = useRef(new Set<HTMLSpanElement>());
|
|
29
|
-
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
rippleColorRef.current = rippleColor;
|
|
32
|
-
}, [rippleColor]);
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
const activeRipples = activeRipplesRef.current;
|
|
36
|
-
return () => {
|
|
37
|
-
activeRipples.forEach((circle) => circle.remove());
|
|
38
|
-
activeRipples.clear();
|
|
39
|
-
};
|
|
40
|
-
}, []);
|
|
41
|
-
|
|
42
|
-
useImperativeHandle(ref, () => ({
|
|
43
|
-
triggerRipple(e) {
|
|
44
|
-
const container = containerRef.current;
|
|
45
|
-
if (!container) return;
|
|
46
|
-
|
|
47
|
-
const circle = document.createElement("span");
|
|
48
|
-
circle.className = "ripple";
|
|
49
|
-
|
|
50
|
-
if (rippleColorRef.current) {
|
|
51
|
-
circle.style.setProperty("--rippleColor", rippleColorRef.current);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const rect = container.getBoundingClientRect();
|
|
55
|
-
const size = Math.max(rect.width, rect.height);
|
|
56
|
-
const x = e.clientX - rect.left - size / 2;
|
|
57
|
-
const y = e.clientY - rect.top - size / 2;
|
|
58
|
-
|
|
59
|
-
circle.style.width = circle.style.height = `${size}px`;
|
|
60
|
-
circle.style.left = `${x}px`;
|
|
61
|
-
circle.style.top = `${y}px`;
|
|
62
|
-
|
|
63
|
-
container.appendChild(circle);
|
|
64
|
-
activeRipplesRef.current.add(circle);
|
|
65
|
-
|
|
66
|
-
circle.addEventListener("animationend", () => {
|
|
67
|
-
activeRipplesRef.current.delete(circle);
|
|
68
|
-
circle.remove();
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
}));
|
|
72
|
-
|
|
73
|
-
return <div ref={containerRef} className="ripple-container" />;
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
Ripple.displayName = "Ripple";
|
|
77
|
-
|
|
78
|
-
export default Ripple;
|
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
3
|
-
import { motion, useMotionValue, animate, useTransform } from "framer-motion";
|
|
4
|
-
import { interpolate } from "flubber";
|
|
5
|
-
import { useReduceMotion } from "@/components/tools/ReduceMotionContext";
|
|
6
|
-
import Icon from "@/components/tools/label/Icon";
|
|
7
|
-
import { shapePaths, resolveShapePath } from "./ShapePaths";
|
|
8
|
-
import type { ShapeInput } from "./ShapePaths";
|
|
9
|
-
import styles from "./Shape.module.css";
|
|
10
|
-
|
|
11
|
-
export type { ShapeType } from "./ShapePaths";
|
|
12
|
-
|
|
13
|
-
export type ShapeSize = "xs" | "sm" | "md" | "lg" | "xl";
|
|
14
|
-
|
|
15
|
-
// Plain lookup, not a hook — resolving a size token to a pixel value is a
|
|
16
|
-
// cheap, pure read with nothing to memoize; useCallback would only add
|
|
17
|
-
// indirection (and a stale-closure footgun) for zero benefit.
|
|
18
|
-
const SIZE_PX: Record<ShapeSize, number> = {
|
|
19
|
-
xs: 48,
|
|
20
|
-
sm: 60,
|
|
21
|
-
md: 72,
|
|
22
|
-
lg: 96,
|
|
23
|
-
xl: 118,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// ---------------------------------------------------------------------------
|
|
27
|
-
// ShapeMorph — the raw morphing SVG. Used directly by ShapeLoader, Lightbox's
|
|
28
|
-
// card art, and the app/page.tsx demo (all want just the animated shape, no
|
|
29
|
-
// icon overlay); Shape (below) wraps it for the icon-badge use case. Merged
|
|
30
|
-
// into one file since they were never really two components — Shape was
|
|
31
|
-
// always just ShapeMorph plus an icon layered on top.
|
|
32
|
-
// ---------------------------------------------------------------------------
|
|
33
|
-
|
|
34
|
-
interface ShapeMorphProps {
|
|
35
|
-
shape: ShapeInput;
|
|
36
|
-
size?: number;
|
|
37
|
-
color?: string;
|
|
38
|
-
duration?: number;
|
|
39
|
-
isHovered?: boolean;
|
|
40
|
-
swapRotation?: number;
|
|
41
|
-
continuousRotation?: boolean;
|
|
42
|
-
spinDuration?: number;
|
|
43
|
-
style?: React.CSSProperties;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function ShapeMorph({
|
|
47
|
-
shape,
|
|
48
|
-
size = 200,
|
|
49
|
-
color = "currentColor",
|
|
50
|
-
duration = 0.3,
|
|
51
|
-
isHovered = false,
|
|
52
|
-
swapRotation = 0,
|
|
53
|
-
continuousRotation = false,
|
|
54
|
-
spinDuration = 6,
|
|
55
|
-
style,
|
|
56
|
-
}: ShapeMorphProps) {
|
|
57
|
-
const progress = useMotionValue(0);
|
|
58
|
-
const scale = useMotionValue(1);
|
|
59
|
-
const baseRotation = useMotionValue(0);
|
|
60
|
-
const nudgeRotation = useMotionValue(0);
|
|
61
|
-
const rotation = useTransform(
|
|
62
|
-
[baseRotation, nudgeRotation],
|
|
63
|
-
([b, n]: number[]) => b + n,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const rm = useReduceMotion();
|
|
67
|
-
const rmRef = useRef(rm);
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
rmRef.current = rm;
|
|
70
|
-
}, [rm]);
|
|
71
|
-
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
if (!continuousRotation || rm) return;
|
|
74
|
-
const ctrl = animate(baseRotation, baseRotation.get() + 360 * 10000, {
|
|
75
|
-
duration: spinDuration * 10000,
|
|
76
|
-
ease: "linear",
|
|
77
|
-
});
|
|
78
|
-
return () => ctrl.stop();
|
|
79
|
-
}, [continuousRotation, spinDuration, rm]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
80
|
-
|
|
81
|
-
const pathElementRef = useRef<SVGPathElement>(null);
|
|
82
|
-
const pathRef = useRef(resolveShapePath(shape));
|
|
83
|
-
const animationRef = useRef<ReturnType<typeof animate> | null>(null);
|
|
84
|
-
const pendingExitRef = useRef(false);
|
|
85
|
-
const prevIsHoveredRef = useRef(isHovered);
|
|
86
|
-
const prevShapeRef = useRef(resolveShapePath(shape));
|
|
87
|
-
|
|
88
|
-
const startMorph = (targetPath: string, onComplete?: () => void) => {
|
|
89
|
-
const startPath = pathRef.current;
|
|
90
|
-
if (startPath === targetPath) {
|
|
91
|
-
onComplete?.();
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
animationRef.current?.stop();
|
|
96
|
-
animationRef.current = null;
|
|
97
|
-
|
|
98
|
-
const interpolator = interpolate(startPath, targetPath, {
|
|
99
|
-
maxSegmentLength: 8,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
if (rmRef.current) {
|
|
103
|
-
pathElementRef.current?.setAttribute("d", targetPath);
|
|
104
|
-
pathRef.current = targetPath;
|
|
105
|
-
animationRef.current = null;
|
|
106
|
-
onComplete?.();
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
progress.set(0);
|
|
111
|
-
animationRef.current = animate(progress, 1, {
|
|
112
|
-
duration,
|
|
113
|
-
ease: [0.4, 0, 0.2, 1],
|
|
114
|
-
onUpdate: (latest) => {
|
|
115
|
-
const interpolated = interpolator(latest);
|
|
116
|
-
pathElementRef.current?.setAttribute("d", interpolated);
|
|
117
|
-
pathRef.current = interpolated;
|
|
118
|
-
},
|
|
119
|
-
onComplete: () => {
|
|
120
|
-
animationRef.current = null;
|
|
121
|
-
onComplete?.();
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
useEffect(() => {
|
|
127
|
-
const hoveredChanged = isHovered !== prevIsHoveredRef.current;
|
|
128
|
-
prevIsHoveredRef.current = isHovered;
|
|
129
|
-
if (!hoveredChanged) return;
|
|
130
|
-
|
|
131
|
-
if (isHovered) {
|
|
132
|
-
pendingExitRef.current = false;
|
|
133
|
-
|
|
134
|
-
const keys = Object.keys(shapePaths) as Array<keyof typeof shapePaths>;
|
|
135
|
-
const otherShapes = keys.filter((k) => k !== shape);
|
|
136
|
-
const randomKey =
|
|
137
|
-
otherShapes[Math.floor(Math.random() * otherShapes.length)];
|
|
138
|
-
|
|
139
|
-
startMorph(shapePaths[randomKey], () => {
|
|
140
|
-
if (pendingExitRef.current) {
|
|
141
|
-
pendingExitRef.current = false;
|
|
142
|
-
startMorph(resolveShapePath(shape));
|
|
143
|
-
animate(scale, 1, { type: "spring", stiffness: 300, damping: 15 });
|
|
144
|
-
if (swapRotation > 0) {
|
|
145
|
-
// Animate back to absolute 0 to prevent drift accumulation
|
|
146
|
-
animate(nudgeRotation, 0, {
|
|
147
|
-
duration,
|
|
148
|
-
ease: [0.51, 0, 0.1, 1],
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
if (!rmRef.current) {
|
|
155
|
-
animate(scale, 1.15, { type: "spring", stiffness: 300, damping: 15 });
|
|
156
|
-
if (swapRotation > 0) {
|
|
157
|
-
animate(nudgeRotation, nudgeRotation.get() + swapRotation, {
|
|
158
|
-
duration,
|
|
159
|
-
ease: [0.51, 0, 0.1, 1],
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
164
|
-
if (animationRef.current) {
|
|
165
|
-
pendingExitRef.current = true;
|
|
166
|
-
} else {
|
|
167
|
-
startMorph(resolveShapePath(shape));
|
|
168
|
-
if (!rmRef.current) {
|
|
169
|
-
animate(scale, 1, { type: "spring", stiffness: 300, damping: 15 });
|
|
170
|
-
if (swapRotation > 0) {
|
|
171
|
-
// Animate back to absolute 0 to prevent drift accumulation
|
|
172
|
-
animate(nudgeRotation, 0, {
|
|
173
|
-
duration,
|
|
174
|
-
ease: [0.51, 0, 0.1, 1],
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}, [isHovered, shape]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
181
|
-
|
|
182
|
-
useEffect(() => {
|
|
183
|
-
const resolvedPath = resolveShapePath(shape);
|
|
184
|
-
const shapeChanged = resolvedPath !== prevShapeRef.current;
|
|
185
|
-
prevShapeRef.current = resolvedPath;
|
|
186
|
-
if (!shapeChanged) return;
|
|
187
|
-
|
|
188
|
-
startMorph(resolvedPath);
|
|
189
|
-
if (swapRotation > 0 && !rmRef.current) {
|
|
190
|
-
animate(nudgeRotation, nudgeRotation.get() + swapRotation, {
|
|
191
|
-
duration: duration * 2,
|
|
192
|
-
ease: [0.01, 1.25, 0.23, 1.01],
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}, [shape]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
196
|
-
|
|
197
|
-
return (
|
|
198
|
-
<motion.svg
|
|
199
|
-
width={size}
|
|
200
|
-
height={size}
|
|
201
|
-
viewBox="0 0 380 380"
|
|
202
|
-
style={{
|
|
203
|
-
scale,
|
|
204
|
-
rotate: continuousRotation || swapRotation > 0 ? rotation : undefined,
|
|
205
|
-
overflow: "visible",
|
|
206
|
-
...style,
|
|
207
|
-
}}
|
|
208
|
-
>
|
|
209
|
-
<path
|
|
210
|
-
ref={pathElementRef}
|
|
211
|
-
d={resolveShapePath(shape)}
|
|
212
|
-
fill={color}
|
|
213
|
-
style={{ transition: "fill var(--transition-expressive-color)" }}
|
|
214
|
-
/>
|
|
215
|
-
</motion.svg>
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// ---------------------------------------------------------------------------
|
|
220
|
-
// Shape — ShapeMorph wrapped as an icon badge (morphing colored blob behind
|
|
221
|
-
// a static Material icon glyph). This is what Card's withIcon, Dialog's
|
|
222
|
-
// header icon, and Toast's indicator all actually render.
|
|
223
|
-
// ---------------------------------------------------------------------------
|
|
224
|
-
|
|
225
|
-
type ShapeProps = {
|
|
226
|
-
background?: string;
|
|
227
|
-
color?: string;
|
|
228
|
-
onClick?: () => void;
|
|
229
|
-
shapePath: ShapeInput;
|
|
230
|
-
systemName: string;
|
|
231
|
-
size?: ShapeSize;
|
|
232
|
-
duration?: number;
|
|
233
|
-
isHovered?: boolean;
|
|
234
|
-
// Set false for a purely decorative/static shape (e.g. a status icon) —
|
|
235
|
-
// otherwise hovering it always morphs regardless of what isHovered is set
|
|
236
|
-
// to, since the outer div's own mouse tracking runs unconditionally.
|
|
237
|
-
interactive?: boolean;
|
|
238
|
-
swapRotation?: number;
|
|
239
|
-
continuousRotation?: boolean;
|
|
240
|
-
spinDuration?: number;
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
export default function Shape({
|
|
244
|
-
background = "var(--md-sys-color-primary)",
|
|
245
|
-
color = "var(--md-sys-color-on-primary)",
|
|
246
|
-
onClick,
|
|
247
|
-
shapePath,
|
|
248
|
-
systemName,
|
|
249
|
-
size = "md",
|
|
250
|
-
duration,
|
|
251
|
-
isHovered = false,
|
|
252
|
-
interactive = true,
|
|
253
|
-
swapRotation,
|
|
254
|
-
continuousRotation,
|
|
255
|
-
spinDuration,
|
|
256
|
-
}: ShapeProps) {
|
|
257
|
-
const [internalHover, setInternalHover] = useState(false);
|
|
258
|
-
|
|
259
|
-
const sizePx = SIZE_PX[size];
|
|
260
|
-
|
|
261
|
-
return (
|
|
262
|
-
<div
|
|
263
|
-
onClick={onClick}
|
|
264
|
-
onMouseEnter={interactive ? () => setInternalHover(true) : undefined}
|
|
265
|
-
onMouseLeave={interactive ? () => setInternalHover(false) : undefined}
|
|
266
|
-
className={styles.shapeOuter}
|
|
267
|
-
style={
|
|
268
|
-
{
|
|
269
|
-
position: "relative",
|
|
270
|
-
width: sizePx,
|
|
271
|
-
height: sizePx,
|
|
272
|
-
display: "inline-flex",
|
|
273
|
-
alignItems: "center",
|
|
274
|
-
justifyContent: "center",
|
|
275
|
-
cursor: interactive || onClick ? "pointer" : "default",
|
|
276
|
-
} as React.CSSProperties
|
|
277
|
-
}
|
|
278
|
-
>
|
|
279
|
-
<div
|
|
280
|
-
className={`${styles.shapeInner} ${onClick ? styles.interactive : ""}`}
|
|
281
|
-
style={{
|
|
282
|
-
display: "inline-flex",
|
|
283
|
-
alignItems: "center",
|
|
284
|
-
justifyContent: "center",
|
|
285
|
-
}}
|
|
286
|
-
>
|
|
287
|
-
<ShapeMorph
|
|
288
|
-
shape={shapePath}
|
|
289
|
-
size={sizePx}
|
|
290
|
-
color={background}
|
|
291
|
-
duration={duration}
|
|
292
|
-
isHovered={isHovered || (interactive && internalHover)}
|
|
293
|
-
swapRotation={swapRotation}
|
|
294
|
-
continuousRotation={continuousRotation}
|
|
295
|
-
spinDuration={spinDuration}
|
|
296
|
-
/>
|
|
297
|
-
</div>
|
|
298
|
-
<span
|
|
299
|
-
style={{
|
|
300
|
-
position: "absolute",
|
|
301
|
-
color,
|
|
302
|
-
display: "inline-flex",
|
|
303
|
-
padding: 16,
|
|
304
|
-
alignItems: "center",
|
|
305
|
-
justifyContent: "center",
|
|
306
|
-
cursor: interactive || onClick ? "pointer" : "default",
|
|
307
|
-
}}
|
|
308
|
-
>
|
|
309
|
-
<Icon systemName={systemName} />
|
|
310
|
-
</span>
|
|
311
|
-
</div>
|
|
312
|
-
);
|
|
313
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
.shapeOuter {
|
|
2
|
-
--shape-scale-clamped: clamp(0.8, var(--shape-scale, 1), 2);
|
|
3
|
-
transition: margin var(--transition-expressive-fast);
|
|
4
|
-
|
|
5
|
-
-webkit-user-select: none;
|
|
6
|
-
user-select: none;
|
|
7
|
-
-webkit-touch-callout: none;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
.shapeInner {
|
|
11
|
-
scale: var(--shape-scale-clamped, 1);
|
|
12
|
-
transition: scale var(--transition-expressive-fast);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.shapeOuter:hover .shapeInner.interactive {
|
|
16
|
-
scale: clamp(0.8, calc(var(--shape-scale-clamped, 1) + 0.06), 2);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.shapeOuter:active .shapeInner.interactive {
|
|
20
|
-
scale: clamp(0.8, calc(var(--shape-scale-clamped, 1) - 0.06), 2);
|
|
21
|
-
}
|