UNPKG

dgz-ui

Version:

Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript

2 lines (1 loc) 5.1 kB
"use strict";const L=require("react"),h=require("./index-Dyp2JWEo.cjs"),w=require("./index-2AoaKL3W.cjs"),j=require("./index-C1oWDt_I.cjs"),O=require("./index-9_bM8_1f.cjs"),g=require("./jsx-runtime-h4oGeKUK.cjs");function U(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 i=U(L);function F(e,t,{checkForDefaultPrevented:n=!0}={}){return function(r){if(e==null||e(r),n===!1||!r.defaultPrevented)return t==null?void 0:t(r)}}function q(e,t){return i.useReducer((n,o)=>t[n][o]??n,e)}var I=e=>{const{present:t,children:n}=e,o=W(t),r=typeof n=="function"?n({present:o.isPresent}):i.Children.only(n),c=j.useComposedRefs(o.ref,k(r));return typeof n=="function"||o.isPresent?i.cloneElement(r,{ref:c}):null};I.displayName="Presence";function W(e){const[t,n]=i.useState(),o=i.useRef(null),r=i.useRef(e),c=i.useRef("none"),u=e?"mounted":"unmounted",[m,a]=q(u,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return i.useEffect(()=>{const s=v(o.current);c.current=m==="mounted"?s:"none"},[m]),h.useLayoutEffect2(()=>{const s=o.current,f=r.current;if(f!==e){const N=c.current,l=v(s);e?a("MOUNT"):l==="none"||(s==null?void 0:s.display)==="none"?a("UNMOUNT"):a(f&&N!==l?"ANIMATION_OUT":"UNMOUNT"),r.current=e}},[e,a]),h.useLayoutEffect2(()=>{if(t){let s;const f=t.ownerDocument.defaultView??window,p=l=>{const C=v(o.current).includes(CSS.escape(l.animationName));if(l.target===t&&C&&(a("ANIMATION_END"),!r.current)){const R=t.style.animationFillMode;t.style.animationFillMode="forwards",s=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=R)})}},N=l=>{l.target===t&&(c.current=v(o.current))};return t.addEventListener("animationstart",N),t.addEventListener("animationcancel",p),t.addEventListener("animationend",p),()=>{f.clearTimeout(s),t.removeEventListener("animationstart",N),t.removeEventListener("animationcancel",p),t.removeEventListener("animationend",p)}}else a("ANIMATION_END")},[t,a]),{isPresent:["mounted","unmountSuspended"].includes(m),ref:i.useCallback(s=>{o.current=s?getComputedStyle(s):null,n(s)},[])}}function v(e){return(e==null?void 0:e.animationName)||"none"}function k(e){var o,r;let t=(o=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(r=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var A="Collapsible",[$,B]=h.createContextScope(A),[G,P]=$(A),_=i.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:o,defaultOpen:r,disabled:c,onOpenChange:u,...m}=e,[a,s]=w.useControllableState({prop:o,defaultProp:r??!1,onChange:u,caller:A});return g.jsxRuntimeExports.jsx(G,{scope:n,disabled:c,contentId:w.useId(),open:a,onOpenToggle:i.useCallback(()=>s(f=>!f),[s]),children:g.jsxRuntimeExports.jsx(O.Primitive.div,{"data-state":E(a),"data-disabled":c?"":void 0,...m,ref:t})})});_.displayName=A;var D="CollapsibleTrigger",y=i.forwardRef((e,t)=>{const{__scopeCollapsible:n,...o}=e,r=P(D,n);return g.jsxRuntimeExports.jsx(O.Primitive.button,{type:"button","aria-controls":r.contentId,"aria-expanded":r.open||!1,"data-state":E(r.open),"data-disabled":r.disabled?"":void 0,disabled:r.disabled,...o,ref:t,onClick:F(e.onClick,r.onOpenToggle)})});y.displayName=D;var T="CollapsibleContent",M=i.forwardRef((e,t)=>{const{forceMount:n,...o}=e,r=P(T,e.__scopeCollapsible);return g.jsxRuntimeExports.jsx(I,{present:n||r.open,children:({present:c})=>g.jsxRuntimeExports.jsx(z,{...o,ref:t,present:c})})});M.displayName=T;var z=i.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:o,children:r,...c}=e,u=P(T,n),[m,a]=i.useState(o),s=i.useRef(null),f=j.useComposedRefs(t,s),p=i.useRef(0),N=p.current,l=i.useRef(0),b=l.current,C=u.open||m,R=i.useRef(C),x=i.useRef(void 0);return i.useEffect(()=>{const d=requestAnimationFrame(()=>R.current=!1);return()=>cancelAnimationFrame(d)},[]),h.useLayoutEffect2(()=>{const d=s.current;if(d){x.current=x.current||{transitionDuration:d.style.transitionDuration,animationName:d.style.animationName},d.style.transitionDuration="0s",d.style.animationName="none";const S=d.getBoundingClientRect();p.current=S.height,l.current=S.width,R.current||(d.style.transitionDuration=x.current.transitionDuration,d.style.animationName=x.current.animationName),a(o)}},[u.open,o]),g.jsxRuntimeExports.jsx(O.Primitive.div,{"data-state":E(u.open),"data-disabled":u.disabled?"":void 0,id:u.contentId,hidden:!C,...c,ref:f,style:{"--radix-collapsible-content-height":N?`${N}px`:void 0,"--radix-collapsible-content-width":b?`${b}px`:void 0,...e.style},children:C&&r})});function E(e){return e?"open":"closed"}var V=_,J=y,K=M;exports.CollapsibleContent=M;exports.CollapsibleTrigger=y;exports.Content=K;exports.Root=V;exports.Trigger=J;exports.createCollapsibleScope=B;