sui-explorer-local
Version:
Local Sui Explorer
8 lines (7 loc) • 2.77 kB
JavaScript
import{j as e}from"./jsx-runtime-ffb262ed.js";import{c as w}from"./clsx-0839fdbe.js";import{r as o}from"./index-76fb7be0.js";import{L}from"./Link-0a628896.js";import{C as b}from"./ChevronUp12-a03638a4.js";import{T as h}from"./Text-6932fd32.js";import"./_commonjsHelpers-de833af9.js";import"./index-dca19ccf.js";import"./index-d3ea75b5.js";import"./index-1489375c.js";import"./sizeAndWeight-05769a6b.js";const c=o.createContext(null);function j(){const t=o.useContext(c);if(!t)throw new Error("ExpandableListItems must be used within an ExpandableList");const{showAll:r,items:s,defaultItemsToShow:n}=t,l=o.useMemo(()=>r?s:s==null?void 0:s.slice(0,n),[r,s,n]);return e.jsx(e.Fragment,{children:l})}function E(){const t=o.useContext(c);if(!t)throw new Error("ExpandableListControl must be used within an ExpandableList");const{handleShowAllClick:r,showAll:s,items:n,itemsLabel:l,defaultItemsToShow:d}=t;let a="";return s?a="Show Less":a=l?`Show All ${n.length} ${l}`:"Show All",n.length<=d?null:e.jsx("div",{className:"flex cursor-pointer items-center gap-1 text-steel hover:text-steel-dark",children:e.jsx(L,{variant:"text",onClick:r,children:e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx(h,{variant:"bodySmall/medium",children:a}),e.jsx(b,{className:w("h-3 w-3",s?"":"rotate-90")})]})})})}function m({items:t,defaultItemsToShow:r,itemsLabel:s,children:n}){const[l,d]=o.useState(!1),a=()=>d(f=>!f);return e.jsx(c.Provider,{value:{handleShowAllClick:a,showAll:l,items:t,defaultItemsToShow:r,itemsLabel:s},children:n||e.jsxs(e.Fragment,{children:[e.jsx(j,{}),e.jsx(E,{})]})})}try{m.displayName="ExpandableList",m.__docgenInfo={description:"",displayName:"ExpandableList",props:{items:{defaultValue:null,description:"",name:"items",required:!0,type:{name:"ReactNode[]"}},defaultItemsToShow:{defaultValue:null,description:"",name:"defaultItemsToShow",required:!0,type:{name:"number"}},itemsLabel:{defaultValue:null,description:"",name:"itemsLabel",required:!1,type:{name:"string"}}}}}catch{}const D={component:m};function S({children:t}){return e.jsx("li",{children:e.jsx(h,{color:"steel-darker",variant:"bodySmall/normal",children:t})})}const i={render:()=>e.jsx("ul",{children:e.jsx(m,{defaultItemsToShow:3,items:Array.from({length:10}).map((t,r)=>e.jsxs(S,{children:["Item ",r]},r))})})};var u,p,x;i.parameters={...i.parameters,docs:{...(u=i.parameters)==null?void 0:u.docs,source:{originalSource:`{
render: () => <ul>
<ExpandableList defaultItemsToShow={3} items={Array.from({
length: 10
}).map((_, index) => <ListItem key={index}>Item {index}</ListItem>)} />
</ul>
}`,...(x=(p=i.parameters)==null?void 0:p.docs)==null?void 0:x.source}}};const V=["Default"];export{i as Default,V as __namedExportsOrder,D as default};