forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageSlide.tsx
More file actions
49 lines (43 loc) · 1.3 KB
/
Copy pathPageSlide.tsx
File metadata and controls
49 lines (43 loc) · 1.3 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
'use client';
import { useLayoutEffect, useRef, type ReactNode } from 'react';
import { cn } from '@/lib/utils';
import { prefersReducedMotion, readDurationToken } from '@/lib/transitionsDev';
export function PageSlide({
pageKey,
children,
className,
}: {
pageKey: string;
children: ReactNode;
className?: string;
}) {
const ref = useRef<HTMLDivElement>(null);
const pageRef = useRef<HTMLElement>(null);
useLayoutEffect(() => {
const el = ref.current;
if (!el) return;
el.removeAttribute('data-settled');
el.setAttribute('data-page', '1');
void el.offsetWidth;
el.setAttribute('data-page', '2');
if (prefersReducedMotion()) {
el.setAttribute('data-settled', '');
return;
}
const page = pageRef.current;
const settle = () => el.setAttribute('data-settled', '');
page?.addEventListener('transitionend', settle);
const timer = window.setTimeout(settle, readDurationToken('--page-slide-dur', 250) + 80);
return () => {
page?.removeEventListener('transitionend', settle);
window.clearTimeout(timer);
};
}, [pageKey]);
return (
<div ref={ref} className={cn('t-page-slide h-full', className)} data-page="1">
<section ref={pageRef} className="t-page" data-page-id="2">
{children}
</section>
</div>
);
}