dgz-ui
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript
2 lines (1 loc) • 5.97 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../jsx-runtime-h4oGeKUK.cjs"),l=require("react"),Z=require("../index-Dyp2JWEo.cjs"),H=require("../index-DG_2LC46.cjs"),ee=require("../index-C1oWDt_I.cjs"),y=require("../index-2AoaKL3W.cjs"),$=require("../index-9_bM8_1f.cjs"),v=require("../index-BrVIp8mi.cjs"),oe=require("../index-CrR8uNCV.cjs"),te=require("../chevron-down-DJIIbSYZ.cjs"),S=require("../utils-BeXF6FlA.cjs");function re(e,t,{checkForDefaultPrevented:o=!0}={}){return function(i){if(e==null||e(i),o===!1||!i.defaultPrevented)return t==null?void 0:t(i)}}var d="Accordion",ne=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[D,ce,ie]=H.createCollection(d),[g,Re]=Z.createContextScope(d,[ie,v.createCollapsibleScope]),k=v.createCollapsibleScope(),V=l.forwardRef((e,t)=>{const{type:o,...c}=e,i=c,r=c;return n.jsxRuntimeExports.jsx(D.Provider,{scope:e.__scopeAccordion,children:o==="multiple"?n.jsxRuntimeExports.jsx(de,{...r,ref:t}):n.jsxRuntimeExports.jsx(le,{...i,ref:t})})});V.displayName=d;var[K,se]=g(d),[z,ae]=g(d,{collapsible:!1}),le=l.forwardRef((e,t)=>{const{value:o,defaultValue:c,onValueChange:i=()=>{},collapsible:r=!1,...a}=e,[s,u]=y.useControllableState({prop:o,defaultProp:c??"",onChange:i,caller:d});return n.jsxRuntimeExports.jsx(K,{scope:e.__scopeAccordion,value:l.useMemo(()=>s?[s]:[],[s]),onItemOpen:u,onItemClose:l.useCallback(()=>r&&u(""),[r,u]),children:n.jsxRuntimeExports.jsx(z,{scope:e.__scopeAccordion,collapsible:r,children:n.jsxRuntimeExports.jsx(L,{...a,ref:t})})})}),de=l.forwardRef((e,t)=>{const{value:o,defaultValue:c,onValueChange:i=()=>{},...r}=e,[a,s]=y.useControllableState({prop:o,defaultProp:c??[],onChange:i,caller:d}),u=l.useCallback(f=>s((p=[])=>[...p,f]),[s]),m=l.useCallback(f=>s((p=[])=>p.filter(R=>R!==f)),[s]);return n.jsxRuntimeExports.jsx(K,{scope:e.__scopeAccordion,value:a,onItemOpen:u,onItemClose:m,children:n.jsxRuntimeExports.jsx(z,{scope:e.__scopeAccordion,collapsible:!0,children:n.jsxRuntimeExports.jsx(L,{...r,ref:t})})})}),[ue,b]=g(d),L=l.forwardRef((e,t)=>{const{__scopeAccordion:o,disabled:c,dir:i,orientation:r="vertical",...a}=e,s=l.useRef(null),u=ee.useComposedRefs(s,t),m=ce(o),p=oe.useDirection(i)==="ltr",R=re(e.onKeyDown,A=>{var O;if(!ne.includes(A.key))return;const W=A.target,h=m().filter(P=>{var M;return!((M=P.ref.current)!=null&&M.disabled)}),j=h.findIndex(P=>P.ref.current===W),q=h.length;if(j===-1)return;A.preventDefault();let x=j;const I=0,E=q-1,w=()=>{x=j+1,x>E&&(x=I)},_=()=>{x=j-1,x<I&&(x=E)};switch(A.key){case"Home":x=I;break;case"End":x=E;break;case"ArrowRight":r==="horizontal"&&(p?w():_());break;case"ArrowDown":r==="vertical"&&w();break;case"ArrowLeft":r==="horizontal"&&(p?_():w());break;case"ArrowUp":r==="vertical"&&_();break}const X=x%q;(O=h[X].ref.current)==null||O.focus()});return n.jsxRuntimeExports.jsx(ue,{scope:o,disabled:c,direction:i,orientation:r,children:n.jsxRuntimeExports.jsx(D.Slot,{scope:o,children:n.jsxRuntimeExports.jsx($.Primitive.div,{...a,"data-orientation":r,ref:u,onKeyDown:c?void 0:R})})})}),C="AccordionItem",[xe,T]=g(C),G=l.forwardRef((e,t)=>{const{__scopeAccordion:o,value:c,...i}=e,r=b(C,o),a=se(C,o),s=k(o),u=y.useId(),m=c&&a.value.includes(c)||!1,f=r.disabled||e.disabled;return n.jsxRuntimeExports.jsx(xe,{scope:o,open:m,disabled:f,triggerId:u,children:n.jsxRuntimeExports.jsx(v.Root,{"data-orientation":r.orientation,"data-state":Q(m),...s,...i,ref:t,disabled:f,open:m,onOpenChange:p=>{p?a.onItemOpen(c):a.onItemClose(c)}})})});G.displayName=C;var U="AccordionHeader",Y=l.forwardRef((e,t)=>{const{__scopeAccordion:o,...c}=e,i=b(d,o),r=T(U,o);return n.jsxRuntimeExports.jsx($.Primitive.h3,{"data-orientation":i.orientation,"data-state":Q(r.open),"data-disabled":r.disabled?"":void 0,...c,ref:t})});Y.displayName=U;var N="AccordionTrigger",B=l.forwardRef((e,t)=>{const{__scopeAccordion:o,...c}=e,i=b(d,o),r=T(N,o),a=ae(N,o),s=k(o);return n.jsxRuntimeExports.jsx(D.ItemSlot,{scope:o,children:n.jsxRuntimeExports.jsx(v.Trigger,{"aria-disabled":r.open&&!a.collapsible||void 0,"data-orientation":i.orientation,id:r.triggerId,...s,...c,ref:t})})});B.displayName=N;var F="AccordionContent",J=l.forwardRef((e,t)=>{const{__scopeAccordion:o,...c}=e,i=b(d,o),r=T(F,o),a=k(o);return n.jsxRuntimeExports.jsx(v.Content,{role:"region","aria-labelledby":r.triggerId,"data-orientation":i.orientation,...a,...c,ref:t,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...e.style}})});J.displayName=F;function Q(e){return e?"open":"closed"}var pe=V,me=G,fe=Y,ve=B,Ae=J;function je({...e}){return n.jsxRuntimeExports.jsx(pe,{"data-slot":"accordion",...e})}function Ce({className:e,...t}){return n.jsxRuntimeExports.jsx(me,{"data-slot":"accordion-item",className:S.cn("border-b last:border-b-0",e),...t})}function ge({className:e,children:t,...o}){return n.jsxRuntimeExports.jsx(fe,{className:"flex",children:n.jsxRuntimeExports.jsxs(ve,{"data-slot":"accordion-trigger",className:S.cn("focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",e),...o,children:[t,n.jsxRuntimeExports.jsx(te.ChevronDown,{className:"text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200"})]})})}function be({className:e,children:t,...o}){return n.jsxRuntimeExports.jsx(Ae,{"data-slot":"accordion-content",className:"data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm",...o,children:n.jsxRuntimeExports.jsx("div",{className:S.cn("pt-0 pb-4",e),children:t})})}exports.Accordion=je;exports.AccordionContent=be;exports.AccordionItem=Ce;exports.AccordionTrigger=ge;