zaravand-ui 7.1.0 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Table/Table.cjs +1 -1
- package/dist/components/Table/Table.interface.d.cts +41 -0
- package/dist/components/Table/Table.interface.d.ts +41 -0
- package/dist/components/Table/Table.js +335 -318
- package/dist/components/Table/Table.utils.cjs +1 -1
- package/dist/components/Table/Table.utils.d.cts +2 -0
- package/dist/components/Table/Table.utils.d.ts +2 -0
- package/dist/components/Table/Table.utils.js +20 -16
- package/dist/components/Table/TableActionsContext.cjs +1 -0
- package/dist/components/Table/TableActionsContext.d.cts +26 -0
- package/dist/components/Table/TableActionsContext.d.ts +26 -0
- package/dist/components/Table/TableActionsContext.js +5 -0
- package/dist/components/Table/TableParts.cjs +1 -1
- package/dist/components/Table/TableParts.js +56 -34
- package/dist/components/Table/TableRowActions.cjs +1 -0
- package/dist/components/Table/TableRowActions.d.cts +14 -0
- package/dist/components/Table/TableRowActions.d.ts +14 -0
- package/dist/components/Table/TableRowActions.js +110 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +9 -8
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../../config/useZuiConfig.cjs`),n=require(`../../services/localizeDigits/localizeDigits.cjs`),r=require(`../../lib/utils.cjs`),i=require(`../shared/responsiveScale.cjs`),a=require(`../shared/ActionSheet.cjs`),o=require(`../shared/FieldClearButton.cjs`),s=require(`../shared/IconActionButton.cjs`),c=require(`../shared/useExclusiveAction.cjs`),ee=require(`../shared/useStickyToolbar.cjs`),te=require(`../shared/viewport.cjs`),ne=require(`../Select/Select.cjs`),l=require(`./Table.constants.cjs`),u=require(`./Table.utils.cjs`),re=require(`./Table.variant.cjs`),ie=require(`./TableActiveFilters.cjs`),ae=require(`./TableFilterRegistry.cjs`),oe=require(`./TableColumnFilter.cjs`),se=require(`./TableEmptyState.cjs`),ce=require(`./TablePaginationControls.cjs`),d=require(`./TableParts.cjs`),le=require(`./TableSkeletonRows.cjs`),ue=require(`./TableSortToggle.cjs`),de=require(`./hooks/useTablePagination.cjs`),fe=require(`./hooks/useTableCardLabels.cjs`),pe=require(`./hooks/useTableFilter.cjs`),me=require(`./hooks/useTableSearch.cjs`),he=require(`./hooks/useTableSort.cjs`);let f=require(`react`);f=e.__toESM(f,1);let p=require(`react/jsx-runtime`),m=require(`lucide-react`);function ge(e){let t=e.target.closest(`button, a, input, textarea, select, label, [role="button"], [role="combobox"], [role="checkbox"]`);return t!==null&&e.currentTarget.contains(t)}var _e=f.forwardRef(function({className:e,containerClassName:_e,loading:h=!1,isMutating:g=!1,stickyHeaderOnScroll:ve=!0,maxVisibleRowsBeforeScroll:ye,allowInfiniteMode:be=!0,stickyToolbar:xe=!0,schema:_,data:v,setData:Se,onAdd:Ce,onImportExcel:we,onEdit:y,onDelete:b,onPrint:x,onPreviewPrint:S,actions:Te,onCellSelectChange:Ee,getRowId:C,showNumberRow:De=!1,showColumnBorder:Oe=!1,showRowBorder:ke=!1,toolbarExtra:Ae,children:je},Me){let{messages:w,digits:T,dir:E}=t.useZuiConfig(),D=f.useMemo(()=>({digits:T,messages:w}),[T,w]),O=f.Children.count(je)>0,[Ne,Pe]=f.useState({}),Fe=f.useMemo(()=>({register:e=>Pe(t=>({...t,[e.column.key]:e})),unregister:e=>Pe(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e)))}),[]),Ie=Object.values(Ne),k=te.useIsMobileViewport(),Le=f.useRef(null),Re=f.useMemo(()=>r.mergeRefs(Me,Le),[Me]);fe.useTableCardLabels(Le,O);let A=f.useMemo(()=>_.columns.filter(e=>e.view),[_.columns]),ze=f.useMemo(()=>A.filter(e=>e.sortable),[A]),j=f.useMemo(()=>A.filter(e=>e.filterable),[A]),Be=typeof Ce==`function`,Ve=typeof we==`function`,M=typeof y==`function`,N=typeof b==`function`,P=typeof x==`function`,F=typeof S==`function`,I=Te??[],He=I.length>0,L=_.searchable??!1,R=De&&!O,Ue=Ae!=null&&Ae!==!1,We=_.pagination,Ge=We?.onSearchChange,Ke=typeof Ge==`function`,qe=M||N||He,z=qe&&!k,{rowNumberColumnStyle:Je,columnStyleByKey:Ye,actionsColumnStyle:Xe}=f.useMemo(()=>u.resolveColumnWidthPercentages(A,R,z),[z,R,A]),Ze=f.useMemo(()=>{let e=_.columns.map(e=>{if(e.type!==`select`&&e.type!==`radio`)return[e.key,[]];if(Array.isArray(e.options)&&e.options.length>0)return[e.key,e.options];if(e.optionsSource)return[e.key,[]];let t=new Set;return v.forEach(n=>{let r=n[e.key];if(typeof r==`string`||typeof r==`number`){let e=String(r).trim();e.length>0&&t.add(e)}}),[e.key,Array.from(t).map(e=>({value:e,label:e}))]});return Object.fromEntries(e)},[v,_.columns]),[Qe,B]=c.useExclusiveAction(),[$e,et]=f.useState(!1),[tt,nt]=f.useState(!1),[rt,it]=f.useState(!1),[at,ot]=f.useState(null),[st,ct]=f.useState(!1),[lt,ut]=f.useState({open:!1,actions:[]}),V=g||Qe,dt=f.useCallback(async()=>{g||!Ce||await B(Ce)},[g,Ce,B]),ft=f.useCallback(async()=>{g||!we||await B(we)},[g,we,B]),H=f.useCallback(async(e,t,n,r)=>{g||await B(()=>e({row:t,rowIndex:n,rowId:r??u.resolveSafeRowId(t,n,C)}))},[C,g,B]),pt=f.useCallback(async(e,t,n)=>{y&&await H(y,e,t,n)},[y,H]),mt=f.useCallback(async(e,t,n)=>{b&&await H(b,e,t,n)},[b,H]),ht=f.useCallback(async(e,t,n,r)=>{await H(e.onClick,t,n,r)},[H]),gt=f.useCallback(async(e,t,n,r,i)=>{if(g)return;let a=i.trim(),o=a.length>0?a:null;if(e[r]===o)return;let s=n??u.resolveSafeRowId(e,t,C),c={...e,[r]:o};await B(async()=>{try{if(Ee&&await Ee({row:c,previousRow:e,rowIndex:t,rowId:s,columnKey:r,value:a})===!1)return;Se(e=>u.replaceRowByIdentifier(e,t,s,C,c))}catch{return}})},[C,g,Ee,B,Se]),_t=f.useCallback((e,t,n)=>{let i=e=>(0,p.jsx)(`span`,{className:r.cn(`zui:inline-flex`,o.CLEAR_ICON_CLASS,`zui:[&>svg]:size-full`),children:e}),a=[];M&&a.push({key:`edit`,label:w.common.edit,icon:i((0,p.jsx)(m.Pencil,{"aria-hidden":`true`})),onSelect:()=>void pt(e,t,n)}),I.forEach((r,o)=>{a.push({key:`custom-${o}`,label:r.tooltip,icon:i(r.icon),onSelect:()=>void ht(r,e,t,n)})}),N&&a.push({key:`delete`,label:w.common.delete,icon:i((0,p.jsx)(m.Trash2,{"aria-hidden":`true`})),danger:!0,onSelect:()=>void mt(e,t,n)}),ut({open:!0,actions:a})},[ht,mt,pt,w.common.delete,w.common.edit,I,N,M]),{searchTerm:vt,normalizedSearchTerm:yt,filteredRows:bt,handleSearchInputChange:xt}=me.useTableSearch({data:v,visibleColumns:A,showSearchInput:L,hasRemoteSearchHandler:Ke,onSearchChange:Ge,getRowId:C,cellFormatOptions:D}),{filteredRows:St,filterValues:U,activeFilterCount:Ct,filterKey:wt,handleFilterChange:Tt,handleFilterClear:Et}=pe.useTableFilter({rows:bt,columns:_.columns,filterConfig:_.filter}),W=f.useMemo(()=>Object.fromEntries(j.map(e=>[e.key,u.resolveFilterOptions(e,v,D)])),[D,v,j]),{sortedRows:G,activeSort:K,handleSortToggle:Dt,handleSortClear:Ot}=he.useTableSort({rows:St,columns:_.columns,sortConfig:_.sort}),kt=f.useCallback(async()=>{x&&await x({rows:G.map(({row:e})=>e),columns:A})},[x,G,A]),At=f.useCallback(async()=>{S&&await S({rows:G.map(({row:e})=>e),columns:A})},[S,G,A]),{pagingMode:q,currentPage:jt,totalPages:Mt,resolvedPageSize:Nt,visibleRows:J,showPagingModeToggle:Pt,shouldRenderPagination:Ft,shouldRenderInfiniteMode:It,canLoadMoreInInfiniteMode:Lt,shouldUseRemotePaging:Rt,shouldUseScrollableRows:zt,tableScrollViewportRef:Bt,tableScrollViewportStyle:Vt,handlePageChange:Ht,handlePagingModeToggle:Ut,handleTableScrollViewport:Wt,isInfiniteRequestPending:Gt}=de.useTablePagination({hasChildren:O,filteredRows:G,paginationConfig:We,loading:h,isRowActionBusy:V,searchKey:`${yt}|${wt}`,sortKey:K?`${K.sortKey}:${K.direction}`:``,maxVisibleRowsBeforeScroll:ye,allowInfiniteMode:be}),Kt=zt&&ve,qt=f.useMemo(()=>u.resolveLoadingRowsCount(_.pagination?.pageSize,v.length),[v.length,_.pagination?.pageSize]),Jt=h&&(J.length===0||Rt&&q===`pagination`),Yt=It&&h&&J.length>0,Xt=It&&J.length>0,Zt=Xt&&(h||Gt),Qt=Xt&&Lt&&!h&&!Gt,$t=Xt&&!Lt&&!h&&!Gt,en=Math.min(qt,Math.max(1,Math.min(Nt,3))),Y=h||V,tn=k?0:+!!M+I.length+ +!!N,nn=q===`pagination`?w.table.switchToInfinite:w.table.switchToPagination,rn=Be||Ve||Pt||P||F,X=k&&!O&&ze.length>0,Z=k&&!O&&j.length>0,Q=!O&&(L||rn||X||Z),an=f.useRef(null),on=f.useRef(null);ee.useStickyToolbar(an,on,k&&xe&&Q);let sn=f.useMemo(()=>{let e=e=>(0,p.jsx)(e,{className:o.CLEAR_ICON_CLASS,"aria-hidden":`true`}),t=ze.map(t=>{let r=K?.sortKey===t.key?K.direction:void 0,i=n.localizeDigits(t.label,T);return{key:t.key,label:r===void 0?i:`${i} (${r===`asc`?w.table.sortAscending:w.table.sortDescending})`,icon:e(r===`asc`?m.ArrowUp:r===`desc`?m.ArrowDown:m.ArrowUpDown),active:r!==void 0,onSelect:()=>Dt(t.key)}});return K&&t.push({key:`clear-sort`,label:w.table.sortDefault,icon:e(m.RotateCcw),onSelect:Ot}),t},[K,T,Ot,Dt,w.table.sortAscending,w.table.sortDefault,w.table.sortDescending,ze]),cn=f.useCallback(e=>{ot(e),ct(!0)},[]),ln=f.useMemo(()=>j.map(e=>{let t=U[e.key],r=t!==void 0&&!u.isEmptyFilterValue(t),i=n.localizeDigits(e.label,T),a=r?n.localizeDigits(u.resolveFilterText(t,W[e.key]??[]),T):``;return{key:e.key,label:r?`${i}: ${a}`:i,icon:(0,p.jsx)(m.Funnel,{className:o.CLEAR_ICON_CLASS,fill:r?`currentColor`:`none`,"aria-hidden":`true`}),active:r,onSelect:()=>cn(e.key)}}),[T,W,U,j,cn]),$=j.find(e=>e.key===at),un=f.useMemo(()=>{let e=e=>(0,p.jsx)(e,{className:o.CLEAR_ICON_CLASS,"aria-hidden":`true`});return[Be?{key:`add`,label:w.common.add,icon:e(m.Plus),onSelect:()=>void dt()}:null,Ve?{key:`import`,label:w.table.importExcel,icon:e(m.FileSpreadsheet),onSelect:()=>void ft()}:null,P?{key:`print`,label:w.table.print,icon:e(m.Printer),onSelect:()=>void kt()}:null,F?{key:`preview-print`,label:w.table.printPreview,icon:e(m.Eye),onSelect:()=>void At()}:null,Pt?{key:`paging-mode`,label:nn,icon:e(q===`pagination`?m.Infinity:m.Rows3),onSelect:Ut}:null].filter(e=>e!==null)},[dt,ft,Ut,At,kt,w.common.add,w.table.importExcel,w.table.print,w.table.printPreview,q,nn,Be,Ve,Pt,F,P]),dn=k&&(un.length>0||X||Z),fn=k&&un.length>1,pn=Ue&&Q&&L,mn=Ue&&Q&&!L,hn=Ue&&!Q,gn=(0,p.jsx)(`div`,{"data-slot":`table-toolbar-extra`,className:r.cn(`zui:flex zui:w-full zui:items-center`,i.CONTROL_HEIGHT_SM),children:Ae});return(0,p.jsxs)(`div`,{"data-slot":`table-container`,dir:E,className:r.cn(re.tableContainerVariants(),_e),children:[O?(0,p.jsx)(ie.default,{columns:Ie.map(e=>e.column),values:Object.fromEntries(Ie.flatMap(e=>e.value?[[e.column.key,e.value]]:[])),optionsByColumn:Object.fromEntries(Ie.map(e=>[e.column.key,e.options])),onRemove:e=>Ne[e]?.onChange(void 0)}):(0,p.jsx)(ie.default,{columns:A,values:U,optionsByColumn:W,onRemove:e=>Tt(e,void 0),onSelect:k?cn:void 0}),hn?(0,p.jsx)(`div`,{"data-slot":`table-toolbar-extra-row`,className:`zui:mb-3`,children:gn}):null,Q?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`div`,{ref:on,"aria-hidden":`true`,"data-slot":`table-sticky-sentinel`}),(0,p.jsxs)(`div`,{ref:an,"data-slot":`table-sticky-toolbar`,"data-sticky-toolbar":k&&xe?`true`:void 0,className:`zui:mb-3`,children:[pn?(0,p.jsx)(`div`,{"data-slot":`table-toolbar-extra-row`,className:`zui:mb-2`,children:gn}):null,(0,p.jsx)(s.ListToolbar,{"data-slot":`table-controls`,searchSlot:`table-search-input`,actionsSlot:`table-add-action`,inlineActionsOnMobile:dn,search:L?{value:vt,onChange:xt,placeholder:w.common.searchPlaceholder,ariaLabel:w.table.searchAriaLabel,disabled:V}:void 0,leading:mn?gn:void 0,actions:X||Z||fn||rn?(0,p.jsxs)(p.Fragment,{children:[X?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-sort-button`,label:w.table.sortBy,disabled:Y,onClick:()=>nt(!0),icon:(0,p.jsx)(m.ArrowUpDown,{"aria-hidden":`true`})}):null,Z?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-filter-button`,label:w.table.filterBy,disabled:Y,onClick:()=>it(!0),icon:(0,p.jsxs)(`span`,{className:`zui:relative zui:inline-flex`,children:[(0,p.jsx)(m.Funnel,{fill:Ct>0?`currentColor`:`none`,"aria-hidden":`true`}),Ct>0?(0,p.jsx)(`span`,{"aria-hidden":`true`,"data-slot":`table-filter-active-dot`,className:`zui:absolute zui:-end-1 zui:-top-1 zui:size-2 zui:rounded-full zui:bg-[var(--zui-theme-action-primary)] zui:ring-2 zui:ring-[var(--zui-color-surface)]`}):null]})}):null,fn?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-toolbar-menu-button`,label:w.table.actions,disabled:Y,onClick:()=>et(!0),icon:(0,p.jsx)(m.EllipsisVertical,{"aria-hidden":`true`})}):rn?(0,p.jsxs)(p.Fragment,{children:[Pt?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-paging-mode-toggle-button`,label:nn,disabled:Y,onClick:Ut,icon:q===`pagination`?(0,p.jsx)(m.Infinity,{className:l.pagingToggleIconClassName,"aria-hidden":`true`}):(0,p.jsx)(m.Rows3,{className:l.pagingToggleIconClassName,"aria-hidden":`true`})}):null,F?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-action-preview-print-button`,label:w.table.printPreview,disabled:Y,onClick:()=>void At(),icon:(0,p.jsx)(m.Eye,{})}):null,P?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-action-print-button`,label:w.table.print,disabled:Y,onClick:()=>void kt(),icon:(0,p.jsx)(m.Printer,{})}):null,Ve?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-action-import-excel-button`,label:w.table.importExcel,disabled:Y,onClick:()=>void ft(),icon:(0,p.jsx)(m.FileSpreadsheet,{})}):null,Be?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-action-add-button`,label:w.common.add,disabled:Y,onClick:()=>void dt(),icon:(0,p.jsx)(m.Plus,{})}):null]}):null]}):void 0})]}),X?(0,p.jsx)(a.default,{open:tt,onOpenChange:nt,actions:sn,label:w.table.sortBy}):null,Z?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(a.default,{open:rt,onOpenChange:it,actions:ln,label:w.table.filterBy}),$?(0,p.jsx)(oe.TableColumnFilterSheet,{column:$,value:U[$.key],onChange:e=>Tt($.key,e),options:W[$.key]??[],open:st,onOpenChange:ct},$.key):null]}):null,fn?(0,p.jsx)(a.default,{open:$e,onOpenChange:et,actions:un.map(e=>({...e,disabled:Y})),label:w.table.actions}):null]}):null,(0,p.jsx)(`div`,{ref:Bt,"data-slot":`table-scroll-viewport`,className:r.cn(`zui:relative zui:w-full zui:min-w-0 zui:overflow-x-auto zui-radius-xs zui:bg-[var(--zui-color-surface)] zui:shadow-[0_4px_14px_-12px_var(--zui-effect-shadow-ink-35)]`,zt?`zui:overflow-y-auto`:void 0),style:Vt,onScroll:Wt,children:(0,p.jsx)(`table`,{ref:Re,"data-slot":`table`,className:r.cn(re.tableVariants({showColumnBorder:Oe,showRowBorder:ke}),e),dir:E,children:O?(0,p.jsx)(ae.TableFilterRegistryContext.Provider,{value:Fe,children:je}):A.length===0?(0,p.jsx)(d.TableBody,{children:(0,p.jsx)(d.TableRow,{children:(0,p.jsx)(d.TableCell,{className:`zui:py-7 zui:text-center zui:text-[var(--zui-color-text)]`,children:w.table.noColumns})})}):(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`colgroup`,{children:[R?(0,p.jsx)(`col`,{style:Je}):null,A.map(e=>(0,p.jsx)(`col`,{style:Ye[e.key]},`col-${e.key}`)),z?(0,p.jsx)(`col`,{style:Xe}):null]}),(0,p.jsx)(d.TableHeader,{children:(0,p.jsxs)(d.TableRow,{children:[R?(0,p.jsx)(d.TableHead,{align:`center`,className:r.cn(l.rowNumberColumnClassName,Kt?l.stickyHeaderCellClassName:void 0),children:w.table.rowNumber}):null,A.map(e=>{let t=e.sortable&&K?.sortKey===e.key?K.direction:void 0,r=e.sortable?(0,p.jsx)(ue.default,{columnLabel:e.label,direction:t,onToggle:()=>Dt(e.key)}):null,i=e.filterable?(0,p.jsx)(oe.default,{column:e,value:U[e.key],onChange:t=>Tt(e.key,t),options:W[e.key]??[]}):null;return(0,p.jsx)(d.TableHead,{align:e.align,className:Kt?l.stickyHeaderCellClassName:void 0,"aria-sort":e.sortable?u.resolveAriaSort(t):void 0,children:e.sortable||e.filterable?(0,p.jsxs)(`span`,{className:`zui:inline-flex zui:items-center zui:gap-2`,children:[n.localizeDigits(e.label,T),(0,p.jsxs)(`span`,{className:`zui:inline-flex zui:items-center`,children:[E===`rtl`?r:i,E===`rtl`?i:r]})]}):n.localizeDigits(e.label,T)},`head-${e.key}`)}),z?(0,p.jsx)(d.TableHead,{align:`center`,className:r.cn(l.actionsColumnClassName,l.actionsColumnStickyClassName,Kt?l.stickyHeaderCellClassName:void 0),children:w.table.actions}):null]})}),(0,p.jsx)(d.TableBody,{children:Jt?(0,p.jsx)(le.default,{count:qt,keyPrefix:`loading`,showRowNumbers:R,columns:A,actionsCount:tn}):J.length===0?(0,p.jsx)(se.default,{colSpan:A.length+ +!!z+ +!!R,showSearchInput:L,normalizedSearchTerm:yt,hasActiveFilters:Ct>0,onClearFilters:Et}):(0,p.jsxs)(p.Fragment,{children:[J.map(({row:e,rowIndex:t,rowId:i},a)=>{let o=i===void 0?`row-${t}`:`row-id-${String(i)}`,c=Ft?(jt-1)*Nt+a+1:a+1;return(0,p.jsxs)(d.TableRow,{...k&&qe?{tabIndex:0,"aria-haspopup":`dialog`,"data-actionable":`true`,onClick:n=>{ge(n)||_t(e,t,i)},onKeyDown:n=>{n.target===n.currentTarget&&(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),_t(e,t,i))}}:{},children:[R?(0,p.jsx)(d.TableCell,{align:`center`,className:l.rowNumberColumnClassName,"data-label":w.table.rowNumber,children:n.localizeDigits(String(c),T)}):null,A.map(r=>{let a=`cell-${r.key}-${o}`;if(r.viewType===`select`){let o=Ze[r.key]??[],s=e[r.key],c=typeof s==`string`||typeof s==`number`?String(s):``;return(0,p.jsx)(d.TableCell,{align:r.align,"data-label":n.localizeDigits(r.label,T),children:(0,p.jsx)(ne.default,{disabled:V||o.length===0&&!r.optionsSource,placeholder:u.resolvePlaceholder(r),options:o,remoteOptions:r.optionsSource,value:c,onValueChange:n=>{let a=Array.isArray(n)?n[0]??``:n;gt(e,t,i,r.key,a)}})},a)}return(0,p.jsx)(d.TableCell,{align:r.align,"data-label":n.localizeDigits(r.label,T),children:u.formatCellValue(e[r.key],r,D)},a)}),z?(0,p.jsx)(d.TableCell,{align:`center`,"data-cell":`actions`,className:r.cn(l.actionsColumnClassName,l.actionsColumnStickyClassName),children:(0,p.jsxs)(`div`,{"data-slot":`table-row-actions`,className:`zui:flex zui:items-center zui:justify-center zui:gap-0.5`,children:[M?(0,p.jsx)(s.IconActionButton,{"data-slot":`table-action-edit-button`,label:w.common.edit,icon:(0,p.jsx)(m.Pencil,{className:l.actionIconClassName,"aria-hidden":`true`}),disabled:V,className:r.cn(l.rowActionButtonClassName,`zui:text-[var(--zui-theme-text-primary)]`),onClick:()=>void pt(e,t,i)}):null,I.map((n,a)=>(0,p.jsx)(s.IconActionButton,{"data-slot":`table-action-custom-button`,label:n.tooltip,icon:n.icon,disabled:V,className:r.cn(l.rowActionButtonClassName,`zui:text-[var(--zui-theme-text-primary)]`),onClick:()=>void ht(n,e,t,i)},`${n.tooltip}-${a}`)),N?(0,p.jsx)(s.IconActionButton,{"data-slot":`table-action-delete-button`,label:w.common.delete,icon:(0,p.jsx)(m.Trash2,{className:l.actionIconClassName,"aria-hidden":`true`}),disabled:V,className:r.cn(l.rowActionButtonClassName,`zui:text-[var(--zui-theme-status-danger)]`),onClick:()=>void mt(e,t,i)}):null]})}):null]},o)}),Yt?(0,p.jsx)(le.default,{count:en,keyPrefix:`infinite-loading`,showRowNumbers:R,columns:A,actionsCount:tn}):null]})})]})})}),k&&qe?(0,p.jsx)(a.default,{open:lt.open,onOpenChange:e=>ut(t=>({...t,open:e})),actions:lt.actions,label:w.table.actions}):null,(0,p.jsx)(ce.default,{shouldRenderInfiniteMode:It,shouldShowInfiniteLoadingStatus:Zt,shouldShowInfiniteReadyStatus:Qt,shouldShowInfiniteCompletedStatus:$t,shouldRenderPagination:Ft,loading:h,isRowActionBusy:V,currentPage:jt,totalPages:Mt,onPageChange:Ht})]})});_e.displayName=`Table`,exports.default=_e;
|
|
1
|
+
"use client";const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../../config/useZuiConfig.cjs`),n=require(`../../services/localizeDigits/localizeDigits.cjs`),r=require(`../../lib/utils.cjs`),i=require(`../shared/responsiveScale.cjs`),a=require(`../shared/ActionSheet.cjs`),o=require(`../shared/FieldClearButton.cjs`),s=require(`../shared/IconActionButton.cjs`),c=require(`../shared/useExclusiveAction.cjs`),ee=require(`../shared/useStickyToolbar.cjs`),te=require(`../shared/viewport.cjs`),ne=require(`../Select/Select.cjs`),re=require(`./TableActionsContext.cjs`),l=require(`./Table.constants.cjs`),u=require(`./Table.utils.cjs`),ie=require(`./Table.variant.cjs`),ae=require(`./TableActiveFilters.cjs`),oe=require(`./TableFilterRegistry.cjs`),se=require(`./TableColumnFilter.cjs`),ce=require(`./TableEmptyState.cjs`),le=require(`./TablePaginationControls.cjs`),d=require(`./TableParts.cjs`),ue=require(`./TableSkeletonRows.cjs`),de=require(`./TableSortToggle.cjs`),fe=require(`./hooks/useTablePagination.cjs`),pe=require(`./hooks/useTableCardLabels.cjs`),me=require(`./hooks/useTableFilter.cjs`),he=require(`./hooks/useTableSearch.cjs`),ge=require(`./hooks/useTableSort.cjs`);let f=require(`react`);f=e.__toESM(f,1);let p=require(`react/jsx-runtime`),m=require(`lucide-react`);var _e=f.forwardRef(function({className:e,containerClassName:_e,loading:h=!1,isMutating:g=!1,stickyHeaderOnScroll:ve=!0,maxVisibleRowsBeforeScroll:ye,allowInfiniteMode:be=!0,stickyToolbar:xe=!0,schema:_,data:v,setData:Se,onAdd:y,onImportExcel:b,onEdit:x,onDelete:Ce,onPrint:we,onPreviewPrint:S,actions:Te,onCellSelectChange:Ee,getRowId:C,showNumberRow:De=!1,showColumnBorder:Oe=!1,showRowBorder:ke=!1,toolbarExtra:Ae,children:je},Me){let{messages:w,digits:T,dir:E}=t.useZuiConfig(),D=f.useMemo(()=>({digits:T,messages:w}),[T,w]),O=f.Children.count(je)>0,[Ne,Pe]=f.useState({}),Fe=f.useMemo(()=>({register:e=>Pe(t=>({...t,[e.column.key]:e})),unregister:e=>Pe(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e)))}),[]),Ie=Object.values(Ne),k=te.useIsMobileViewport(),Le=f.useRef(null),Re=f.useMemo(()=>r.mergeRefs(Me,Le),[Me]);pe.useTableCardLabels(Le,O);let A=f.useMemo(()=>_.columns.filter(e=>e.view),[_.columns]),ze=f.useMemo(()=>A.filter(e=>e.sortable),[A]),j=f.useMemo(()=>A.filter(e=>e.filterable),[A]),Be=typeof y==`function`,Ve=typeof b==`function`,M=typeof x==`function`,N=typeof Ce==`function`,P=typeof we==`function`,F=typeof S==`function`,I=(Te??[]).filter(e=>!e.hidden),He=I.length>0,L=_.searchable??!1,R=De&&!O,Ue=Ae!=null&&Ae!==!1,We=_.pagination,Ge=We?.onSearchChange,Ke=typeof Ge==`function`,qe=M||N||He,z=qe&&!k,{rowNumberColumnStyle:Je,columnStyleByKey:Ye,actionsColumnStyle:Xe}=f.useMemo(()=>u.resolveColumnWidthPercentages(A,R,z),[z,R,A]),Ze=f.useMemo(()=>{let e=_.columns.map(e=>{if(e.type!==`select`&&e.type!==`radio`)return[e.key,[]];if(Array.isArray(e.options)&&e.options.length>0)return[e.key,e.options];if(e.optionsSource)return[e.key,[]];let t=new Set;return v.forEach(n=>{let r=n[e.key];if(typeof r==`string`||typeof r==`number`){let e=String(r).trim();e.length>0&&t.add(e)}}),[e.key,Array.from(t).map(e=>({value:e,label:e}))]});return Object.fromEntries(e)},[v,_.columns]),[Qe,B]=c.useExclusiveAction(),[$e,et]=f.useState(!1),[tt,nt]=f.useState(!1),[rt,it]=f.useState(!1),[at,ot]=f.useState(null),[st,ct]=f.useState(!1),[lt,ut]=f.useState({open:!1,actions:[]}),V=g||Qe,dt=f.useCallback(async()=>{g||!y||await B(y)},[g,y,B]),ft=f.useCallback(async()=>{g||!b||await B(b)},[g,b,B]),H=f.useCallback(async(e,t,n,r)=>{g||await B(()=>e({row:t,rowIndex:n,rowId:r??u.resolveSafeRowId(t,n,C)}))},[C,g,B]),pt=f.useCallback(async(e,t,n)=>{x&&await H(x,e,t,n)},[x,H]),mt=f.useCallback(async(e,t,n)=>{Ce&&await H(Ce,e,t,n)},[Ce,H]),ht=f.useMemo(()=>({isMobile:k,isBusy:V,run:async e=>{g||await B(e)},openRowSheet:e=>ut({open:!0,actions:e})}),[V,k,g,B]),gt=f.useCallback(async(e,t,n,r)=>{await H(e.onClick,t,n,r)},[H]),_t=f.useCallback(async(e,t,n,r,i)=>{if(g)return;let a=i.trim(),o=a.length>0?a:null;if(e[r]===o)return;let s=n??u.resolveSafeRowId(e,t,C),c={...e,[r]:o};await B(async()=>{try{if(Ee&&await Ee({row:c,previousRow:e,rowIndex:t,rowId:s,columnKey:r,value:a})===!1)return;Se(e=>u.replaceRowByIdentifier(e,t,s,C,c))}catch{return}})},[C,g,Ee,B,Se]),vt=f.useCallback((e,t,n)=>{let i=e=>(0,p.jsx)(`span`,{className:r.cn(`zui:inline-flex`,o.CLEAR_ICON_CLASS,`zui:[&>svg]:size-full`),children:e}),a=[];M&&a.push({key:`edit`,label:w.common.edit,icon:i((0,p.jsx)(m.Pencil,{"aria-hidden":`true`})),onSelect:()=>void pt(e,t,n)}),I.forEach((r,o)=>{a.push({key:`custom-${o}`,label:r.tooltip,icon:i(r.icon),danger:r.danger,disabled:r.disabled,onSelect:()=>void gt(r,e,t,n)})}),N&&a.push({key:`delete`,label:w.common.delete,icon:i((0,p.jsx)(m.Trash2,{"aria-hidden":`true`})),danger:!0,onSelect:()=>void mt(e,t,n)}),ut({open:!0,actions:a})},[gt,mt,pt,w.common.delete,w.common.edit,I,N,M]),{searchTerm:yt,normalizedSearchTerm:bt,filteredRows:xt,handleSearchInputChange:St}=he.useTableSearch({data:v,visibleColumns:A,showSearchInput:L,hasRemoteSearchHandler:Ke,onSearchChange:Ge,getRowId:C,cellFormatOptions:D}),{filteredRows:Ct,filterValues:U,activeFilterCount:wt,filterKey:Tt,handleFilterChange:Et,handleFilterClear:Dt}=me.useTableFilter({rows:xt,columns:_.columns,filterConfig:_.filter}),W=f.useMemo(()=>Object.fromEntries(j.map(e=>[e.key,u.resolveFilterOptions(e,v,D)])),[D,v,j]),{sortedRows:G,activeSort:K,handleSortToggle:Ot,handleSortClear:kt}=ge.useTableSort({rows:Ct,columns:_.columns,sortConfig:_.sort}),At=f.useCallback(async()=>{we&&await we({rows:G.map(({row:e})=>e),columns:A})},[we,G,A]),jt=f.useCallback(async()=>{S&&await S({rows:G.map(({row:e})=>e),columns:A})},[S,G,A]),{pagingMode:q,currentPage:Mt,totalPages:Nt,resolvedPageSize:Pt,visibleRows:J,showPagingModeToggle:Ft,shouldRenderPagination:It,shouldRenderInfiniteMode:Lt,canLoadMoreInInfiniteMode:Rt,shouldUseRemotePaging:zt,shouldUseScrollableRows:Bt,tableScrollViewportRef:Vt,tableScrollViewportStyle:Ht,handlePageChange:Ut,handlePagingModeToggle:Wt,handleTableScrollViewport:Gt,isInfiniteRequestPending:Kt}=fe.useTablePagination({hasChildren:O,filteredRows:G,paginationConfig:We,loading:h,isRowActionBusy:V,searchKey:`${bt}|${Tt}`,sortKey:K?`${K.sortKey}:${K.direction}`:``,maxVisibleRowsBeforeScroll:ye,allowInfiniteMode:be}),qt=Bt&&ve,Jt=f.useMemo(()=>u.resolveLoadingRowsCount(_.pagination?.pageSize,v.length),[v.length,_.pagination?.pageSize]),Yt=h&&(J.length===0||zt&&q===`pagination`),Xt=Lt&&h&&J.length>0,Zt=Lt&&J.length>0,Qt=Zt&&(h||Kt),$t=Zt&&Rt&&!h&&!Kt,en=Zt&&!Rt&&!h&&!Kt,tn=Math.min(Jt,Math.max(1,Math.min(Pt,3))),Y=h||V,nn=k?0:+!!M+I.length+ +!!N,rn=q===`pagination`?w.table.switchToInfinite:w.table.switchToPagination,an=Be||Ve||Ft||P||F,X=k&&!O&&ze.length>0,Z=k&&!O&&j.length>0,Q=!O&&(L||an||X||Z),on=f.useRef(null),sn=f.useRef(null);ee.useStickyToolbar(on,sn,k&&xe&&Q);let cn=f.useMemo(()=>{let e=e=>(0,p.jsx)(e,{className:o.CLEAR_ICON_CLASS,"aria-hidden":`true`}),t=ze.map(t=>{let r=K?.sortKey===t.key?K.direction:void 0,i=n.localizeDigits(t.label,T);return{key:t.key,label:r===void 0?i:`${i} (${r===`asc`?w.table.sortAscending:w.table.sortDescending})`,icon:e(r===`asc`?m.ArrowUp:r===`desc`?m.ArrowDown:m.ArrowUpDown),active:r!==void 0,onSelect:()=>Ot(t.key)}});return K&&t.push({key:`clear-sort`,label:w.table.sortDefault,icon:e(m.RotateCcw),onSelect:kt}),t},[K,T,kt,Ot,w.table.sortAscending,w.table.sortDefault,w.table.sortDescending,ze]),ln=f.useCallback(e=>{ot(e),ct(!0)},[]),un=f.useMemo(()=>j.map(e=>{let t=U[e.key],r=t!==void 0&&!u.isEmptyFilterValue(t),i=n.localizeDigits(e.label,T),a=r?n.localizeDigits(u.resolveFilterText(t,W[e.key]??[]),T):``;return{key:e.key,label:r?`${i}: ${a}`:i,icon:(0,p.jsx)(m.Funnel,{className:o.CLEAR_ICON_CLASS,fill:r?`currentColor`:`none`,"aria-hidden":`true`}),active:r,onSelect:()=>ln(e.key)}}),[T,W,U,j,ln]),$=j.find(e=>e.key===at),dn=f.useMemo(()=>{let e=e=>(0,p.jsx)(e,{className:o.CLEAR_ICON_CLASS,"aria-hidden":`true`});return[Be?{key:`add`,label:w.common.add,icon:e(m.Plus),onSelect:()=>void dt()}:null,Ve?{key:`import`,label:w.table.importExcel,icon:e(m.FileSpreadsheet),onSelect:()=>void ft()}:null,P?{key:`print`,label:w.table.print,icon:e(m.Printer),onSelect:()=>void At()}:null,F?{key:`preview-print`,label:w.table.printPreview,icon:e(m.Eye),onSelect:()=>void jt()}:null,Ft?{key:`paging-mode`,label:rn,icon:e(q===`pagination`?m.Infinity:m.Rows3),onSelect:Wt}:null].filter(e=>e!==null)},[dt,ft,Wt,jt,At,w.common.add,w.table.importExcel,w.table.print,w.table.printPreview,q,rn,Be,Ve,Ft,F,P]),fn=k&&(dn.length>0||X||Z),pn=k&&dn.length>1,mn=Ue&&Q&&L,hn=Ue&&Q&&!L,gn=Ue&&!Q,_n=(0,p.jsx)(`div`,{"data-slot":`table-toolbar-extra`,className:r.cn(`zui:flex zui:w-full zui:items-center`,i.CONTROL_HEIGHT_SM),children:Ae});return(0,p.jsxs)(`div`,{"data-slot":`table-container`,dir:E,className:r.cn(ie.tableContainerVariants(),_e),children:[O?(0,p.jsx)(ae.default,{columns:Ie.map(e=>e.column),values:Object.fromEntries(Ie.flatMap(e=>e.value?[[e.column.key,e.value]]:[])),optionsByColumn:Object.fromEntries(Ie.map(e=>[e.column.key,e.options])),onRemove:e=>Ne[e]?.onChange(void 0)}):(0,p.jsx)(ae.default,{columns:A,values:U,optionsByColumn:W,onRemove:e=>Et(e,void 0),onSelect:k?ln:void 0}),gn?(0,p.jsx)(`div`,{"data-slot":`table-toolbar-extra-row`,className:`zui:mb-3`,children:_n}):null,Q?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`div`,{ref:sn,"aria-hidden":`true`,"data-slot":`table-sticky-sentinel`}),(0,p.jsxs)(`div`,{ref:on,"data-slot":`table-sticky-toolbar`,"data-sticky-toolbar":k&&xe?`true`:void 0,className:`zui:mb-3`,children:[mn?(0,p.jsx)(`div`,{"data-slot":`table-toolbar-extra-row`,className:`zui:mb-2`,children:_n}):null,(0,p.jsx)(s.ListToolbar,{"data-slot":`table-controls`,searchSlot:`table-search-input`,actionsSlot:`table-add-action`,inlineActionsOnMobile:fn,search:L?{value:yt,onChange:St,placeholder:w.common.searchPlaceholder,ariaLabel:w.table.searchAriaLabel,disabled:V}:void 0,leading:hn?_n:void 0,actions:X||Z||pn||an?(0,p.jsxs)(p.Fragment,{children:[X?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-sort-button`,label:w.table.sortBy,disabled:Y,onClick:()=>nt(!0),icon:(0,p.jsx)(m.ArrowUpDown,{"aria-hidden":`true`})}):null,Z?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-filter-button`,label:w.table.filterBy,disabled:Y,onClick:()=>it(!0),icon:(0,p.jsxs)(`span`,{className:`zui:relative zui:inline-flex`,children:[(0,p.jsx)(m.Funnel,{fill:wt>0?`currentColor`:`none`,"aria-hidden":`true`}),wt>0?(0,p.jsx)(`span`,{"aria-hidden":`true`,"data-slot":`table-filter-active-dot`,className:`zui:absolute zui:-end-1 zui:-top-1 zui:size-2 zui:rounded-full zui:bg-[var(--zui-theme-action-primary)] zui:ring-2 zui:ring-[var(--zui-color-surface)]`}):null]})}):null,pn?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-toolbar-menu-button`,label:w.table.actions,disabled:Y,onClick:()=>et(!0),icon:(0,p.jsx)(m.EllipsisVertical,{"aria-hidden":`true`})}):an?(0,p.jsxs)(p.Fragment,{children:[Ft?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-paging-mode-toggle-button`,label:rn,disabled:Y,onClick:Wt,icon:q===`pagination`?(0,p.jsx)(m.Infinity,{className:l.pagingToggleIconClassName,"aria-hidden":`true`}):(0,p.jsx)(m.Rows3,{className:l.pagingToggleIconClassName,"aria-hidden":`true`})}):null,F?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-action-preview-print-button`,label:w.table.printPreview,disabled:Y,onClick:()=>void jt(),icon:(0,p.jsx)(m.Eye,{})}):null,P?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-action-print-button`,label:w.table.print,disabled:Y,onClick:()=>void At(),icon:(0,p.jsx)(m.Printer,{})}):null,Ve?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-action-import-excel-button`,label:w.table.importExcel,disabled:Y,onClick:()=>void ft(),icon:(0,p.jsx)(m.FileSpreadsheet,{})}):null,Be?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-action-add-button`,label:w.common.add,disabled:Y,onClick:()=>void dt(),icon:(0,p.jsx)(m.Plus,{})}):null]}):null]}):void 0})]}),X?(0,p.jsx)(a.default,{open:tt,onOpenChange:nt,actions:cn,label:w.table.sortBy}):null,Z?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(a.default,{open:rt,onOpenChange:it,actions:un,label:w.table.filterBy}),$?(0,p.jsx)(se.TableColumnFilterSheet,{column:$,value:U[$.key],onChange:e=>Et($.key,e),options:W[$.key]??[],open:st,onOpenChange:ct},$.key):null]}):null,pn?(0,p.jsx)(a.default,{open:$e,onOpenChange:et,actions:dn.map(e=>({...e,disabled:Y})),label:w.table.actions}):null]}):null,(0,p.jsx)(`div`,{ref:Vt,"data-slot":`table-scroll-viewport`,className:r.cn(`zui:relative zui:w-full zui:min-w-0 zui:overflow-x-auto zui-radius-xs zui:bg-[var(--zui-color-surface)] zui:shadow-[0_4px_14px_-12px_var(--zui-effect-shadow-ink-35)]`,Bt?`zui:overflow-y-auto`:void 0),style:Ht,onScroll:Gt,children:(0,p.jsx)(`table`,{ref:Re,"data-slot":`table`,className:r.cn(ie.tableVariants({showColumnBorder:Oe,showRowBorder:ke}),e),dir:E,children:O?(0,p.jsx)(re.TableActionsContext.Provider,{value:ht,children:(0,p.jsx)(oe.TableFilterRegistryContext.Provider,{value:Fe,children:je})}):A.length===0?(0,p.jsx)(d.TableBody,{children:(0,p.jsx)(d.TableRow,{children:(0,p.jsx)(d.TableCell,{className:`zui:py-7 zui:text-center zui:text-[var(--zui-color-text)]`,children:w.table.noColumns})})}):(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`colgroup`,{children:[R?(0,p.jsx)(`col`,{style:Je}):null,A.map(e=>(0,p.jsx)(`col`,{style:Ye[e.key]},`col-${e.key}`)),z?(0,p.jsx)(`col`,{style:Xe}):null]}),(0,p.jsx)(d.TableHeader,{children:(0,p.jsxs)(d.TableRow,{children:[R?(0,p.jsx)(d.TableHead,{align:`center`,className:r.cn(l.rowNumberColumnClassName,qt?l.stickyHeaderCellClassName:void 0),children:w.table.rowNumber}):null,A.map(e=>{let t=e.sortable&&K?.sortKey===e.key?K.direction:void 0,r=e.sortable?(0,p.jsx)(de.default,{columnLabel:e.label,direction:t,onToggle:()=>Ot(e.key)}):null,i=e.filterable?(0,p.jsx)(se.default,{column:e,value:U[e.key],onChange:t=>Et(e.key,t),options:W[e.key]??[]}):null;return(0,p.jsx)(d.TableHead,{align:e.align,className:qt?l.stickyHeaderCellClassName:void 0,"aria-sort":e.sortable?u.resolveAriaSort(t):void 0,children:e.sortable||e.filterable?(0,p.jsxs)(`span`,{className:`zui:inline-flex zui:items-center zui:gap-2`,children:[n.localizeDigits(e.label,T),(0,p.jsxs)(`span`,{className:`zui:inline-flex zui:items-center`,children:[E===`rtl`?r:i,E===`rtl`?i:r]})]}):n.localizeDigits(e.label,T)},`head-${e.key}`)}),z?(0,p.jsx)(d.TableHead,{align:`center`,className:r.cn(l.actionsColumnClassName,l.actionsColumnStickyClassName,qt?l.stickyHeaderCellClassName:void 0),children:w.table.actions}):null]})}),(0,p.jsx)(d.TableBody,{children:Yt?(0,p.jsx)(ue.default,{count:Jt,keyPrefix:`loading`,showRowNumbers:R,columns:A,actionsCount:nn}):J.length===0?(0,p.jsx)(ce.default,{colSpan:A.length+ +!!z+ +!!R,showSearchInput:L,normalizedSearchTerm:bt,hasActiveFilters:wt>0,onClearFilters:Dt}):(0,p.jsxs)(p.Fragment,{children:[J.map(({row:e,rowIndex:t,rowId:i},a)=>{let o=i===void 0?`row-${t}`:`row-id-${String(i)}`,c=It?(Mt-1)*Pt+a+1:a+1;return(0,p.jsxs)(d.TableRow,{...k&&qe?{tabIndex:0,"aria-haspopup":`dialog`,"data-actionable":`true`,onClick:n=>{u.isInsideInteractiveControl(n)||vt(e,t,i)},onKeyDown:n=>{n.target===n.currentTarget&&(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),vt(e,t,i))}}:{},children:[R?(0,p.jsx)(d.TableCell,{align:`center`,className:l.rowNumberColumnClassName,"data-label":w.table.rowNumber,children:n.localizeDigits(String(c),T)}):null,A.map(r=>{let a=`cell-${r.key}-${o}`;if(r.viewType===`select`){let o=Ze[r.key]??[],s=e[r.key],c=typeof s==`string`||typeof s==`number`?String(s):``;return(0,p.jsx)(d.TableCell,{align:r.align,"data-label":n.localizeDigits(r.label,T),children:(0,p.jsx)(ne.default,{disabled:V||o.length===0&&!r.optionsSource,placeholder:u.resolvePlaceholder(r),options:o,remoteOptions:r.optionsSource,value:c,onValueChange:n=>{let a=Array.isArray(n)?n[0]??``:n;_t(e,t,i,r.key,a)}})},a)}return(0,p.jsx)(d.TableCell,{align:r.align,"data-label":n.localizeDigits(r.label,T),children:u.formatCellValue(e[r.key],r,D)},a)}),z?(0,p.jsx)(d.TableCell,{align:`center`,"data-cell":`actions`,className:r.cn(l.actionsColumnClassName,l.actionsColumnStickyClassName),children:(0,p.jsxs)(`div`,{"data-slot":`table-row-actions`,className:`zui:flex zui:items-center zui:justify-center zui:gap-0.5`,children:[M?(0,p.jsx)(s.IconActionButton,{"data-slot":`table-action-edit-button`,label:w.common.edit,icon:(0,p.jsx)(m.Pencil,{className:l.actionIconClassName,"aria-hidden":`true`}),disabled:V,className:r.cn(l.rowActionButtonClassName,`zui:text-[var(--zui-theme-text-primary)]`),onClick:()=>void pt(e,t,i)}):null,I.map((n,a)=>(0,p.jsx)(s.IconActionButton,{"data-slot":`table-action-custom-button`,label:n.tooltip,icon:n.icon,disabled:V||n.disabled,className:r.cn(l.rowActionButtonClassName,n.danger?`zui:text-[var(--zui-theme-status-danger)]`:`zui:text-[var(--zui-theme-text-primary)]`,n.className),onClick:()=>void gt(n,e,t,i)},`${n.tooltip}-${a}`)),N?(0,p.jsx)(s.IconActionButton,{"data-slot":`table-action-delete-button`,label:w.common.delete,icon:(0,p.jsx)(m.Trash2,{className:l.actionIconClassName,"aria-hidden":`true`}),disabled:V,className:r.cn(l.rowActionButtonClassName,`zui:text-[var(--zui-theme-status-danger)]`),onClick:()=>void mt(e,t,i)}):null]})}):null]},o)}),Xt?(0,p.jsx)(ue.default,{count:tn,keyPrefix:`infinite-loading`,showRowNumbers:R,columns:A,actionsCount:nn}):null]})})]})})}),k&&(qe||O)?(0,p.jsx)(a.default,{open:lt.open,onOpenChange:e=>ut(t=>({...t,open:e})),actions:lt.actions,label:w.table.actions}):null,(0,p.jsx)(le.default,{shouldRenderInfiniteMode:Lt,shouldShowInfiniteLoadingStatus:Qt,shouldShowInfiniteReadyStatus:$t,shouldShowInfiniteCompletedStatus:en,shouldRenderPagination:It,loading:h,isRowActionBusy:V,currentPage:Mt,totalPages:Nt,onPageChange:Ut})]})});_e.displayName=`Table`,exports.default=_e;
|
|
@@ -54,7 +54,26 @@ export type TablePrintHandler = (input: TablePrintHandlerInput) => void | Promis
|
|
|
54
54
|
export type TableAction = {
|
|
55
55
|
icon: React.ReactNode;
|
|
56
56
|
onClick: (input: TableRowActionInput) => void | Promise<void>;
|
|
57
|
+
/** Shown as the button's tooltip and accessible name; on phones it is the label in the sheet. */
|
|
57
58
|
tooltip: string;
|
|
59
|
+
/** Added to the action's button (colour, size, hover...). Has no effect in the phone sheet. */
|
|
60
|
+
className?: string;
|
|
61
|
+
/** Greys the action out. */
|
|
62
|
+
disabled?: boolean;
|
|
63
|
+
/** Draws the action in the danger colour. */
|
|
64
|
+
danger?: boolean;
|
|
65
|
+
/** Leaves the action out (handy for per-row conditions). */
|
|
66
|
+
hidden?: boolean;
|
|
67
|
+
};
|
|
68
|
+
/** What a consumer may change about the built-in edit / delete actions of `TableRowActions`. */
|
|
69
|
+
export type TableDefaultActionOptions = {
|
|
70
|
+
/** Replaces the built-in icon. */
|
|
71
|
+
icon?: React.ReactNode;
|
|
72
|
+
/** Replaces the built-in tooltip (`messages.common.edit` / `messages.common.delete`). */
|
|
73
|
+
tooltip?: string;
|
|
74
|
+
className?: string;
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
hidden?: boolean;
|
|
58
77
|
};
|
|
59
78
|
export type TableCellSelectChangeHandlerInput = {
|
|
60
79
|
row: DynamicTableRow;
|
|
@@ -271,6 +290,28 @@ export type TableRowProps = Omit<React.ComponentPropsWithoutRef<"tr">, "slot"> &
|
|
|
271
290
|
/** Rendered as `data-slot`. */
|
|
272
291
|
slot?: "table-row" | "table-loading-row";
|
|
273
292
|
};
|
|
293
|
+
export type TableRowActionsProps = {
|
|
294
|
+
/**
|
|
295
|
+
* The row these actions belong to. A hand-written table does not hand its rows to the `Table`,
|
|
296
|
+
* so the handlers receive exactly what is given here (`row` falls back to `{}`, `rowIndex` to `0`).
|
|
297
|
+
*/
|
|
298
|
+
row?: DynamicTableRow;
|
|
299
|
+
rowIndex?: number;
|
|
300
|
+
rowId?: TableRowId;
|
|
301
|
+
/** Shows the built-in edit action (pencil). */
|
|
302
|
+
onEdit?: TableEditRowHandler;
|
|
303
|
+
/** Shows the built-in delete action (trash, danger colour). */
|
|
304
|
+
onDelete?: TableDeleteRowHandler;
|
|
305
|
+
/** Custom icon / tooltip / class for the built-in edit action. */
|
|
306
|
+
editAction?: TableDefaultActionOptions;
|
|
307
|
+
/** Custom icon / tooltip / class for the built-in delete action. */
|
|
308
|
+
deleteAction?: TableDefaultActionOptions;
|
|
309
|
+
/** Extra actions with their own icon, tooltip and handler; placed between edit and delete. */
|
|
310
|
+
actions?: TableAction[];
|
|
311
|
+
/** Added to the actions cell. */
|
|
312
|
+
className?: string;
|
|
313
|
+
};
|
|
314
|
+
export type TableActionsHeadProps = Omit<TableHeadProps, "align">;
|
|
274
315
|
export type TableHeadProps = Omit<React.ComponentPropsWithoutRef<"th">, "align"> & {
|
|
275
316
|
align?: TableColumnAlign;
|
|
276
317
|
/** @deprecated Use the standard `aria-sort` attribute. */
|
|
@@ -54,7 +54,26 @@ export type TablePrintHandler = (input: TablePrintHandlerInput) => void | Promis
|
|
|
54
54
|
export type TableAction = {
|
|
55
55
|
icon: React.ReactNode;
|
|
56
56
|
onClick: (input: TableRowActionInput) => void | Promise<void>;
|
|
57
|
+
/** Shown as the button's tooltip and accessible name; on phones it is the label in the sheet. */
|
|
57
58
|
tooltip: string;
|
|
59
|
+
/** Added to the action's button (colour, size, hover...). Has no effect in the phone sheet. */
|
|
60
|
+
className?: string;
|
|
61
|
+
/** Greys the action out. */
|
|
62
|
+
disabled?: boolean;
|
|
63
|
+
/** Draws the action in the danger colour. */
|
|
64
|
+
danger?: boolean;
|
|
65
|
+
/** Leaves the action out (handy for per-row conditions). */
|
|
66
|
+
hidden?: boolean;
|
|
67
|
+
};
|
|
68
|
+
/** What a consumer may change about the built-in edit / delete actions of `TableRowActions`. */
|
|
69
|
+
export type TableDefaultActionOptions = {
|
|
70
|
+
/** Replaces the built-in icon. */
|
|
71
|
+
icon?: React.ReactNode;
|
|
72
|
+
/** Replaces the built-in tooltip (`messages.common.edit` / `messages.common.delete`). */
|
|
73
|
+
tooltip?: string;
|
|
74
|
+
className?: string;
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
hidden?: boolean;
|
|
58
77
|
};
|
|
59
78
|
export type TableCellSelectChangeHandlerInput = {
|
|
60
79
|
row: DynamicTableRow;
|
|
@@ -271,6 +290,28 @@ export type TableRowProps = Omit<React.ComponentPropsWithoutRef<"tr">, "slot"> &
|
|
|
271
290
|
/** Rendered as `data-slot`. */
|
|
272
291
|
slot?: "table-row" | "table-loading-row";
|
|
273
292
|
};
|
|
293
|
+
export type TableRowActionsProps = {
|
|
294
|
+
/**
|
|
295
|
+
* The row these actions belong to. A hand-written table does not hand its rows to the `Table`,
|
|
296
|
+
* so the handlers receive exactly what is given here (`row` falls back to `{}`, `rowIndex` to `0`).
|
|
297
|
+
*/
|
|
298
|
+
row?: DynamicTableRow;
|
|
299
|
+
rowIndex?: number;
|
|
300
|
+
rowId?: TableRowId;
|
|
301
|
+
/** Shows the built-in edit action (pencil). */
|
|
302
|
+
onEdit?: TableEditRowHandler;
|
|
303
|
+
/** Shows the built-in delete action (trash, danger colour). */
|
|
304
|
+
onDelete?: TableDeleteRowHandler;
|
|
305
|
+
/** Custom icon / tooltip / class for the built-in edit action. */
|
|
306
|
+
editAction?: TableDefaultActionOptions;
|
|
307
|
+
/** Custom icon / tooltip / class for the built-in delete action. */
|
|
308
|
+
deleteAction?: TableDefaultActionOptions;
|
|
309
|
+
/** Extra actions with their own icon, tooltip and handler; placed between edit and delete. */
|
|
310
|
+
actions?: TableAction[];
|
|
311
|
+
/** Added to the actions cell. */
|
|
312
|
+
className?: string;
|
|
313
|
+
};
|
|
314
|
+
export type TableActionsHeadProps = Omit<TableHeadProps, "align">;
|
|
274
315
|
export type TableHeadProps = Omit<React.ComponentPropsWithoutRef<"th">, "align"> & {
|
|
275
316
|
align?: TableColumnAlign;
|
|
276
317
|
/** @deprecated Use the standard `aria-sort` attribute. */
|