import { keyframes, styled } from '@stitches/react' import * as CollapsiblePrimitive from '@radix-ui/react-collapsible' import { ComponentPropsWithoutRef, ElementRef, forwardRef, ReactNode, useState, } from 'react' import { AnimatePresence, motion } from 'framer-motion' export const slideDown = keyframes({ from: { height: 0 }, to: { height: 'var(--radix-collapsible-content-height)' }, }) export const slideUp = keyframes({ from: { height: 'var(--radix-collapsible-content-height)' }, to: { height: 0 }, }) const CollapsibleContent = styled(CollapsiblePrimitive.CollapsibleContent, { background: 'transparent', border: 'none', borderRadius: 0, }) const CollapsibleRoot = styled(CollapsiblePrimitive.Root, { borderRadius: 8, overflow: 'hidden', }) const AnimatedCollapsibleContent = forwardRef< ElementRef, ComponentPropsWithoutRef >(({ children, ...props }, forwardedRef) => ( {children} )) type Props = { trigger: ReactNode contentProps?: CollapsiblePrimitive.CollapsibleContentProps } const Collapsible = forwardRef< ElementRef, ComponentPropsWithoutRef & Props >(({ children, trigger, contentProps, ...props }, forwardedRef) => { const [open, setOpen] = useState(false) return ( {trigger} {open && ( {children} )} ) }) export { Collapsible, CollapsibleContent, AnimatedCollapsibleContent, CollapsibleRoot, }