@stereopt/data-table 0.1.8 → 0.1.10

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/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -25,9 +35,6 @@ __export(index_exports, {
25
35
  });
26
36
  module.exports = __toCommonJS(index_exports);
27
37
 
28
- // src/dataTable/DataTable.tsx
29
- var import_react_table = require("@tanstack/react-table");
30
-
31
38
  // src/lib/utils.ts
32
39
  var import_clsx = require("clsx");
33
40
  var import_tailwind_merge = require("tailwind-merge");
@@ -41,13 +48,13 @@ function Table({ className, ...props }) {
41
48
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
42
49
  "div",
43
50
  {
44
- "data-slot": "table-container",
45
51
  className: "relative w-full overflow-x-auto",
52
+ "data-slot": "table-container",
46
53
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
47
54
  "table",
48
55
  {
49
- "data-slot": "table",
50
56
  className: cn("w-full caption-bottom text-sm", className),
57
+ "data-slot": "table",
51
58
  ...props
52
59
  }
53
60
  )
@@ -58,8 +65,8 @@ function TableHeader({ className, ...props }) {
58
65
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
59
66
  "thead",
60
67
  {
61
- "data-slot": "table-header",
62
68
  className: cn("[&_tr]:border-b", className),
69
+ "data-slot": "table-header",
63
70
  ...props
64
71
  }
65
72
  );
@@ -68,8 +75,8 @@ function TableBody({ className, ...props }) {
68
75
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
69
76
  "tbody",
70
77
  {
71
- "data-slot": "table-body",
72
78
  className: cn("[&_tr:last-child]:border-0", className),
79
+ "data-slot": "table-body",
73
80
  ...props
74
81
  }
75
82
  );
@@ -78,11 +85,11 @@ function TableRow({ className, ...props }) {
78
85
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
79
86
  "tr",
80
87
  {
81
- "data-slot": "table-row",
82
88
  className: cn(
83
89
  "border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted",
84
90
  className
85
91
  ),
92
+ "data-slot": "table-row",
86
93
  ...props
87
94
  }
88
95
  );
@@ -91,11 +98,11 @@ function TableHead({ className, ...props }) {
91
98
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
92
99
  "th",
93
100
  {
94
- "data-slot": "table-head",
95
101
  className: cn(
96
102
  "h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0",
97
103
  className
98
104
  ),
105
+ "data-slot": "table-head",
99
106
  ...props
100
107
  }
101
108
  );
@@ -104,60 +111,493 @@ function TableCell({ className, ...props }) {
104
111
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
105
112
  "td",
106
113
  {
107
- "data-slot": "table-cell",
108
114
  className: cn(
109
115
  "p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0",
110
116
  className
111
117
  ),
118
+ "data-slot": "table-cell",
112
119
  ...props
113
120
  }
114
121
  );
115
122
  }
116
123
 
117
- // src/dataTable/DataTable.tsx
124
+ // src/components/ui/button.tsx
125
+ var import_class_variance_authority = require("class-variance-authority");
126
+
127
+ // node_modules/@radix-ui/react-slot/dist/index.mjs
128
+ var dist_exports = {};
129
+ __export(dist_exports, {
130
+ Root: () => Slot,
131
+ Slot: () => Slot,
132
+ Slottable: () => Slottable,
133
+ createSlot: () => createSlot,
134
+ createSlottable: () => createSlottable
135
+ });
136
+ var React2 = __toESM(require("react"), 1);
137
+
138
+ // node_modules/@radix-ui/react-compose-refs/dist/index.mjs
139
+ var React = __toESM(require("react"), 1);
140
+ function setRef(ref, value) {
141
+ if (typeof ref === "function") {
142
+ return ref(value);
143
+ } else if (ref !== null && ref !== void 0) {
144
+ ref.current = value;
145
+ }
146
+ }
147
+ function composeRefs(...refs) {
148
+ return (node) => {
149
+ let hasCleanup = false;
150
+ const cleanups = refs.map((ref) => {
151
+ const cleanup = setRef(ref, node);
152
+ if (!hasCleanup && typeof cleanup == "function") {
153
+ hasCleanup = true;
154
+ }
155
+ return cleanup;
156
+ });
157
+ if (hasCleanup) {
158
+ return () => {
159
+ for (let i = 0; i < cleanups.length; i++) {
160
+ const cleanup = cleanups[i];
161
+ if (typeof cleanup == "function") {
162
+ cleanup();
163
+ } else {
164
+ setRef(refs[i], null);
165
+ }
166
+ }
167
+ };
168
+ }
169
+ };
170
+ }
171
+
172
+ // node_modules/@radix-ui/react-slot/dist/index.mjs
118
173
  var import_jsx_runtime2 = require("react/jsx-runtime");
119
- function DataTable({ columns, data }) {
174
+ // @__NO_SIDE_EFFECTS__
175
+ function createSlot(ownerName) {
176
+ const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
177
+ const Slot2 = React2.forwardRef((props, forwardedRef) => {
178
+ const { children, ...slotProps } = props;
179
+ const childrenArray = React2.Children.toArray(children);
180
+ const slottable = childrenArray.find(isSlottable);
181
+ if (slottable) {
182
+ const newElement = slottable.props.children;
183
+ const newChildren = childrenArray.map((child) => {
184
+ if (child === slottable) {
185
+ if (React2.Children.count(newElement) > 1) return React2.Children.only(null);
186
+ return React2.isValidElement(newElement) ? newElement.props.children : null;
187
+ } else {
188
+ return child;
189
+ }
190
+ });
191
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SlotClone, { ...slotProps, ref: forwardedRef, children: React2.isValidElement(newElement) ? React2.cloneElement(newElement, void 0, newChildren) : null });
192
+ }
193
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SlotClone, { ...slotProps, ref: forwardedRef, children });
194
+ });
195
+ Slot2.displayName = `${ownerName}.Slot`;
196
+ return Slot2;
197
+ }
198
+ var Slot = /* @__PURE__ */ createSlot("Slot");
199
+ // @__NO_SIDE_EFFECTS__
200
+ function createSlotClone(ownerName) {
201
+ const SlotClone = React2.forwardRef((props, forwardedRef) => {
202
+ const { children, ...slotProps } = props;
203
+ if (React2.isValidElement(children)) {
204
+ const childrenRef = getElementRef(children);
205
+ const props2 = mergeProps(slotProps, children.props);
206
+ if (children.type !== React2.Fragment) {
207
+ props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
208
+ }
209
+ return React2.cloneElement(children, props2);
210
+ }
211
+ return React2.Children.count(children) > 1 ? React2.Children.only(null) : null;
212
+ });
213
+ SlotClone.displayName = `${ownerName}.SlotClone`;
214
+ return SlotClone;
215
+ }
216
+ var SLOTTABLE_IDENTIFIER = /* @__PURE__ */ Symbol("radix.slottable");
217
+ // @__NO_SIDE_EFFECTS__
218
+ function createSlottable(ownerName) {
219
+ const Slottable2 = ({ children }) => {
220
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children });
221
+ };
222
+ Slottable2.displayName = `${ownerName}.Slottable`;
223
+ Slottable2.__radixId = SLOTTABLE_IDENTIFIER;
224
+ return Slottable2;
225
+ }
226
+ var Slottable = /* @__PURE__ */ createSlottable("Slottable");
227
+ function isSlottable(child) {
228
+ return React2.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
229
+ }
230
+ function mergeProps(slotProps, childProps) {
231
+ const overrideProps = { ...childProps };
232
+ for (const propName in childProps) {
233
+ const slotPropValue = slotProps[propName];
234
+ const childPropValue = childProps[propName];
235
+ const isHandler = /^on[A-Z]/.test(propName);
236
+ if (isHandler) {
237
+ if (slotPropValue && childPropValue) {
238
+ overrideProps[propName] = (...args) => {
239
+ const result = childPropValue(...args);
240
+ slotPropValue(...args);
241
+ return result;
242
+ };
243
+ } else if (slotPropValue) {
244
+ overrideProps[propName] = slotPropValue;
245
+ }
246
+ } else if (propName === "style") {
247
+ overrideProps[propName] = { ...slotPropValue, ...childPropValue };
248
+ } else if (propName === "className") {
249
+ overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
250
+ }
251
+ }
252
+ return { ...slotProps, ...overrideProps };
253
+ }
254
+ function getElementRef(element) {
255
+ let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
256
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
257
+ if (mayWarn) {
258
+ return element.ref;
259
+ }
260
+ getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
261
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
262
+ if (mayWarn) {
263
+ return element.props.ref;
264
+ }
265
+ return element.props.ref || element.ref;
266
+ }
267
+
268
+ // src/components/ui/button.tsx
269
+ var import_jsx_runtime3 = require("react/jsx-runtime");
270
+ var buttonVariants = (0, import_class_variance_authority.cva)(
271
+ "group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
272
+ {
273
+ variants: {
274
+ variant: {
275
+ default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
276
+ outline: "border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
277
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
278
+ ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
279
+ destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
280
+ link: "text-primary underline-offset-4 hover:underline"
281
+ },
282
+ size: {
283
+ default: "h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
284
+ xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
285
+ sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
286
+ lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
287
+ icon: "size-8",
288
+ "icon-xs": "size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
289
+ "icon-sm": "size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
290
+ "icon-lg": "size-9"
291
+ }
292
+ },
293
+ defaultVariants: {
294
+ variant: "default",
295
+ size: "default"
296
+ }
297
+ }
298
+ );
299
+ function Button({
300
+ className,
301
+ variant = "default",
302
+ size = "default",
303
+ asChild = false,
304
+ ...props
305
+ }) {
306
+ const Comp = asChild ? dist_exports.Root : "button";
307
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
308
+ Comp,
309
+ {
310
+ className: cn(buttonVariants({ variant, size, className })),
311
+ "data-size": size,
312
+ "data-slot": "button",
313
+ "data-variant": variant,
314
+ ...props
315
+ }
316
+ );
317
+ }
318
+
319
+ // node_modules/lucide-react/dist/esm/createLucideIcon.js
320
+ var import_react2 = require("react");
321
+
322
+ // node_modules/lucide-react/dist/esm/shared/src/utils/mergeClasses.js
323
+ var mergeClasses = (...classes) => classes.filter((className, index, array) => {
324
+ return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
325
+ }).join(" ").trim();
326
+
327
+ // node_modules/lucide-react/dist/esm/shared/src/utils/toKebabCase.js
328
+ var toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
329
+
330
+ // node_modules/lucide-react/dist/esm/shared/src/utils/toCamelCase.js
331
+ var toCamelCase = (string) => string.replace(
332
+ /^([A-Z])|[\s-_]+(\w)/g,
333
+ (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase()
334
+ );
335
+
336
+ // node_modules/lucide-react/dist/esm/shared/src/utils/toPascalCase.js
337
+ var toPascalCase = (string) => {
338
+ const camelCase = toCamelCase(string);
339
+ return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
340
+ };
341
+
342
+ // node_modules/lucide-react/dist/esm/Icon.js
343
+ var import_react = require("react");
344
+
345
+ // node_modules/lucide-react/dist/esm/defaultAttributes.js
346
+ var defaultAttributes = {
347
+ xmlns: "http://www.w3.org/2000/svg",
348
+ width: 24,
349
+ height: 24,
350
+ viewBox: "0 0 24 24",
351
+ fill: "none",
352
+ stroke: "currentColor",
353
+ strokeWidth: 2,
354
+ strokeLinecap: "round",
355
+ strokeLinejoin: "round"
356
+ };
357
+
358
+ // node_modules/lucide-react/dist/esm/shared/src/utils/hasA11yProp.js
359
+ var hasA11yProp = (props) => {
360
+ for (const prop in props) {
361
+ if (prop.startsWith("aria-") || prop === "role" || prop === "title") {
362
+ return true;
363
+ }
364
+ }
365
+ return false;
366
+ };
367
+
368
+ // node_modules/lucide-react/dist/esm/Icon.js
369
+ var Icon = (0, import_react.forwardRef)(
370
+ ({
371
+ color = "currentColor",
372
+ size = 24,
373
+ strokeWidth = 2,
374
+ absoluteStrokeWidth,
375
+ className = "",
376
+ children,
377
+ iconNode,
378
+ ...rest
379
+ }, ref) => (0, import_react.createElement)(
380
+ "svg",
381
+ {
382
+ ref,
383
+ ...defaultAttributes,
384
+ width: size,
385
+ height: size,
386
+ stroke: color,
387
+ strokeWidth: absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
388
+ className: mergeClasses("lucide", className),
389
+ ...!children && !hasA11yProp(rest) && { "aria-hidden": "true" },
390
+ ...rest
391
+ },
392
+ [
393
+ ...iconNode.map(([tag, attrs]) => (0, import_react.createElement)(tag, attrs)),
394
+ ...Array.isArray(children) ? children : [children]
395
+ ]
396
+ )
397
+ );
398
+
399
+ // node_modules/lucide-react/dist/esm/createLucideIcon.js
400
+ var createLucideIcon = (iconName, iconNode) => {
401
+ const Component = (0, import_react2.forwardRef)(
402
+ ({ className, ...props }, ref) => (0, import_react2.createElement)(Icon, {
403
+ ref,
404
+ iconNode,
405
+ className: mergeClasses(
406
+ `lucide-${toKebabCase(toPascalCase(iconName))}`,
407
+ `lucide-${iconName}`,
408
+ className
409
+ ),
410
+ ...props
411
+ })
412
+ );
413
+ Component.displayName = toPascalCase(iconName);
414
+ return Component;
415
+ };
416
+
417
+ // node_modules/lucide-react/dist/esm/icons/chevron-left.js
418
+ var __iconNode = [["path", { d: "m15 18-6-6 6-6", key: "1wnfg3" }]];
419
+ var ChevronLeft = createLucideIcon("chevron-left", __iconNode);
420
+
421
+ // node_modules/lucide-react/dist/esm/icons/chevron-right.js
422
+ var __iconNode2 = [["path", { d: "m9 18 6-6-6-6", key: "mthhwq" }]];
423
+ var ChevronRight = createLucideIcon("chevron-right", __iconNode2);
424
+
425
+ // node_modules/lucide-react/dist/esm/icons/chevrons-left.js
426
+ var __iconNode3 = [
427
+ ["path", { d: "m11 17-5-5 5-5", key: "13zhaf" }],
428
+ ["path", { d: "m18 17-5-5 5-5", key: "h8a8et" }]
429
+ ];
430
+ var ChevronsLeft = createLucideIcon("chevrons-left", __iconNode3);
431
+
432
+ // node_modules/lucide-react/dist/esm/icons/chevrons-right.js
433
+ var __iconNode4 = [
434
+ ["path", { d: "m6 17 5-5-5-5", key: "xnjwq" }],
435
+ ["path", { d: "m13 17 5-5-5-5", key: "17xmmf" }]
436
+ ];
437
+ var ChevronsRight = createLucideIcon("chevrons-right", __iconNode4);
438
+
439
+ // src/dataTable/pagination/DataTablePagination.tsx
440
+ var import_jsx_runtime4 = require("react/jsx-runtime");
441
+ function DataTablePagination({
442
+ table
443
+ }) {
444
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex items-center justify-between px-2 pt-4", children: [
445
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "text-muted-foreground flex-1 text-sm", children: [
446
+ table.getFilteredRowModel().rows.length,
447
+ " rows"
448
+ ] }),
449
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex items-center space-x-6 lg:space-x-8", children: [
450
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex w-[100px] items-center justify-center text-sm font-medium", children: [
451
+ "Page ",
452
+ table.getState().pagination.pageIndex + 1,
453
+ " of",
454
+ " ",
455
+ table.getPageCount() || 1
456
+ ] }),
457
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex items-center space-x-2", children: [
458
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
459
+ Button,
460
+ {
461
+ className: "hidden size-8 lg:flex",
462
+ disabled: !table.getCanPreviousPage(),
463
+ onClick: () => table.setPageIndex(0),
464
+ size: "icon",
465
+ variant: "outline",
466
+ children: [
467
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "sr-only", children: "Go to first page" }),
468
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChevronsLeft, {})
469
+ ]
470
+ }
471
+ ),
472
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
473
+ Button,
474
+ {
475
+ className: "size-8",
476
+ disabled: !table.getCanPreviousPage(),
477
+ onClick: () => table.previousPage(),
478
+ size: "icon",
479
+ variant: "outline",
480
+ children: [
481
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "sr-only", children: "Go to previous page" }),
482
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChevronLeft, {})
483
+ ]
484
+ }
485
+ ),
486
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
487
+ Button,
488
+ {
489
+ className: "size-8",
490
+ disabled: !table.getCanNextPage(),
491
+ onClick: () => table.nextPage(),
492
+ size: "icon",
493
+ variant: "outline",
494
+ children: [
495
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "sr-only", children: "Go to next page" }),
496
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChevronRight, {})
497
+ ]
498
+ }
499
+ ),
500
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
501
+ Button,
502
+ {
503
+ className: "hidden size-8 lg:flex",
504
+ disabled: !table.getCanNextPage(),
505
+ onClick: () => table.setPageIndex(table.getPageCount() - 1),
506
+ size: "icon",
507
+ variant: "outline",
508
+ children: [
509
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "sr-only", children: "Go to last page" }),
510
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChevronsRight, {})
511
+ ]
512
+ }
513
+ )
514
+ ] })
515
+ ] })
516
+ ] });
517
+ }
518
+
519
+ // src/dataTable/DataTable.tsx
520
+ var import_react_table = require("@tanstack/react-table");
521
+ var import_jsx_runtime5 = require("react/jsx-runtime");
522
+ function DataTable({
523
+ columns,
524
+ data,
525
+ config
526
+ }) {
120
527
  const table = (0, import_react_table.useReactTable)({
121
528
  data,
122
529
  columns,
123
- getCoreRowModel: (0, import_react_table.getCoreRowModel)()
530
+ getCoreRowModel: (0, import_react_table.getCoreRowModel)(),
531
+ getPaginationRowModel: (0, import_react_table.getPaginationRowModel)(),
532
+ getFilteredRowModel: (0, import_react_table.getFilteredRowModel)(),
533
+ getFacetedRowModel: (0, import_react_table.getFacetedRowModel)(),
534
+ getFacetedUniqueValues: (0, import_react_table.getFacetedUniqueValues)(),
535
+ autoResetPageIndex: false,
536
+ initialState: {
537
+ columnVisibility: config?.columnVisibility
538
+ }
124
539
  });
125
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "w-full", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "rounded-md border overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Table, { children: [
126
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TableHeader, { className: "bg-muted", children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TableRow, { children: headerGroup.headers.map((header) => {
127
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
128
- TableHead,
540
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "w-full", children: [
541
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-md border overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Table, { children: [
542
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TableHeader, { className: "bg-muted", children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TableRow, { children: headerGroup.headers.map((header) => {
543
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
544
+ TableHead,
545
+ {
546
+ colSpan: header.colSpan,
547
+ style: { width: header.getSize() },
548
+ children: header.isPlaceholder ? null : (0, import_react_table.flexRender)(
549
+ header.column.columnDef.header,
550
+ header.getContext()
551
+ )
552
+ },
553
+ header.id
554
+ );
555
+ }) }, headerGroup.id)) }),
556
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TableBody, { children: table.getRowModel().rows?.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
557
+ TableRow,
129
558
  {
130
- colSpan: header.colSpan,
131
- style: { width: header.getSize() },
132
- children: header.isPlaceholder ? null : (0, import_react_table.flexRender)(
133
- header.column.columnDef.header,
134
- header.getContext()
135
- )
559
+ "data-state": row.getIsSelected() && "selected",
560
+ children: row.getVisibleCells().map((cell) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TableCell, { className: "truncate max-w-0", children: (0, import_react_table.flexRender)(
561
+ cell.column.columnDef.cell,
562
+ cell.getContext()
563
+ ) }, cell.id))
136
564
  },
137
- header.id
138
- );
139
- }) }, headerGroup.id)) }),
140
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TableBody, { children: table.getRowModel().rows?.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
141
- TableRow,
142
- {
143
- "data-state": row.getIsSelected() && "selected",
144
- children: row.getVisibleCells().map((cell) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TableCell, { className: "truncate max-w-0", children: (0, import_react_table.flexRender)(
145
- cell.column.columnDef.cell,
146
- cell.getContext()
147
- ) }, cell.id))
148
- },
149
- row.id
150
- )) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TableRow, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
151
- TableCell,
152
- {
153
- className: "h-24 text-center",
154
- colSpan: columns.length,
155
- children: "No results."
156
- }
157
- ) }) })
158
- ] }) }) });
565
+ row.id
566
+ )) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TableRow, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
567
+ TableCell,
568
+ {
569
+ className: "h-24 text-center",
570
+ colSpan: columns.length,
571
+ children: "No results."
572
+ }
573
+ ) }) })
574
+ ] }) }),
575
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DataTablePagination, { table })
576
+ ] });
159
577
  }
160
578
  // Annotate the CommonJS export names for ESM import in node:
161
579
  0 && (module.exports = {
162
580
  DataTable
163
581
  });
582
+ /*! Bundled license information:
583
+
584
+ lucide-react/dist/esm/shared/src/utils/mergeClasses.js:
585
+ lucide-react/dist/esm/shared/src/utils/toKebabCase.js:
586
+ lucide-react/dist/esm/shared/src/utils/toCamelCase.js:
587
+ lucide-react/dist/esm/shared/src/utils/toPascalCase.js:
588
+ lucide-react/dist/esm/defaultAttributes.js:
589
+ lucide-react/dist/esm/shared/src/utils/hasA11yProp.js:
590
+ lucide-react/dist/esm/Icon.js:
591
+ lucide-react/dist/esm/createLucideIcon.js:
592
+ lucide-react/dist/esm/icons/chevron-left.js:
593
+ lucide-react/dist/esm/icons/chevron-right.js:
594
+ lucide-react/dist/esm/icons/chevrons-left.js:
595
+ lucide-react/dist/esm/icons/chevrons-right.js:
596
+ lucide-react/dist/esm/lucide-react.js:
597
+ (**
598
+ * @license lucide-react v0.574.0 - ISC
599
+ *
600
+ * This source code is licensed under the ISC license.
601
+ * See the LICENSE file in the root directory of this source tree.
602
+ *)
603
+ */
package/dist/index.d.cts CHANGED
@@ -1,10 +1,16 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ColumnDef } from '@tanstack/react-table';
3
3
 
4
+ type ColumnVisibility<TData> = {
5
+ [K in keyof TData]?: boolean;
6
+ } & Record<string, boolean>;
4
7
  interface DataTableProps<TData, TValue> {
5
8
  columns: ColumnDef<TData, TValue>[];
6
9
  data: TData[];
10
+ config?: {
11
+ columnVisibility?: ColumnVisibility<TData>;
12
+ };
7
13
  }
8
- declare function DataTable<TData, TValue>({ columns, data }: DataTableProps<TData, TValue>): react_jsx_runtime.JSX.Element;
14
+ declare function DataTable<TData, TValue>({ columns, data, config, }: DataTableProps<TData, TValue>): react_jsx_runtime.JSX.Element;
9
15
 
10
16
  export { DataTable, type DataTableProps, DataTable as default };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,16 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ColumnDef } from '@tanstack/react-table';
3
3
 
4
+ type ColumnVisibility<TData> = {
5
+ [K in keyof TData]?: boolean;
6
+ } & Record<string, boolean>;
4
7
  interface DataTableProps<TData, TValue> {
5
8
  columns: ColumnDef<TData, TValue>[];
6
9
  data: TData[];
10
+ config?: {
11
+ columnVisibility?: ColumnVisibility<TData>;
12
+ };
7
13
  }
8
- declare function DataTable<TData, TValue>({ columns, data }: DataTableProps<TData, TValue>): react_jsx_runtime.JSX.Element;
14
+ declare function DataTable<TData, TValue>({ columns, data, config, }: DataTableProps<TData, TValue>): react_jsx_runtime.JSX.Element;
9
15
 
10
16
  export { DataTable, type DataTableProps, DataTable as default };