UNPKG

dgz-ui

Version:

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

2 lines (1 loc) 1.39 kB
"use strict";const r=require("react"),_=require("./index-DcWZbXs6.cjs"),u=require("./index-t1JFNXJ1.cjs"),p=require("./jsx-runtime-DUiatUiq.cjs");function v(s){const d=s+"CollectionProvider",[M,E]=_.createContextScope(d),[A,m]=M(d,{collectionRef:{current:null},itemMap:new Map}),C=c=>{const{scope:e,children:l}=c,t=r.useRef(null),o=r.useRef(new Map).current;return p.jsxRuntimeExports.jsx(A,{scope:e,itemMap:o,collectionRef:t,children:l})};C.displayName=d;const f=s+"CollectionSlot",N=u.createSlot(f),x=r.forwardRef((c,e)=>{const{scope:l,children:t}=c,o=m(f,l),n=u.useComposedRefs(e,o.collectionRef);return p.jsxRuntimeExports.jsx(N,{ref:n,children:t})});x.displayName=f;const a=s+"CollectionItemSlot",R="data-radix-collection-item",T=u.createSlot(a),I=r.forwardRef((c,e)=>{const{scope:l,children:t,...o}=c,n=r.useRef(null),S=u.useComposedRefs(e,n),i=m(a,l);return r.useEffect(()=>(i.itemMap.set(n,{ref:n,...o}),()=>void i.itemMap.delete(n))),p.jsxRuntimeExports.jsx(T,{[R]:"",ref:S,children:t})});I.displayName=a;function j(c){const e=m(s+"CollectionConsumer",c);return r.useCallback(()=>{const t=e.collectionRef.current;if(!t)return[];const o=Array.from(t.querySelectorAll(`[${R}]`));return Array.from(e.itemMap.values()).sort((i,O)=>o.indexOf(i.ref.current)-o.indexOf(O.ref.current))},[e.collectionRef,e.itemMap])}return[{Provider:C,Slot:x,ItemSlot:I},j,E]}exports.createCollection=v;