UNPKG

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 8.03 kB
"use strict";Object.defineProperty(exports,"t",{value:!0});const e=require("react/jsx-runtime"),t=require("react"),n=require("clsx"),o=require("tailwind-merge"),s=require("@radix-ui/react-slot"),a=require("class-variance-authority"),r=require("@radix-ui/react-dropdown-menu"),i=require("lucide-react");function d(e){if(e&&e.t)return e;const t=Object.create(null);if(e)for(const n in e)if("default"!==n){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}return t.default=e,Object.freeze(t)}const c=d(t),l=d(r);function u(...e){return o.twMerge(n.clsx(e))}const m=c.forwardRef(({className:t,type:n,...o},s)=>e.jsx("input",{type:n,className:u("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:s,...o}));m.displayName="Input";const f=a.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"}}),p=c.forwardRef(({className:t,variant:n,size:o,asChild:a=!1,...r},i)=>{const d=a?s.Slot:"button";return e.jsx(d,{className:u(f({variant:n,size:o,className:t})),ref:i,...r})});p.displayName="Button";const h=l.Root,g=l.Trigger;c.forwardRef(({className:t,inset:n,children:o,...s},a)=>e.jsxs(l.SubTrigger,{ref:a,className:u("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",n&&"pl-8",t),...s,children:[o,e.jsx(i.ChevronRight,{className:"ml-auto"})]})).displayName=l.SubTrigger.displayName,c.forwardRef(({className:t,...n},o)=>e.jsx(l.SubContent,{ref:o,className:u("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),...n})).displayName=l.SubContent.displayName;const b=c.forwardRef(({className:t,sideOffset:n=4,...o},s)=>e.jsx(l.Portal,{children:e.jsx(l.Content,{ref:s,sideOffset:n,className:u("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=l.Content.displayName,c.forwardRef(({className:t,inset:n,...o},s)=>e.jsx(l.Item,{ref:s,className:u("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",n&&"pl-8",t),...o})).displayName=l.Item.displayName;const v=c.forwardRef(({className:t,children:n,checked:o,...s},a)=>e.jsxs(l.CheckboxItem,{ref:a,className:u("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:o,...s,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(l.ItemIndicator,{children:e.jsx(i.Check,{className:"h-4 w-4"})})}),n]}));v.displayName=l.CheckboxItem.displayName,c.forwardRef(({className:t,children:n,...o},s)=>e.jsxs(l.RadioItem,{ref:s,className:u("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),...o,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(l.ItemIndicator,{children:e.jsx(i.Circle,{className:"h-2 w-2 fill-current"})})}),n]})).displayName=l.RadioItem.displayName,c.forwardRef(({className:t,inset:n,...o},s)=>e.jsx(l.Label,{ref:s,className:u("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",t),...o})).displayName=l.Label.displayName,c.forwardRef(({className:t,...n},o)=>e.jsx(l.Separator,{ref:o,className:u("-mx-1 my-1 h-px bg-muted",t),...n})).displayName=l.Separator.displayName,exports.DebouncedInput=function({value:n,onChange:o,debounce:s=500,type:a="text",maxLength:r=1e3,...i}){const[d,c]=t.useState(n),l=function(e=10,n=1e3){const o=t.useRef([]);return t.useCallback(()=>{const t=Date.now();return o.current=o.current.filter(e=>n>t-e),o.current.length<e&&(o.current.push(t),!0)},[e,n])}(),u=t.useRef(n),f=t.useRef(o);t.useEffect(()=>{f.current=o},[o]),t.useEffect(()=>{if("number"===a){const e=+n;u.current=isNaN(e)||null==n||""===n?void 0:e}else u.current=n;c(n)},[n,a]),function(e,n,o){const s=t.useRef(null),a=t.useRef(o),r=t.useRef(void 0);t.useEffect(()=>{a.current=o},[o]),t.useEffect(()=>(s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{r.current!==e&&(r.current=e,a.current(e))},n),()=>{s.current&&clearTimeout(s.current)}),[e,n])}(d,s,t.useCallback(e=>{if(!l())return;let t=e;if("text"===a||"search"===a)t="string"==typeof e?"string"!=typeof(n=e)?"":n.replace(/['";\\]/g,"").replace(/<[^>]*>/g,"").slice(0,1e3).trim():e+"";else if("number"===a){const n=+e;t=isNaN(n)||null==e||""===e?void 0:Math.max(-1e6,Math.min(1e6,n))}var n;t!==u.current&&(u.current=t,f.current(t))},[a,l]));const p=t.useCallback(e=>{const t=e.target.value;t.length>r||("number"!==a||""===t||/^-?\d*\.?\d*$/.test(t))&&c(t)},[r,a]),h=t.useMemo(()=>i.autoComplete||"off",[i.autoComplete]);return e.jsx(m,{...i,type:a,maxLength:r,value:d,onChange:p,autoComplete:h,spellCheck:!1})},exports.MultiSelect=({placeholder:n,options:o,selectedOptions:s,setSelectedOptions:a})=>{const r=t.useCallback(e=>{a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[a]),d=t.useCallback(e=>s.includes(e),[s]),c=t.useCallback(e=>{e.preventDefault()},[]),l=t.useCallback(e=>{e.preventDefault()},[]);return e.jsxs(h,{children:[e.jsx(g,{asChild:!0,className:"w-full",children:e.jsxs(p,{variant:"outline",className:"w-full flex items-center justify-between",children:[e.jsx("div",{children:n}),e.jsx(i.ChevronDown,{className:"h-4 w-4 opacity-50"})]})}),e.jsx(b,{className:"w-56",onCloseAutoFocus:c,children:o.map(t=>e.jsx(v,{onSelect:l,checked:d(t.value),onCheckedChange:()=>r(t.value),children:t.label},t.value))})]})};