UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

1 lines 6.34 kB
{"version":3,"file":"collapse.cjs","names":["variants: Variants","createTransition","createComponent","collapseStyle","AnimatePresence","motion"],"sources":["../../../../src/components/collapse/collapse.tsx"],"sourcesContent":["\"use client\"\n\nimport type { Variants } from \"motion/react\"\nimport type { ThemeProps } from \"../../core\"\nimport type {\n HTMLMotionProps,\n MotionTransitionVariants,\n WithTransitionProps,\n} from \"../motion\"\nimport type { CollapseStyle } from \"./collapse.style\"\nimport { AnimatePresence } from \"motion/react\"\nimport { useEffect, useMemo, useState } from \"react\"\nimport { createComponent } from \"../../core\"\nimport { createdDom, isNumeric } from \"../../utils\"\nimport { createTransition, motion } from \"../motion\"\nimport { collapseStyle } from \"./collapse.style\"\n\nconst variants: Variants = {\n enter: ({\n animationOpacity,\n delay,\n duration,\n endingHeight: height,\n enter,\n transition,\n transitionEnd,\n } = {}) => ({\n ...(animationOpacity ? { opacity: 1 } : {}),\n height,\n transition: createTransition.enter(transition?.enter)(delay, duration),\n transitionEnd: transitionEnd?.enter,\n ...enter,\n }),\n exit: ({\n animationOpacity,\n delay,\n duration,\n exit,\n startingHeight: height,\n transition,\n transitionEnd,\n } = {}) => ({\n ...(animationOpacity ? { opacity: isNumeric(height) ? 1 : 0 } : {}),\n height,\n transition: createTransition.exit(transition?.exit)(delay, duration),\n transitionEnd: transitionEnd?.exit,\n ...exit,\n }),\n} satisfies MotionTransitionVariants\n\nexport interface CollapseProps\n extends WithTransitionProps<HTMLMotionProps>,\n ThemeProps<CollapseStyle> {\n /**\n * If `true`, the opacity of the content will be animated.\n *\n * @default true\n */\n animationOpacity?: boolean\n /**\n * The height you want the content in its expanded state.\n *\n * @default 'auto'\n */\n endingHeight?: number | string\n /**\n * The height you want the content in its collapsed state.\n *\n * @default 0\n */\n startingHeight?: number | string\n}\n\nconst {\n PropsContext: CollapsePropsContext,\n usePropsContext: useCollapsePropsContext,\n withContext,\n} = createComponent<CollapseProps, CollapseStyle>(\"collapse\", collapseStyle)\n\nexport { CollapsePropsContext, useCollapsePropsContext }\n\n/**\n * `Collapse` is a component that allows you to expand or collapse an element for display.\n *\n * @see https://yamada-ui.com/docs/components/collapse\n */\nexport const Collapse = withContext<\"div\", CollapseProps>(\n ({\n style,\n animationOpacity = true,\n delay,\n duration,\n endingHeight = \"auto\",\n open: openProp,\n startingHeight = 0,\n transition: transitionProp,\n transitionEnd,\n unmountOnExit,\n ...rest\n }) => {\n const [mounted, setMounted] = useState(false)\n const animate = openProp || unmountOnExit ? \"enter\" : \"exit\"\n const open = unmountOnExit ? openProp : true\n\n const transition = useMemo(() => {\n if (!mounted) {\n return { enter: { duration: 0 } }\n } else if (transitionProp) {\n return transitionProp\n } else {\n return {\n enter: {\n height: {\n duration: duration ?? 0.3,\n ease: [0.25, 0.1, 0.25, 1],\n },\n opacity: {\n duration: duration ?? 0.4,\n ease: [0.25, 0.1, 0.25, 1],\n },\n },\n exit: {\n height: {\n duration: duration ?? 0.3,\n ease: [0.25, 0.1, 0.25, 1],\n },\n opacity: {\n duration: duration ?? 0.4,\n ease: [0.25, 0.1, 0.25, 1],\n },\n },\n }\n }\n }, [mounted, duration, transitionProp])\n\n const custom = useMemo(\n () => ({\n animationOpacity,\n delay,\n duration,\n endingHeight,\n startingHeight,\n transition,\n transitionEnd,\n }),\n [\n animationOpacity,\n delay,\n duration,\n endingHeight,\n startingHeight,\n transition,\n transitionEnd,\n ],\n )\n\n useEffect(() => {\n if (createdDom()) setMounted(true)\n }, [])\n\n return (\n <AnimatePresence custom={custom} initial={false}>\n {open ? (\n <motion.div\n style={{ overflow: \"hidden\", ...style }}\n animate={animate}\n custom={custom}\n exit=\"exit\"\n initial={unmountOnExit ? \"exit\" : false}\n variants={variants}\n {...rest}\n />\n ) : null}\n </AnimatePresence>\n )\n },\n)()\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,MAAMA,WAAqB;CACzB,QAAQ,EACN,kBACA,OACA,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