"use client"; import { useId } from "./chunk-ZZUMGTHG.js"; import { Presence } from "./chunk-MZLEVI2I.js"; import { useControllableState } from "./chunk-I6MWER2B.js"; import { composeEventHandlers, createContextScope, useLayoutEffect2 } from "./chunk-ILYE3ZA7.js"; import { Primitive } from "./chunk-H55D7VYG.js"; import "./chunk-R6S4VRB5.js"; import { useComposedRefs } from "./chunk-4WIT4MX7.js"; import { require_jsx_runtime } from "./chunk-S77I6LSE.js"; import { require_react } from "./chunk-3TFVT2CW.js"; import { __toESM } from "./chunk-4MBMRILA.js"; // node_modules/@radix-ui/react-collapsible/dist/index.mjs var React = __toESM(require_react(), 1); var import_jsx_runtime = __toESM(require_jsx_runtime(), 1); var COLLAPSIBLE_NAME = "Collapsible"; var [createCollapsibleContext, createCollapsibleScope] = createContextScope(COLLAPSIBLE_NAME); var [CollapsibleProvider, useCollapsibleContext] = createCollapsibleContext(COLLAPSIBLE_NAME); var Collapsible = React.forwardRef( (props, forwardedRef) => { const { __scopeCollapsible, open: openProp, defaultOpen, disabled, onOpenChange, ...collapsibleProps } = props; const [open = false, setOpen] = useControllableState({ prop: openProp, defaultProp: defaultOpen, onChange: onOpenChange }); return (0, import_jsx_runtime.jsx)( CollapsibleProvider, { scope: __scopeCollapsible, disabled, contentId: useId(), open, onOpenToggle: React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen]), children: (0, import_jsx_runtime.jsx)( Primitive.div, { "data-state": getState(open), "data-disabled": disabled ? "" : void 0, ...collapsibleProps, ref: forwardedRef } ) } ); } ); Collapsible.displayName = COLLAPSIBLE_NAME; var TRIGGER_NAME = "CollapsibleTrigger"; var CollapsibleTrigger = React.forwardRef( (props, forwardedRef) => { const { __scopeCollapsible, ...triggerProps } = props; const context = useCollapsibleContext(TRIGGER_NAME, __scopeCollapsible); return (0, import_jsx_runtime.jsx)( Primitive.button, { type: "button", "aria-controls": context.contentId, "aria-expanded": context.open || false, "data-state": getState(context.open), "data-disabled": context.disabled ? "" : void 0, disabled: context.disabled, ...triggerProps, ref: forwardedRef, onClick: composeEventHandlers(props.onClick, context.onOpenToggle) } ); } ); CollapsibleTrigger.displayName = TRIGGER_NAME; var CONTENT_NAME = "CollapsibleContent"; var CollapsibleContent = React.forwardRef( (props, forwardedRef) => { const { forceMount, ...contentProps } = props; const context = useCollapsibleContext(CONTENT_NAME, props.__scopeCollapsible); return (0, import_jsx_runtime.jsx)(Presence, { present: forceMount || context.open, children: ({ present }) => (0, import_jsx_runtime.jsx)(CollapsibleContentImpl, { ...contentProps, ref: forwardedRef, present }) }); } ); CollapsibleContent.displayName = CONTENT_NAME; var CollapsibleContentImpl = React.forwardRef((props, forwardedRef) => { const { __scopeCollapsible, present, children, ...contentProps } = props; const context = useCollapsibleContext(CONTENT_NAME, __scopeCollapsible); const [isPresent, setIsPresent] = React.useState(present); const ref = React.useRef(null); const composedRefs = useComposedRefs(forwardedRef, ref); const heightRef = React.useRef(0); const height = heightRef.current; const widthRef = React.useRef(0); const width = widthRef.current; const isOpen = context.open || isPresent; const isMountAnimationPreventedRef = React.useRef(isOpen); const originalStylesRef = React.useRef(); React.useEffect(() => { const rAF = requestAnimationFrame(() => isMountAnimationPreventedRef.current = false); return () => cancelAnimationFrame(rAF); }, []); useLayoutEffect2(() => { const node = ref.current; if (node) { originalStylesRef.current = originalStylesRef.current || { transitionDuration: node.style.transitionDuration, animationName: node.style.animationName }; node.style.transitionDuration = "0s"; node.style.animationName = "none"; const rect = node.getBoundingClientRect(); heightRef.current = rect.height; widthRef.current = rect.width; if (!isMountAnimationPreventedRef.current) { node.style.transitionDuration = originalStylesRef.current.transitionDuration; node.style.animationName = originalStylesRef.current.animationName; } setIsPresent(present); } }, [context.open, present]); return (0, import_jsx_runtime.jsx)( Primitive.div, { "data-state": getState(context.open), "data-disabled": context.disabled ? "" : void 0, id: context.contentId, hidden: !isOpen, ...contentProps, ref: composedRefs, style: { [`--radix-collapsible-content-height`]: height ? `${height}px` : void 0, [`--radix-collapsible-content-width`]: width ? `${width}px` : void 0, ...props.style }, children: isOpen && children } ); }); function getState(open) { return open ? "open" : "closed"; } var Root = Collapsible; var Trigger = CollapsibleTrigger; var Content = CollapsibleContent; export { Collapsible, CollapsibleContent, CollapsibleTrigger, Content, Root, Trigger, createCollapsibleScope }; //# sourceMappingURL=@radix-ui_react-collapsible.js.map