tanstack-shadcn-table
Version:
A powerful, feature-rich React table component built on top of TanStack Table v8 with shadcn/ui styling. Optimized bundle size with 55% reduction through peer dependencies.
1 lines • 14.7 kB
JavaScript
"use strict";Object.defineProperty(exports,"t",{value:!0});const e=require("react/jsx-runtime"),t=require("react"),r=require("lucide-react"),o=require("@radix-ui/react-dropdown-menu"),a=require("clsx"),n=require("tailwind-merge"),s=require("@radix-ui/react-slot"),i=require("class-variance-authority"),l=require("cmdk"),d=require("@radix-ui/react-popover"),c=require("@radix-ui/react-separator");function u(e){if(e&&e.t)return e;const t=Object.create(null);if(e)for(const r in e)if("default"!==r){const o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}return t.default=e,Object.freeze(t)}const m=u(t),f=u(o),p=u(d),g=u(c);function h(...e){return n.twMerge(a.clsx(e))}const v=f.Root,x=f.Trigger;m.forwardRef(({className:t,inset:o,children:a,...n},s)=>e.jsxs(f.SubTrigger,{ref:s,className:h("flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",o&&"pl-8",t),...n,children:[a,e.jsx(r.ChevronRight,{className:"ml-auto"})]})).displayName=f.SubTrigger.displayName,m.forwardRef(({className:t,...r},o)=>e.jsx(f.SubContent,{ref:o,className:h("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]",t),...r})).displayName=f.SubContent.displayName;const b=m.forwardRef(({className:t,sideOffset:r=4,...o},a)=>e.jsx(f.Portal,{children:e.jsx(f.Content,{ref:a,sideOffset:r,className:h("z-50 max-h-[var(--radix-dropdown-menu-content-available-height)] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]",t),...o})}));b.displayName=f.Content.displayName;const w=m.forwardRef(({className:t,inset:r,...o},a)=>e.jsx(f.Item,{ref:a,className:h("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",r&&"pl-8",t),...o}));w.displayName=f.Item.displayName,m.forwardRef(({className:t,children:o,checked:a,...n},s)=>e.jsxs(f.CheckboxItem,{ref:s,className:h("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),checked:a,...n,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(f.ItemIndicator,{children:e.jsx(r.Check,{className:"h-4 w-4"})})}),o]})).displayName=f.CheckboxItem.displayName,m.forwardRef(({className:t,children:o,...a},n)=>e.jsxs(f.RadioItem,{ref:n,className:h("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...a,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(f.ItemIndicator,{children:e.jsx(r.Circle,{className:"h-2 w-2 fill-current"})})}),o]})).displayName=f.RadioItem.displayName,m.forwardRef(({className:t,inset:r,...o},a)=>e.jsx(f.Label,{ref:a,className:h("px-2 py-1.5 text-sm font-semibold",r&&"pl-8",t),...o})).displayName=f.Label.displayName;const y=m.forwardRef(({className:t,...r},o)=>e.jsx(f.Separator,{ref:o,className:h("-mx-1 my-1 h-px bg-muted",t),...r}));y.displayName=f.Separator.displayName;const N=i.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),z=m.forwardRef(({className:t,variant:r,size:o,asChild:a=!1,...n},i)=>{const l=a?s.Slot:"button";return e.jsx(l,{className:h(N({variant:r,size:o,className:t})),ref:i,...n})});z.displayName="Button";const k=i.cva("inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",secondary:"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",destructive:"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"}},defaultVariants:{variant:"default"}});function C({className:t,variant:r,asChild:o=!1,...a}){const n=o?s.Slot:"span";return e.jsx(n,{"data-slot":"badge",className:h(k({variant:r}),t),...a})}function S({className:t,...r}){return e.jsx(l.Command,{"data-slot":"command",className:h("bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",t),...r})}function F({className:t,...o}){return e.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-9 items-center gap-2 border-b px-3",children:[e.jsx(r.SearchIcon,{className:"size-4 shrink-0 opacity-50"}),e.jsx(l.Command.Input,{"data-slot":"command-input",className:h("placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",t),...o})]})}function _({className:t,...r}){return e.jsx(l.Command.List,{"data-slot":"command-list",className:h("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",t),...r})}function R({...t}){return e.jsx(l.Command.Empty,{"data-slot":"command-empty",className:"py-6 text-center text-sm",...t})}function j({className:t,...r}){return e.jsx(l.Command.Group,{"data-slot":"command-group",className:h("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium",t),...r})}function O({className:t,...r}){return e.jsx(l.Command.Separator,{"data-slot":"command-separator",className:h("bg-border -mx-1 h-px",t),...r})}function A({className:t,...r}){return e.jsx(l.Command.Item,{"data-slot":"command-item",className:h("data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",t),...r})}function q({...t}){return e.jsx(p.Root,{"data-slot":"popover",...t})}function P({...t}){return e.jsx(p.Trigger,{"data-slot":"popover-trigger",...t})}function T({className:t,align:r="center",sideOffset:o=4,...a}){return e.jsx(p.Portal,{children:e.jsx(p.Content,{"data-slot":"popover-content",align:r,sideOffset:o,className:h("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",t),...a})})}function D({className:t,orientation:r="horizontal",decorative:o=!0,...a}){return e.jsx(g.Root,{"data-slot":"separator",decorative:o,orientation:r,className:h("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",t),...a})}const H={pagination:{previous:"Previous",next:"Next",first:"First",last:"Last",page:"Page",of:"of",rowsPerPage:"Rows per page",goToPage:"Go to page",totalRecords:"Total: {total} records",showingXtoYofZ:"Showing {from} to {to} of {total} entries",noData:"No data available"},filters:{search:"Search",searchAllColumns:"Search all columns...",showFilter:"Show Filter",hideFilter:"Hide Filter",clearFilter:"Clear filter",clearAllFilters:"Clear all filters",filterBy:"Filter by {column}",all:"All",true:"True",false:"False",min:"Min",max:"Max",from:"From",to:"To",selectOption:"Select option",noOptionsFound:"No options found",selectedCount:"{count} selected",clearFilters:"Clear filters",noResultsFound:"No results found."},sorting:{sortAscending:"Sort ascending",sortDescending:"Sort descending",clearSort:"Clear sort",sortBy:"Sort by {column}"},columns:{hide:"Hide",show:"Show",toggleVisibility:"Toggle column visibility",resetColumns:"Reset columns",reorderColumns:"Reorder columns",resizeColumn:"Resize column"},selection:{selectAll:"Select all",selectRow:"Select row",deselectAll:"Deselect all",selectedCount:"{count} selected",selectAllOnPage:"Select all on this page",selectAllRows:"Select all rows"},status:{loading:"Loading...",error:"An error occurred",noResults:"No results found",retry:"Retry",loadMore:"Load more"},security:{rateLimitExceeded:"Rate limit exceeded. Please try again later.",invalidInput:"Invalid input detected",fileSizeExceeded:"File size exceeds limit",fileTypeNotAllowed:"File type not allowed",inputTooLong:"Input is too long"},accessibility:{sortColumn:"Sort column {column}",filterColumn:"Filter column {column}",selectAllRows:"Select all rows",selectRow:"Select row {row}",columnHeader:"Column header {column}",tableCaption:"Data table with {rows} rows and {columns} columns",resizeHandle:"Resize column {column}",dragHandle:"Drag to reorder column {column}"}};exports.FacetedFilter=function({column:t,title:o,options:a,translations:n=H}){const s=function(e){return(t,r)=>function(e,t,r){const o=t.split(".");let a=e;for(const e of o)if(a=a?.[e],void 0===a)return void 0,t;return"string"!=typeof a?(void 0,t):r?function(e,t){return e.replace(/\{(\w+)\}/g,(e,r)=>t[r]?.toString()||e)}(a,r):a}(e,t,r)}(n),i=t?.getFacetedUniqueValues(),l=new Set(t?.getFilterValue());return e.jsxs(q,{children:[e.jsx(P,{asChild:!0,children:e.jsxs(z,{className:"h-8 border-dashed",size:"sm",variant:"outline",children:[e.jsx(r.PlusCircle,{}),o,l?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(D,{className:"mx-2 h-4",orientation:"vertical"}),e.jsx(C,{className:"rounded-sm px-1 font-normal lg:hidden",variant:"secondary",children:l.size}),e.jsx("div",{className:"hidden gap-1 lg:flex",children:l.size>2?e.jsx(C,{className:"rounded-sm px-1 font-normal",variant:"secondary",children:s("filters.selectedCount",{count:l.size})}):a.filter(e=>l.has(e.value)).map((t,r)=>e.jsx(C,{className:"rounded-sm px-1 font-normal",variant:"secondary",children:t.label},`${t.value}-${r}`))})]})]})}),e.jsx(T,{align:"start",className:"w-[200px] p-0",children:e.jsxs(S,{children:[e.jsx(F,{placeholder:o}),e.jsxs(_,{children:[e.jsx(R,{children:s("filters.noResultsFound")}),e.jsx(j,{children:a.map((o,a)=>{const n=l.has(o.value);return e.jsxs(A,{onSelect:()=>{n?l.delete(o.value):l.add(o.value);const e=Array.from(l);t?.setFilterValue(e.length?e:void 0)},children:[e.jsx("div",{className:h("flex size-4 items-center justify-center rounded-[4px] border",n?"border-primary bg-primary text-primary-foreground":"border-input [&_svg]:invisible"),children:e.jsx(r.Check,{className:"size-3.5 text-primary-foreground"})}),o.icon&&e.jsx(o.icon,{className:"size-4 text-muted-foreground"}),e.jsx("span",{children:o.label}),i?.get(o.value)&&e.jsx("span",{className:"ml-auto flex size-4 items-center justify-center font-mono text-muted-foreground text-xs",children:i.get(o.value)})]},`${o.value}-${a}`)})}),l.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(O,{}),e.jsx(j,{children:e.jsx(A,{className:"justify-center text-center",onSelect:()=>t?.setFilterValue(void 0),children:s("filters.clearFilters")})})]})]})]})})]})},exports.RowActions=function({row:t,actions:o,trigger:a,align:n="end",side:s="bottom",className:i,size:l="icon"}){if(!o||0===o.length)return null;const d=e.jsxs(z,{variant:"ghost",size:l,className:h("h-8 w-8 p-0",i),onClick:e=>e.stopPropagation(),children:[e.jsx("span",{className:"sr-only",children:"Open menu"}),e.jsx(r.MoreVertical,{className:"h-4 w-4"})]});return e.jsxs(v,{children:[e.jsx(x,{asChild:!0,onClick:e=>e.stopPropagation(),children:a||d}),e.jsx(b,{align:n,side:s,onClick:e=>e.stopPropagation(),children:o.map((r,o)=>{const a="function"==typeof r.disabled?r.disabled(t):r.disabled,n=r.icon,s=e.jsxs(w,{disabled:a,onClick:e=>{e.stopPropagation(),a||r.onClick(t)},className:h(r.destructive&&"text-destructive hover:text-destructive hover:bg-destructive/10 focus:text-destructive focus:bg-destructive/10"),children:[n&&e.jsx(n,{className:"mr-2 h-4 w-4"}),r.label]},r.id);return r.separator&&o>0?e.jsxs(m.Fragment,{children:[e.jsx(y,{}),s]},r.id):s})})]})};