1"use client"
2
3import { FC, ReactNode, useState } from "react"
4import { PlusIcon, XIcon } from "lucide-react"
5import { motion } from "motion/react"
6
7import { cn } from "@/lib/utils"
8
9const CONTAINER_SIZE = 200
10
11interface FamilyButtonProps {
12 children: React.ReactNode
13}
14
15const FamilyButton: React.FC<FamilyButtonProps> = ({ children }) => {
16 const [isExpanded, setIsExpanded] = useState(false)
17 const toggleExpand = () => setIsExpanded(!isExpanded)
18
19 return (
20 <div
21 className={cn(
22 "rounded-[24px] border border-black/10 shadow-sm dark:border-yellow-400/20",
23 "bg-gradient-to-b from-neutral-900 to-black",
24 isExpanded
25 ? "w-[204px] bg-gradient-to-b dark:from-stone-900 dark:to-neutral-900/80"
26 : "dark:from-neutral-900 dark:to-stone-950 bg-gradient-to-b"
27 )}
28 >
29 <div className="rounded-[23px] border border-black/10 ">
30 <div className="rounded-[22px] border dark:border-stone-800 border-white/50 ">
31 <div className="rounded-[21px] border border-neutral-950/20 flex items-center justify-center ">
32 <FamilyButtonContainer
33 isExpanded={isExpanded}
34 toggleExpand={toggleExpand}
35 >
36 {isExpanded ? (
37 <motion.div
38 initial={{ opacity: 0 }}
39 animate={{
40 opacity: 1,
41 transition: {
42 delay: 0.3,
43 duration: 0.4,
44 ease: "easeOut",
45 },
46 }}
47 >
48 {children}
49 </motion.div>
50 ) : null}
51 </FamilyButtonContainer>
52 </div>
53 </div>
54 </div>
55 </div>
56 )
57}
58
59// A container that wraps content and handles animations
60interface FamilyButtonContainerProps {
61 isExpanded: boolean
62 toggleExpand: () => void
63 children: ReactNode
64}
65
66const FamilyButtonContainer: FC<FamilyButtonContainerProps> = ({
67 isExpanded,
68 toggleExpand,
69 children,
70}) => {
71 return (
72 <motion.div
73 className={cn(
74 "relative border-white/10 border shadow-lg flex flex-col space-y-1 items-center text-white cursor-pointer z-10",
75 !isExpanded
76 ? "bg-gradient-to-b from-neutral-900 to-stone-900 dark:from-stone-700 dark:to-neutral-800/80"
77 : ""
78 )}
79 layoutRoot
80 layout
81 initial={{ borderRadius: 21, width: "4rem", height: "4rem" }}
82 animate={
83 isExpanded
84 ? {
85 borderRadius: 20,
86 width: CONTAINER_SIZE,
87 height: CONTAINER_SIZE + 50,
88
89 transition: {
90 type: "spring",
91 damping: 25,
92 stiffness: 400,
93 when: "beforeChildren",
94 },
95 }
96 : {
97 borderRadius: 21,
98 width: "4rem",
99 height: "4rem",
100 }
101 }
102 >
103 {children}
104
105 <motion.div
106 className="absolute "
107 initial={{ x: "-50%" }}
108 animate={{
109 x: isExpanded ? "0%" : "-50%",
110 transition: {
111 type: "tween",
112 ease: "easeOut",
113 duration: 0.3,
114 },
115 }}
116 style={{
117 left: isExpanded ? "" : "50%",
118 bottom: 6,
119 }}
120 >
121 {isExpanded ? (
122 <motion.div
123 className="p-[10px] group bg-neutral-800/50 dark:bg-black/50 border border-cyan-100/30 hover:border-neutral-200 text-orange-50 rounded-full shadow-2xl transition-colors duration-300 "
124 onClick={toggleExpand}
125 layoutId="expand-toggle"
126 initial={false}
127 animate={{
128 rotate: -360,
129 transition: {
130 duration: 0.4,
131 },
132 }}
133 >
134 <XIcon
135 className={cn(
136 "h-7 w-7 text-cyan-100/30 dark:text-neutral-400/80 group-hover:text-neutral-500 transition-colors duration-200 "
137 )}
138 />
139 </motion.div>
140 ) : (
141 <motion.div
142 className={cn(
143 "p-[10px] group bg-neutral-200 dark:bg-cyan-500/90 text-cyan-50 border border-cyan-100/10 shadow-2xl transition-colors duration-200"
144 )}
145 style={{ borderRadius: 24 }}
146 onClick={toggleExpand}
147 layoutId="expand-toggle"
148 initial={{ rotate: 180 }}
149 animate={{
150 rotate: -180,
151 transition: {
152 duration: 0.4,
153 },
154 }}
155 >
156 <PlusIcon className="h-7 w-7 text-black dark:text-neutral-900" />
157 </motion.div>
158 )}
159 </motion.div>
160 </motion.div>
161 )
162}
163
164export { FamilyButton }
165export default FamilyButton
166