forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuccessCheck.tsx
More file actions
46 lines (42 loc) · 1.03 KB
/
Copy pathSuccessCheck.tsx
File metadata and controls
46 lines (42 loc) · 1.03 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
'use client';
import { useLayoutEffect, useRef, type CSSProperties, type ReactNode } from 'react';
import { cn } from '@/lib/utils';
export function SuccessCheck({
active,
children,
className,
}: {
active: boolean;
children: ReactNode;
className?: string;
}) {
const ref = useRef<HTMLSpanElement>(null);
useLayoutEffect(() => {
const path = ref.current?.querySelector('path');
if (!path || typeof path.getTotalLength !== 'function') return;
try {
const len = Math.ceil(path.getTotalLength());
path.style.strokeDasharray = String(len);
path.style.strokeDashoffset = String(len);
} catch {
return;
}
}, [children]);
return (
<span
ref={ref}
className={cn('t-success-check', className)}
data-state={active ? 'in' : 'out'}
aria-hidden="true"
style={
{
'--check-y-amount': '3px',
'--check-blur-from': '2px',
'--check-rotate-from': '25deg',
} as CSSProperties
}
>
{children}
</span>
);
}