expandable
cult-ui/expandableFreeComponent
Expandable component system with smooth animations and customizable presets
Install it
npx shadcn@latest add https://raw.githubusercontent.com/nolly-studio/cult-ui/HEAD/apps/www/public/r/styles/default/expandable.jsonSource
1"use client"23import React, {4 createContext,5 ReactNode,6 useContext,7 useEffect,8 useState,9} from "react"10import {11 AnimatePresence,12 HTMLMotionProps,13 motion,14 TargetAndTransition,15 useMotionValue,16 useSpring,17} from "motion/react"18import useMeasure from "react-use-measure"1920import { cn } from "@/lib/utils"2122const springConfig = { stiffness: 200, damping: 20, bounce: 0.2 }2324interface ExpandableContextType {25 isExpanded: boolean // Indicates whether the component is expanded26 toggleExpand: () => void // Function to toggle the expanded state27 expandDirection: "vertical" | "horizontal" | "both" // Direction of expansion28 expandBehavior: "replace" | "push" // How the expansion affects surrounding content29 transitionDuration: number // Duration of the expansion/collapse animation30 easeType:31 | "easeInOut"32 | "easeIn"33 | "easeOut"34 | "linear"35 | [number, number, number, number] // Easing function for the animation36 initialDelay: number // Delay before the animation starts37 onExpandEnd?: () => void // Callback function when expansion ends38 onCollapseEnd?: () => void // Callback function when collapse ends39}4041// Create a context with default values42const ExpandableContext = createContext<ExpandableContextType>({43 isExpanded: false,44 toggleExpand: () => {},45 expandDirection: "vertical", // 'vertical' | 'horizontal' | 'both' // Direction of expansion46 expandBehavior: "replace", // How the expansion affects surrounding content47 transitionDuration: 0.3, // Duration of the expansion/collapse animation48 easeType: "easeInOut" as const, // Easing function for the animation49 initialDelay: 0,50})5152// Custom hook to use the ExpandableContext53const useExpandable = () => useContext(ExpandableContext)5455type ExpandablePropsBase = Omit<HTMLMotionProps<"div">, "children">5657interface ExpandableProps extends ExpandablePropsBase {58 children: ReactNode | ((props: { isExpanded: boolean }) => ReactNode)59 expanded?: boolean60 onToggle?: () => void61 transitionDuration?: number62 easeType?:63 | "easeInOut"64 | "easeIn"65 | "easeOut"66 | "linear"67 | [number, number, number, number]68 expandDirection?: "vertical" | "horizontal" | "both"69 expandBehavior?: "replace" | "push"70 initialDelay?: number71 onExpandStart?: () => void72 onExpandEnd?: () => void73 onCollapseStart?: () => void74 onCollapseEnd?: () => void75}76// ROOT Expand component77const Expandable = React.forwardRef<HTMLDivElement, ExpandableProps>(78 (79 {80 children,81// … truncated
What it pulls in
npm packages
Files it writes
More from cult/ui
All 157 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-instructionsai-instructions | cult/ui | Components | Free | 2 deps | |
| ai-instructions-demoai-instructions-demo | cult/ui | Components | Free | no deps | |
| animated-numberanimated-number | cult/ui | Components | Free | 1 dep | |
| animated-number-demoanimated-number-demo | cult/ui | Components | Free | no deps | |
| bg-animate-buttonbg-animate-button | cult/ui | Components | Free | no deps | |
| bg-animate-button-demobg-animate-button-demo | cult/ui | Components | Free | no deps | |
| bg-animated-fractal-dot-gridbg-animated-fractal-dot-grid | cult/ui | Components | Free | 1 dep | |
| bg-animated-fractal-dot-grid-demobg-animated-fractal-dot-grid-demo | cult/ui | Components | Free | no deps |
