{"version":3,"sources":["../src/collapse.tsx"],"sourcesContent":["import type { CSSUIObject, ThemeProps } from \"@yamada-ui/core\"\nimport type {\n  MotionProps,\n  MotionTransitionVariants,\n  MotionVariants,\n  WithTransitionProps,\n} from \"@yamada-ui/motion\"\nimport { omitThemeProps, useComponentStyle } from \"@yamada-ui/core\"\nimport {\n  AnimatePresence,\n  motion,\n  MOTION_TRANSITION_EASINGS,\n  motionForwardRef,\n  transitionEnter,\n  transitionExit,\n} from \"@yamada-ui/motion\"\nimport { createdDom, cx } from \"@yamada-ui/utils\"\nimport { useEffect, useMemo, useState } from \"react\"\n\nconst isNumeric = (value?: number | string) =>\n  value != null && parseFloat(value.toString()) > 0\n\nconst variants: MotionVariants = {\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: transitionEnter(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: transitionExit(transition?.exit)(delay, duration),\n    transitionEnd: transitionEnd?.exit,\n    ...exit,\n  }),\n} satisfies MotionTransitionVariants\n\nexport const collapseProps = {\n  animate: \"enter\",\n  exit: \"exit\",\n  initial: \"exit\",\n  variants,\n}\n\ninterface CollapseOptions {\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\nexport interface CollapseProps\n  extends WithTransitionProps<MotionProps>,\n    CollapseOptions,\n    ThemeProps<\"Collapse\"> {}\n\n/**\n * `Collapse` is a component that allows you to expand or collapse an element for display.\n *\n * @see Docs https://yamada-ui.com/components/transitions/collapse\n */\nexport const Collapse = motionForwardRef<CollapseProps, \"div\">((props, ref) => {\n  const [style, mergedProps] = useComponentStyle(\"Collapse\", props)\n  const {\n    className,\n    animationOpacity,\n    delay,\n    duration,\n    endingHeight,\n    isOpen,\n    open = isOpen,\n    startingHeight,\n    transition: transitionProp,\n    transitionEnd,\n    unmountOnExit,\n    __css,\n    ...rest\n  } = omitThemeProps(mergedProps)\n  const [mounted, setMounted] = useState(false)\n  const animate = open || unmountOnExit ? \"enter\" : \"exit\"\n  const resolvedOpen = unmountOnExit ? open : true\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: MOTION_TRANSITION_EASINGS.ease,\n          },\n          opacity: {\n            duration: duration ?? 0.4,\n            ease: MOTION_TRANSITION_EASINGS.ease,\n          },\n        },\n        exit: {\n          height: {\n            duration: duration ?? 0.3,\n            ease: MOTION_TRANSITION_EASINGS.ease,\n          },\n          opacity: {\n            duration: duration ?? 0.4,\n            ease: MOTION_TRANSITION_EASINGS.ease,\n          },\n        },\n      }\n    }\n  }, [mounted, duration, transitionProp])\n  const custom = {\n    animationOpacity,\n    delay,\n    duration,\n    endingHeight,\n    startingHeight,\n    transition,\n    transitionEnd,\n  }\n  const css: CSSUIObject = {\n    ...style,\n    ...__css,\n  }\n\n  useEffect(() => {\n    if (createdDom()) setMounted(true)\n  }, [])\n\n  return (\n    <AnimatePresence custom={custom} initial={false}>\n      {resolvedOpen ? (\n        <motion.div\n          ref={ref}\n          className={cx(\"ui-collapse\", className)}\n          {...rest}\n          {...collapseProps}\n          style={{ overflow: \"hidden\", ...rest.style }}\n          animate={animate}\n          custom={custom}\n          initial={unmountOnExit ? \"exit\" : false}\n          __css={css}\n        />\n      ) : null}\n    </AnimatePresence>\n  )\n})\n\nCollapse.displayName = \"Collapse\"\nCollapse.__ui__ = \"Collapse\"\n"],"mappings":";;;AAOA,SAAS,gBAAgB,yBAAyB;AAClD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAY,UAAU;AAC/B,SAAS,WAAW,SAAS,gBAAgB;AAmJrC;AAjJR,IAAM,YAAY,CAAC,UACjB,SAAS,QAAQ,WAAW,MAAM,SAAS,CAAC,IAAI;AAElD,IAAM,WAA2B;AAAA,EAC/B,OAAO,CAAC;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,CAAC,OAAO;AAAA,IACV,GAAI,mBAAmB,EAAE,SAAS,EAAE,IAAI,CAAC;AAAA,IACzC;AAAA,IACA,YAAY,gBAAgB,yCAAY,KAAK,EAAE,OAAO,QAAQ;AAAA,IAC9D,eAAe,+CAAe;AAAA,IAC9B,GAAG;AAAA,EACL;AAAA,EACA,MAAM,CAAC;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB;AAAA,IACA;AAAA,EACF,IAAI,CAAC,OAAO;AAAA,IACV,GAAI,mBAAmB,EAAE,SAAS,UAAU,MAAM,IAAI,IAAI,EAAE,IAAI,CAAC;AAAA,IACjE;AAAA,IACA,YAAY,eAAe,yCAAY,IAAI,EAAE,OAAO,QAAQ;AAAA,IAC5D,eAAe,+CAAe;AAAA,IAC9B,GAAG;AAAA,EACL;AACF;AAEO,IAAM,gBAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,MAAM;AAAA,EACN,SAAS;AAAA,EACT;AACF;AAiCO,IAAM,WAAW,iBAAuC,CAAC,OAAO,QAAQ;AAC7E,QAAM,CAAC,OAAO,WAAW,IAAI,kBAAkB,YAAY,KAAK;AAChE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