-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.tsx
72 lines (65 loc) · 1.54 KB
/
index.tsx
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
71
72
import { Heading, StackProps, VStack } from '@chakra-ui/react';
import { motion, useAnimation, Variants } from 'framer-motion';
import { PropsWithChildren, useEffect } from 'react';
import { useInView } from 'react-intersection-observer';
import SummaryTitle from '../summary-title';
const variants: Variants = {
visible: {
opacity: 1,
transition: {
type: 'tween',
duration: 0.6,
ease: 'easeInOut',
},
},
hidden: {
opacity: 0,
transition: {
type: 'tween',
duration: 0.8,
ease: 'easeInOut',
},
},
};
type Props = PropsWithChildren<{
id?: string;
number: number;
title: string;
summaryTitle: string;
align: string;
}>;
const MotionStack = motion<StackProps>(VStack);
const Scene = ({ children, id, number, title, summaryTitle, align }: Props) => {
const { ref, inView } = useInView({ threshold: 0.1 });
const animation = useAnimation();
useEffect(() => {
if (inView) {
animation.start('visible');
} else {
animation.start('hidden');
}
}, [animation, inView]);
return (
<MotionStack
id={id}
variants={variants}
initial='hidden'
animate={animation}
ref={ref}
as='section'
spacing={3}
minH='100vh'
w='full'
py={20}
>
<VStack spacing={-2} align={align}>
<SummaryTitle number={number} title={summaryTitle} />
<Heading as='h1' textTransform='uppercase'>
{title}
</Heading>
</VStack>
{children}
</MotionStack>
);
};
export default Scene;