UNPKG

siegel

Version:

Web application development ecosystem

1 lines 1.85 kB
import e,{useState as t,useMemo as i}from"react";import l from"../_internals/resolve_tag_attributes.js";import m from"../../../common/is/exists/index.js";import r from"../_internals/apply_classname.js";import a from"../_internals/component.js";import n from"../_internals/ref_apply.js";let s=void 0,_="-ui-accordion",o=(e,t)=>m(t)?`${t}.${e}`:e,c=e=>({expandedPaths:e?i(()=>(function e(t,i){let l={};return t.forEach((t,m)=>{let{id:r,children:a}=t;if(a){let t=o(r||m,i);l[t]=!0,Object.assign(l,e(a,t))}}),l})(e),[]):{}}),p=a(_,{theme:{root:s,item:s,item__empty:s,item__expanded:s,item_title_wrapper:s,item_title:s,nested_list:s}},i=>{let{className:m,theme:a,list:_,builder:p,accordionIcon:d,soloOpen:f,rootTagAttributes:u,autoExpand:h,store:x}=i,[y,E]=x||t(c(h?_:s)),{expandedPaths:j}=y,N={className:r(a.nested_list,[[m,!0]]),children:_.map((t,i)=>(function t(i,l,m,n){let s,{children:_,id:c}=i,u=o(c||l,m),h=j[u],x={item:a.item,item__empty:a.item__empty,item__expanded:a.item__expanded,item_title_wrapper:a.item_title_wrapper,item_title:a.item_title,nested_list:a.nested_list};if(p){let{elem:e,acc:t}=p({listItemTheme:x,listItem:i,index:l,acc:n});n=t,s=e}else s=i.title;if(!_)return e.createElement("li",{key:u,className:x.item__empty,children:s});{let i=_.map((e,i)=>t(e,i,u,n)),l=r(x.item,[[x.item__expanded,h]]);return e.createElement("li",{key:u,className:l},e.createElement("div",{className:x.item_title_wrapper,onMouseDown:function(){let e=h||f?Object.keys(j):[];h?e.forEach(e=>{e.startsWith(u)&&delete j[e]}):(f&&e.forEach(e=>{`${u}`.startsWith(e)||delete j[e]}),j[u]=!0),E({expandedPaths:j})}},e.createElement("div",{className:x.item_title,children:s}),d),e.createElement("ul",{className:x.nested_list,children:i}))}})(t,i))};return n(N,i),N=l(N,u),e.createElement("ul",{...N})});export default p;export{_ as componentID,c as getDefaultState};