Skip to content

Commit 78e7da1

Browse files
committed
Add border animation
1 parent f05eee7 commit 78e7da1

File tree

1 file changed

+51
-19
lines changed

1 file changed

+51
-19
lines changed

apps/builder/app/builder/features/settings-panel/props-section/animation/animation-ranges.tsx

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ const borderColor = "#ccc";
1111
const Wrapper = styled(Box, {
1212
position: "relative",
1313
alignSelf: "stretch",
14-
// borderRight: `1px solid ${borderColor}`,
15-
// borderLeft: `1px solid ${borderColor}`,
1614
});
1715

1816
const InsetLine = styled(Box, {
@@ -34,8 +32,8 @@ const Scrollable = styled(Box, {
3432
});
3533

3634
const bgKeyframes = keyframes({
37-
"0%": { backgroundColor: "oklch(54.6% 0.245 262.881)" },
38-
"100%": { backgroundColor: "oklch(58.6% 0.253 17.585)" },
35+
"0%": { "--progress": "0" },
36+
"100%": { "--progress": "360" },
3937
});
4038

4139
const rafInterval = (callback: () => void): (() => void) => {
@@ -58,6 +56,17 @@ export const AnimationRanges = (props: AnimationRangesProps) => {
5856
const subjectRef = useRef<HTMLDivElement>(null);
5957

6058
useEffect(() => {
59+
try {
60+
CSS.registerProperty({
61+
name: "--progress",
62+
syntax: "<number>",
63+
inherits: true,
64+
initialValue: "0",
65+
});
66+
} catch {
67+
/* */
68+
}
69+
6170
const scrollable = scrollableRef.current;
6271
const subject = subjectRef.current;
6372

@@ -78,12 +87,12 @@ export const AnimationRanges = (props: AnimationRangesProps) => {
7887
const timeDelta = Date.now() - startTime;
7988

8089
scrollable.scrollTop =
81-
(Math.sin(timeDelta / 500) * (scrollHeight - clientHeight)) / 2 +
90+
(Math.sin(timeDelta / 1000) * (scrollHeight - clientHeight)) / 2 +
8291
(scrollHeight - clientHeight) / 2;
8392

8493
const progress =
85-
subject.getAnimations()?.[0]?.effect?.getComputedTiming()?.progress ??
86-
0;
94+
subject.parentElement?.getAnimations()?.[0]?.effect?.getComputedTiming()
95+
?.progress ?? 0;
8796

8897
const content = `${(progress * 100).toFixed(0)}%`;
8998

@@ -110,6 +119,8 @@ export const AnimationRanges = (props: AnimationRangesProps) => {
110119
},
111120
];
112121

122+
const progressRadius = "6px";
123+
113124
return (
114125
<Wrapper>
115126
<Scrollable ref={scrollableRef}>
@@ -119,21 +130,10 @@ export const AnimationRanges = (props: AnimationRangesProps) => {
119130
}}
120131
/>
121132
<Box
122-
ref={subjectRef}
123133
css={{
124134
height: insetSize,
125135
marginLeft: 4,
126136
marginRight: 4,
127-
// border: `1px solid ${borderColor}`,
128-
129-
color: "white",
130-
fontSize: "12px",
131-
display: "flex",
132-
alignItems: "center",
133-
justifyContent: "center",
134-
whiteSpace: "pre",
135-
textAlign: "center",
136-
fontFamily: theme.fonts.robotoMono,
137137

138138
animationName: `${bgKeyframes}`,
139139
animationTimingFunction: "linear",
@@ -142,8 +142,40 @@ export const AnimationRanges = (props: AnimationRangesProps) => {
142142
animationRangeStart: `${rangeStart[0]} ${toValue(rangeStart[1])}`,
143143
animationRangeEnd: `${rangeEnd[0]} ${toValue(rangeEnd[1])}`,
144144
animationTimeline: `view(y ${insetSize})`,
145+
146+
position: "relative",
147+
borderRadius: progressRadius,
145148
}}
146-
/>
149+
>
150+
<Box
151+
css={{
152+
position: "absolute",
153+
inset: 0,
154+
borderRadius: progressRadius,
155+
156+
background: `conic-gradient(oklch(54.6% 0.245 262.881) calc(var(--progress, 0) * 1deg), oklch(92.9% 0.013 255.508) 0)`,
157+
mask: `linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)`,
158+
159+
maskComposite: `exclude`,
160+
padding: `4px`,
161+
}}
162+
/>
163+
164+
<Box
165+
ref={subjectRef}
166+
css={{
167+
position: "absolute",
168+
inset: 0,
169+
fontSize: "12px",
170+
display: "flex",
171+
alignItems: "center",
172+
justifyContent: "center",
173+
whiteSpace: "pre",
174+
textAlign: "center",
175+
fontFamily: theme.fonts.robotoMono,
176+
}}
177+
></Box>
178+
</Box>
147179
<Box
148180
css={{
149181
height: `calc(100% - ${insetSize})`,

0 commit comments

Comments
 (0)