1"use client"
2
3import * as React from "react"
4import { AnimatePresence, motion, MotionProps } from "motion/react"
5
6import { cn } from "@/lib/utils"
7
8interface ShiftCardProps
9 extends Omit<MotionProps, "onAnimationStart" | "onAnimationComplete"> {
10 className?: string
11 topContent?: React.ReactNode
12 middleContent?: React.ReactNode
13 topAnimateContent?: React.ReactNode
14 bottomContent?: React.ReactNode
15}
16
17const ShiftCardHeader = React.forwardRef<
18 HTMLDivElement,
19 React.HTMLAttributes<HTMLDivElement>
20>(({ children, ...props }, ref) => (
21 <div ref={ref} {...props}>
22 {children}
23 </div>
24))
25ShiftCardHeader.displayName = "ShiftCardHeader"
26
27interface ShiftCardContentProps extends React.HTMLAttributes<HTMLDivElement> {
28 isHovered: boolean
29}
30const ShiftCardContent = React.forwardRef<
31 HTMLDivElement,
32 ShiftCardContentProps
33>(({ isHovered, children, ...divProps }, ref) => {
34 // Explicitly define motion props to avoid passing incompatible HTML attributes
35 const motionProps: MotionProps = {
36 initial: { opacity: 0, height: 0 },
37 animate: isHovered
38 ? { opacity: 1, height: 194 }
39 : { opacity: 1, height: 38 },
40 transition: { duration: 0.3, delay: 0.1, ease: "circIn" },
41 }
42
43 return (
44 <motion.div
45 key="shift-card-content"
46 ref={ref}
47 {...motionProps}
48 className={divProps.className}
49 >
50 {children}
51 </motion.div>
52 )
53})
54ShiftCardContent.displayName = "ShiftCardContent"
55
56const ShiftCard = React.forwardRef<HTMLDivElement, ShiftCardProps>(
57 (
58 {
59 className,
60 topContent,
61 topAnimateContent,
62 middleContent,
63 bottomContent,
64 ...props
65 },
66 ref
67 ) => {
68 const [isHovered, setHovered] = React.useState(false)
69 const handleMouseEnter = () => setHovered(true)
70 const handleMouseLeave = () => setHovered(false)
71 const handleTapStart = () => setHovered(true)
72 const handleTapCancel = () => setHovered(false)
73 const handleTap = () => setHovered(false)
74
75 return (
76 <motion.div
77 ref={ref}
78 className={cn(
79 "min-h-[300px] w-[280px] md:w-[300px]",
80 " group relative flex flex-col items-center justify-between overflow-hidden rounded-xl p-3 text-sm ",
81 " hover:cursor-pointer bg-card ",
82 "shadow-[0px_1px_1px_0px_rgba(0,0,0,0.05),0px_1px_1px_0px_rgba(255,252,240,0.5)_inset,0px_0px_0px_1px_hsla(0,0%,100%,0.1)_inset,0px_0px_1px_0px_rgba(28,27,26,0.5)]",
83 /*
84 Applies a multi-layer shadow effect in dark mode:
85 1. Two subtle white inset shadows: one horizontal at 1px height, and one around the entire border at 1px width, both with a very light opacity of 0.03, creating a slight inner glow.
86 2. A series of black shadows:
87 - A basic 1px black border shadow with 10% opacity to subtly outline the element.
88 - Three progressively larger diffuse shadows at 2px, 4px, and 8px, each with 10% opacity, creating a depth effect that enhances the element's visual separation from the background.
89 */
90 "dark:shadow-[0_1px_0_0_rgba(255,255,255,0.03)_inset,0_0_0_1px_rgba(255,255,255,0.03)_inset,0_0_0_1px_rgba(0,0,0,0.1),0_2px_2px_0_rgba(0,0,0,0.1),0_4px_4px_0_rgba(0,0,0,0.1),0_8px_8px_0_rgba(0,0,0,0.1)]",
91 className
92 )}
93 initial={{ y: 20, opacity: 0 }}
94 animate={{ y: 0, opacity: 1 }}
95 whileHover={{ scale: 1.02 }}
96 onMouseEnter={handleMouseEnter}
97 onMouseLeave={handleMouseLeave}
98 onClick={handleTapStart}
99 onTapCancel={handleTapCancel}
100 onTap={handleTap}
101 {...props}
102 >
103 <ShiftCardHeader className="flex h-[46px] w-full flex-col relative text-primary-foreground ">
104 <div className=" w-full">
105 {topContent}
106
107 <AnimatePresence>
108 {isHovered ? <>{topAnimateContent}</> : null}
109 </AnimatePresence>
110 </div>
111 </ShiftCardHeader>
112
113 <div className="pb-12 ">
114 <AnimatePresence>
115 {!isHovered ? <>{middleContent}</> : null}
116 </AnimatePresence>
117 </div>
118
119 <ShiftCardContent
120 isHovered={isHovered}
121 className="absolute -bottom-1.5 left-0 right-0 flex flex-col gap-4 rounded-xl "
122 >
123 <motion.div className="flex w-full flex-col gap-1 ">
124 {bottomContent}
125 </motion.div>
126 </ShiftCardContent>
127 </motion.div>
128 )
129 }
130)
131
132ShiftCard.displayName = "ShiftCard"
133
134export { ShiftCard, ShiftCardHeader, ShiftCardContent }
135export default ShiftCard
136