1"use client"
2
3import React, { forwardRef, ReactNode } from "react"
4import { AnimatePresence, motion, MotionConfig } from "motion/react"
5import useMeasure from "react-use-measure"
6
7import { cn } from "@/lib/utils"
8
9type PanelContainerProps = {
10 panelOpen: boolean
11 handlePanelOpen: () => void
12 className?: string
13 videoUrl?: string
14 renderButton?: (handleToggle: () => void) => ReactNode
15 children: ReactNode
16}
17
18const sectionVariants = {
19 open: {
20 width: "97%",
21 transition: {
22 duration: 0.3,
23 ease: [0.42, 0, 0.58, 1] as const,
24 delayChildren: 0.3,
25 staggerChildren: 0.2,
26 },
27 },
28 closed: {
29 transition: { duration: 0.2, ease: [0.42, 0, 0.58, 1] as const },
30 },
31}
32
33const sharedTransition = { duration: 0.6, ease: [0.42, 0, 0.58, 1] as const }
34
35export const SidePanel = forwardRef<HTMLDivElement, PanelContainerProps>(
36 ({ panelOpen, handlePanelOpen, className, renderButton, children }, ref) => {
37 const [measureRef, bounds] = useMeasure()
38
39 return (
40 <ResizablePanel>
41 <motion.div
42 className={cn(
43 "bg-neutral-900 rounded-r-[44px] w-[160px] md:w-[260px]",
44 className
45 )}
46 animate={panelOpen ? "open" : "closed"}
47 variants={sectionVariants}
48 transition={{ duration: 0.2, ease: [0.42, 0, 0.58, 1] as const }}
49 >
50 <motion.div
51 animate={{ height: bounds.height > 0 ? bounds.height : 0.1 }}
52 className="h-auto"
53 transition={{ type: "spring", bounce: 0.02, duration: 0.65 }}
54 >
55 <div ref={measureRef}>
56 <AnimatePresence mode="popLayout">
57 <motion.div
58 exit={{ opacity: 0 }}
59 transition={{
60 ...sharedTransition,
61 duration: sharedTransition.duration / 2,
62 }}
63 key="form"
64 >
65 <div
66 className={cn(
67 "flex items-center w-full justify-start pl-4 md:pl-4 py-1 md:py-3",
68 panelOpen ? "pr-3" : ""
69 )}
70 >
71 {renderButton && renderButton(handlePanelOpen)}
72 </div>
73
74 {panelOpen && (
75 <motion.div
76 exit={{ opacity: 0 }}
77 transition={sharedTransition}
78 >
79 {children}
80 </motion.div>
81 )}
82 </motion.div>
83 </AnimatePresence>
84 </div>
85 </motion.div>
86 </motion.div>
87 </ResizablePanel>
88 )
89 }
90)
91
92SidePanel.displayName = "SidePanel"
93
94export default SidePanel
95
96type ResizablePanelProps = {
97 children: React.ReactNode
98}
99
100const ResizablePanel = React.forwardRef<HTMLDivElement, ResizablePanelProps>(
101 ({ children }, ref) => {
102 const transition = {
103 type: "tween" as const,
104 ease: [0.42, 0, 0.58, 1] as const,
105 duration: 0.4,
106 }
107
108 return (
109 <MotionConfig transition={transition}>
110 <div className="flex w-full flex-col items-start">
111 <div className="mx-auto w-full">
112 <div
113 ref={ref}
114 className={cn(
115 children ? "rounded-r-none" : "rounded-sm",
116 "relative overflow-hidden"
117 )}
118 >
119 {children}
120 </div>
121 </div>
122 </div>
123 </MotionConfig>
124 )
125 }
126)
127
128ResizablePanel.displayName = "ResizablePanel"
129