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.

2 lines (1 loc) 2.29 kB
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{useRef as n,useEffect as o,useCallback as s,useState as i,useMemo as r}from"react";import{I as c,D as a,a as l,B as u,b as m,c as d}from"./chunks/ui-components-cb3fcf58.js";import{s as h}from"./chunks/security-30c06b21.js";import{ChevronDown as p}from"lucide-react";import"./chunks/utils-9ed1a6bd.js";import"clsx";import"tailwind-merge";import"@radix-ui/react-slot";import"class-variance-authority";import"@radix-ui/react-dropdown-menu";function f({value:t,onChange:a,debounce:l=500,type:u="text",maxLength:m=1e3,...d}){const[p,f]=i(t),x=function(e=10,t=1e3){const o=n([]);return s(()=>{const n=Date.now();return o.current=o.current.filter(e=>t>n-e),o.current.length<e&&(o.current.push(n),!0)},[e,t])}(),b=n(t),v=n(a);o(()=>{v.current=a},[a]),o(()=>{if("number"===u){const e=+t;b.current=isNaN(e)||null==t||""===t?void 0:e}else b.current=t;f(t)},[t,u]),function(e,t,s){const i=n(null),r=n(s),c=n(void 0);o(()=>{r.current=s},[s]),o(()=>(i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{c.current!==e&&(c.current=e,r.current(e))},t),()=>{i.current&&clearTimeout(i.current)}),[e,t])}(p,l,s(e=>{if(!x())return;let t=e;if("text"===u||"search"===u)t="string"==typeof e?h(e):e+"";else if("number"===u){const n=+e;t=isNaN(n)||null==e||""===e?void 0:Math.max(-1e6,Math.min(1e6,n))}t!==b.current&&(b.current=t,v.current(t))},[u,x]));const C=s(e=>{const t=e.target.value;t.length>m||("number"!==u||""===t||/^-?\d*\.?\d*$/.test(t))&&f(t)},[m,u]),N=r(()=>d.autoComplete||"off",[d.autoComplete]);return e(c,{...d,type:u,maxLength:m,value:p,onChange:C,autoComplete:N,spellCheck:!1})}var x=({placeholder:n,options:o,selectedOptions:i,setSelectedOptions:r})=>{const c=s(e=>{r(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[r]),h=s(e=>i.includes(e),[i]),f=s(e=>{e.preventDefault()},[]),x=s(e=>{e.preventDefault()},[]);return t(a,{children:[e(l,{asChild:!0,className:"w-full",children:t(u,{variant:"outline",className:"w-full flex items-center justify-between",children:[e("div",{children:n}),e(p,{className:"h-4 w-4 opacity-50"})]})}),e(m,{className:"w-56",onCloseAutoFocus:f,children:o.map(t=>e(d,{onSelect:x,checked:h(t.value),onCheckedChange:()=>c(t.value),children:t.label},t.value))})]})};export{f as DebouncedInput,x as MultiSelect};