UNPKG

@stanfordspezi/spezi-web-design-system

Version:

Stanford Biodesign Digital Health Spezi Web Design System

2 lines (1 loc) 3.43 kB
"use strict";const a=require("react/jsx-runtime"),S=require("./index-DwV9MiDB.js"),L=require("react"),C=require("./index-Df0u7aLq.js"),v=require("./index-k79m3Yno.js"),x=require("./index-4XkuMsix.js"),F=require("./index-CldYjOhY.js"),B=require("./index-Bbq55jou.js");function G(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const r=G(L);var f="Collapsible",[z,H]=C.createContextScope(f),[J,R]=z(f),T=r.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:o,defaultOpen:s,disabled:c,onOpenChange:i,...b}=e,[p,d]=C.useControllableState({prop:o,defaultProp:s??!1,onChange:i,caller:f});return a.jsx(J,{scope:n,disabled:c,contentId:B.useId(),open:p,onOpenToggle:r.useCallback(()=>d(g=>!g),[d]),children:a.jsx(x.Primitive.div,{"data-state":j(p),"data-disabled":c?"":void 0,...b,ref:t})})});T.displayName=f;var I="CollapsibleTrigger",q=r.forwardRef((e,t)=>{const{__scopeCollapsible:n,...o}=e,s=R(I,n);return a.jsx(x.Primitive.button,{type:"button","aria-controls":s.contentId,"aria-expanded":s.open||!1,"data-state":j(s.open),"data-disabled":s.disabled?"":void 0,disabled:s.disabled,...o,ref:t,onClick:C.composeEventHandlers(e.onClick,s.onOpenToggle)})});q.displayName=I;var h="CollapsibleContent",E=r.forwardRef((e,t)=>{const{forceMount:n,...o}=e,s=R(h,e.__scopeCollapsible);return a.jsx(F.Presence,{present:n||s.open,children:({present:c})=>a.jsx(K,{...o,ref:t,present:c})})});E.displayName=h;var K=r.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:o,children:s,...c}=e,i=R(h,n),[b,p]=r.useState(o),d=r.useRef(null),g=v.useComposedRefs(t,d),y=r.useRef(0),N=y.current,P=r.useRef(0),_=P.current,m=i.open||b,O=r.useRef(m),u=r.useRef(void 0);return r.useEffect(()=>{const l=requestAnimationFrame(()=>O.current=!1);return()=>cancelAnimationFrame(l)},[]),C.useLayoutEffect2(()=>{const l=d.current;if(l){u.current=u.current||{transitionDuration:l.style.transitionDuration,animationName:l.style.animationName},l.style.transitionDuration="0s",l.style.animationName="none";const w=l.getBoundingClientRect();y.current=w.height,P.current=w.width,O.current||(l.style.transitionDuration=u.current.transitionDuration,l.style.animationName=u.current.animationName),p(o)}},[i.open,o]),a.jsx(x.Primitive.div,{"data-state":j(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!m,...c,ref:g,style:{"--radix-collapsible-content-height":N?`${N}px`:void 0,"--radix-collapsible-content-width":_?`${_}px`:void 0,...e.style},children:m&&s})});function j(e){return e?"open":"closed"}var A=T,$=q,D=E;const Q=e=>a.jsx(A,{"data-slot":"collapsible-root",...e}),U=$,M=({className:e,asChild:t=!1,...n})=>{const o=t?v.Slot:"div";return a.jsx(o,{className:S.cn("grid !transition-all data-[state=closed]:grid-rows-[0fr] data-[state=open]:grid-rows-[1fr]",e),...n})},k=({className:e,asChild:t=!1,...n})=>{const o=t?v.Slot:"div";return a.jsx(o,{className:S.cn("overflow-hidden",e),...n})},V=({children:e,...t})=>a.jsx(D,{asChild:!0,forceMount:!0,...t,children:a.jsx(M,{children:a.jsx(k,{children:e})})});exports.CollapsibleContent=V;exports.CollapsibleContentInner=k;exports.CollapsibleContentRoot=M;exports.CollapsibleRoot=Q;exports.CollapsibleTrigger=U;exports.Content=D;exports.Root=A;exports.Trigger=$;exports.createCollapsibleScope=H;