UNPKG

@stanfordspezi/spezi-web-design-system

Version:

Stanford Biodesign Digital Health Spezi Web Design System

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