-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeWrapper.tsx
64 lines (61 loc) · 1.66 KB
/
CodeWrapper.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
import { useState } from "react";
import { motion } from "framer-motion";
const springConfig = {
damping: 20,
stiffness: 120,
mass: 0.15,
};
export default function CodeWrapper({
children,
}: {
children: React.ReactNode;
}) {
const [expanded, setExpanded] = useState(false);
const [hideExpand, setHideExpand] = useState(false);
return (
<div className="relative bg-brand-coal rounded-[.5rem]">
<motion.div
variants={{
expanded: {
height: "auto",
},
collapsed: {
height: "500px",
},
}}
transition={springConfig}
initial="collapsed"
animate={expanded ? "expanded" : "collapsed"}
className="relative overflow-auto "
>
<div
ref={(el) => {
if (el) {
const { height } = el.getBoundingClientRect();
if (height < 500) {
setExpanded(true);
setHideExpand(true);
}
}
}}
>
{children}
</div>
</motion.div>
{!hideExpand && (
<div
className={`${
expanded ? "relative" : "absolute"
} bottom-0 w-full p-4`}
>
<button
className="font-bold uppercase rounded-full px-4 py-1 flex text-xs items-center justify-center bg-brand-charcoal text-brand-beige gap-2 hover:shadow-sm hover:bg-brand-yellow hover:text-brand-charcoal border border-brand-charcoal transition-all"
onClick={() => setExpanded(!expanded)}
>
{expanded ? "Collapse" : "Expand"}
</button>
</div>
)}
</div>
);
}