@brightlocal/ui-components 2.6.1 → 2.8.0

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.
@@ -1,328 +1,312 @@
1
- import { jsx as e, jsxs as S, Fragment as D } from "react/jsx-runtime";
2
- import * as P from "react";
3
- import { flexRender as A, useReactTable as ee, getExpandedRowModel as te, getFilteredRowModel as ae, getSortedRowModel as ne, getPaginationRowModel as oe, getCoreRowModel as le } from "@tanstack/react-table";
4
- import { createColumnHelper as Ye, flexRender as Ze } from "@tanstack/react-table";
5
- import { useVirtualizer as ie } from "@tanstack/react-virtual";
6
- import { ArrowDown as re, ArrowUp as se, ArrowUpDown as ce, Ellipsis as de, Search as ge } from "@brightlocal/icons";
7
- import { cn as b } from "@brightlocal/ui-components/lib/utils";
8
- import { Button as E } from "../button.js";
9
- import { Checkbox as H } from "../checkbox.js";
10
- import { DropdownMenu as ue, DropdownMenuTrigger as me, DropdownMenuContent as pe } from "../dropdown-menu.js";
11
- import { InputGroup as he, InputGroupInput as be, InputGroupAddon as fe } from "../input-group.js";
12
- import { usePagination as Se, Pagination as Ce, PaginationContent as we, PaginationItem as $, PaginationPrevious as xe, PaginationNext as ke, PaginationEllipsis as ve, PaginationLink as Re } from "../pagination.js";
13
- import { Skeleton as Te } from "../skeleton.js";
14
- import { Table as V, TableHeader as j, TableRow as k, TableHead as G, TableBody as L, TableCell as T } from "../table.js";
15
- function y(t, a, l) {
16
- const [n, o] = P.useState(a), r = t !== void 0 ? t : n, i = P.useRef(r);
17
- P.useEffect(() => {
18
- i.current = r;
1
+ import { jsx as a, jsxs as S, Fragment as T } from "react/jsx-runtime";
2
+ import * as m from "react";
3
+ import { useReactTable as ne, getExpandedRowModel as oe, getFilteredRowModel as le, getSortedRowModel as ie, getPaginationRowModel as re, getCoreRowModel as se, flexRender as A } from "@tanstack/react-table";
4
+ import { useVirtualizer as ce } from "@tanstack/react-virtual";
5
+ import { ArrowDown as de, ArrowUp as ue, ArrowUpDown as ge, Search as me, X as pe } from "@brightlocal/icons";
6
+ import { cn as h } from "@brightlocal/ui-components/lib/utils";
7
+ import { Button as H } from "../button.js";
8
+ import { Checkbox as V } from "../checkbox.js";
9
+ import { InputGroup as he, InputGroupAddon as M, InputGroupInput as fe } from "../input-group.js";
10
+ import { usePagination as be, Pagination as Se, PaginationContent as we, PaginationItem as z, PaginationPrevious as Ce, PaginationNext as xe, PaginationEllipsis as Pe, PaginationLink as ve } from "../pagination.js";
11
+ import { Skeleton as Re } from "../skeleton.js";
12
+ import { Table as j, TableBody as E, TableRow as C, TableCell as x, TableHeader as Te, TableHead as ke } from "../table.js";
13
+ function R(e, n, l) {
14
+ const [t, i] = m.useState(n), o = e !== void 0 ? e : t, r = m.useRef(o);
15
+ m.useEffect(() => {
16
+ r.current = o;
19
17
  });
20
- const c = t !== void 0, d = P.useCallback(
21
- (h) => {
22
- const g = typeof h == "function" ? h(i.current) : h;
23
- c || o(g), l?.(g);
18
+ const c = e !== void 0, d = m.useCallback(
19
+ (s) => {
20
+ const u = typeof s == "function" ? s(r.current) : s;
21
+ c || i(u), l?.(u);
24
22
  },
25
23
  [c, l]
26
24
  );
27
- return [r, d];
25
+ return [o, d];
28
26
  }
29
- function Qe(t) {
27
+ function Qe(e) {
30
28
  const {
31
- columns: a,
29
+ columns: n,
32
30
  data: l,
33
- enableSorting: n = !0,
34
- enableGlobalFiltering: o = !1,
35
- enableRowSelection: r = !1,
36
- enablePagination: i = !1,
31
+ enableSorting: t = !0,
32
+ enableGlobalFiltering: i = !1,
33
+ enableRowSelection: o = !1,
34
+ enablePagination: r = !1,
37
35
  pageSize: c = 10,
38
36
  manualSorting: d = !1,
39
- manualFiltering: h = !1,
40
- manualPagination: g = !1,
41
- rowCount: C,
42
- pageCount: u,
43
- enableExpanding: s = !1,
37
+ manualFiltering: s = !1,
38
+ manualPagination: u = !1,
39
+ rowCount: p,
40
+ pageCount: g,
41
+ enableExpanding: f = !1,
44
42
  getSubRows: w,
45
- getRowId: f,
46
- pagination: m,
47
- onPaginationChange: v,
48
- sorting: x,
49
- onSortingChange: F,
50
- globalFilter: N,
51
- onGlobalFilterChange: z,
52
- rowSelection: R,
53
- onRowSelectionChange: p,
54
- expanded: I,
55
- onExpandedChange: M
56
- } = t, [_, O] = y(
57
- m,
43
+ getRowId: P,
44
+ pagination: v,
45
+ onPaginationChange: k,
46
+ sorting: b,
47
+ onSortingChange: I,
48
+ globalFilter: y,
49
+ onGlobalFilterChange: N,
50
+ rowSelection: $,
51
+ onRowSelectionChange: D,
52
+ expanded: X,
53
+ onExpandedChange: q
54
+ } = e, [J, K] = R(
55
+ v,
58
56
  { pageIndex: 0, pageSize: c },
59
- v
60
- ), [q, J] = y(
61
- x,
57
+ k
58
+ ), [O, Q] = R(
59
+ b,
62
60
  [],
63
- F
64
- ), [K, Q] = y(
65
- N,
61
+ I
62
+ ), [W, Y] = R(
63
+ y,
66
64
  "",
67
- z
68
- ), [W, X] = y(R, {}, p), [Y, Z] = y(
69
- I,
65
+ N
66
+ ), [Z, ee] = R($, {}, D), [ae, te] = R(
67
+ X,
70
68
  {},
71
- M
69
+ q
72
70
  );
73
- return ee({
71
+ return ne({
74
72
  data: l,
75
- columns: a,
76
- getCoreRowModel: le(),
77
- ...f && { getRowId: f },
78
- ...(i || g) && {
79
- onPaginationChange: O
73
+ columns: n,
74
+ getCoreRowModel: se(),
75
+ ...P && { getRowId: P },
76
+ ...(r || u) && {
77
+ onPaginationChange: K
80
78
  },
81
- ...i && {
82
- ...!g && {
83
- getPaginationRowModel: oe()
79
+ ...r && {
80
+ ...!u && {
81
+ getPaginationRowModel: re()
84
82
  }
85
83
  },
86
- ...g && {
84
+ ...u && {
87
85
  manualPagination: !0,
88
- ...C != null && { rowCount: C },
89
- ...u != null && { pageCount: u }
86
+ ...p != null && { rowCount: p },
87
+ ...g != null && { pageCount: g }
90
88
  },
91
- ...n && {
89
+ ...t && {
92
90
  ...!d && {
93
- getSortedRowModel: ne()
91
+ getSortedRowModel: ie()
94
92
  },
95
- onSortingChange: J,
93
+ onSortingChange: Q,
96
94
  ...d && { manualSorting: !0 }
97
95
  },
98
- ...o && {
99
- ...!h && {
100
- getFilteredRowModel: ae()
96
+ ...i && {
97
+ ...!s && {
98
+ getFilteredRowModel: le()
101
99
  },
102
- ...h && { manualFiltering: !0 },
103
- onGlobalFilterChange: Q,
100
+ ...s && { manualFiltering: !0 },
101
+ onGlobalFilterChange: Y,
104
102
  globalFilterFn: "includesString"
105
103
  },
106
- ...r && {
104
+ ...o && {
107
105
  enableRowSelection: !0,
108
- onRowSelectionChange: X
106
+ onRowSelectionChange: ee
109
107
  },
110
- ...s && {
111
- getExpandedRowModel: te(),
112
- onExpandedChange: Z,
108
+ ...f && {
109
+ getExpandedRowModel: oe(),
110
+ onExpandedChange: te,
113
111
  getSubRows: w
114
112
  },
115
113
  state: {
116
- pagination: _,
117
- sorting: q,
118
- globalFilter: K,
119
- rowSelection: W,
120
- expanded: Y
114
+ pagination: J,
115
+ sorting: O,
116
+ globalFilter: W,
117
+ rowSelection: Z,
118
+ expanded: ae
121
119
  }
122
120
  });
123
121
  }
124
122
  function ye({
125
- table: t,
126
- dataHook: a,
123
+ table: e,
124
+ dataHook: n,
127
125
  trackingEl: l,
128
- trackingLabel: n,
129
- isLoading: o = !1,
130
- skeletonRowCount: r,
131
- noResultsMessage: i = "No results.",
126
+ trackingLabel: t,
127
+ isLoading: i = !1,
128
+ skeletonRowCount: o,
129
+ noResultsMessage: r = "No results.",
132
130
  stickyHeader: c = !1,
133
131
  className: d,
134
- footer: h
132
+ footer: s
135
133
  }) {
136
- const g = t.getVisibleLeafColumns().length, C = r ?? t.getState().pagination.pageSize ?? 10;
137
- return /* @__PURE__ */ e(
134
+ const u = e.getVisibleLeafColumns().length, p = o ?? e.getState().pagination.pageSize ?? 10;
135
+ return /* @__PURE__ */ a(
138
136
  "div",
139
137
  {
140
- "aria-busy": o || void 0,
141
- className: b("border-border rounded-md border", d),
142
- "data-hook": a,
138
+ "aria-busy": i || void 0,
139
+ className: h("border-border overflow-auto rounded-md border", d),
140
+ "data-hook": n,
143
141
  "data-slot": "data-table-view",
144
142
  "data-tracking-el": l,
145
- "data-tracking-label": n,
146
- children: /* @__PURE__ */ S(V, { dataHook: `${a}-table`, children: [
147
- /* @__PURE__ */ e(
148
- j,
149
- {
150
- className: b(c && "bg-background sticky top-0 z-10"),
151
- children: t.getHeaderGroups().map((u) => /* @__PURE__ */ e(k, { children: u.headers.map((s) => {
152
- const w = s.column.getCanSort() ? s.column.getIsSorted() : !1, f = w === "asc" ? "ascending" : w === "desc" ? "descending" : s.column.getCanSort() ? "none" : void 0;
153
- return /* @__PURE__ */ e(
154
- G,
155
- {
156
- "aria-sort": f,
157
- colSpan: s.colSpan,
158
- children: s.isPlaceholder ? null : A(
159
- s.column.columnDef.header,
160
- s.getContext()
161
- )
162
- },
163
- s.id
164
- );
165
- }) }, u.id))
166
- }
167
- ),
168
- /* @__PURE__ */ e(L, { children: o ? /* @__PURE__ */ S(D, { children: [
169
- /* @__PURE__ */ e(
170
- U,
143
+ "data-tracking-label": t,
144
+ children: /* @__PURE__ */ S(j, { dataHook: `${n}-table`, children: [
145
+ /* @__PURE__ */ a(G, { stickyHeader: c, table: e }),
146
+ /* @__PURE__ */ a(E, { children: i ? /* @__PURE__ */ S(T, { children: [
147
+ /* @__PURE__ */ a(
148
+ B,
171
149
  {
172
- colCount: g,
173
- rowCount: C
150
+ colCount: u,
151
+ rowCount: p
174
152
  }
175
153
  ),
176
- /* @__PURE__ */ e(k, { className: "sr-only", children: /* @__PURE__ */ e(T, { colSpan: g, children: /* @__PURE__ */ e("div", { "aria-live": "polite", role: "status", children: "Loading data…" }) }) })
177
- ] }) : /* @__PURE__ */ e(D, { children: t.getRowModel().rows.length > 0 ? t.getRowModel().rows.map((u) => /* @__PURE__ */ e(B, { row: u }, u.id)) : /* @__PURE__ */ e(k, { children: /* @__PURE__ */ e(T, { colSpan: g, children: /* @__PURE__ */ e("div", { "aria-live": "polite", role: "status", children: i }) }) }) }) }),
178
- h
154
+ /* @__PURE__ */ a(C, { className: "sr-only", children: /* @__PURE__ */ a(x, { colSpan: u, children: /* @__PURE__ */ a("div", { "aria-live": "polite", role: "status", children: "Loading data…" }) }) })
155
+ ] }) : /* @__PURE__ */ a(T, { children: e.getRowModel().rows.length > 0 ? e.getRowModel().rows.map((g) => /* @__PURE__ */ a(L, { row: g }, g.id)) : /* @__PURE__ */ a(C, { children: /* @__PURE__ */ a(x, { colSpan: u, children: /* @__PURE__ */ a("div", { "aria-live": "polite", role: "status", children: r }) }) }) }) }),
156
+ s
179
157
  ] })
180
158
  }
181
159
  );
182
160
  }
183
161
  ye.displayName = "DataTable";
184
- function B({ row: t }) {
185
- return /* @__PURE__ */ e(k, { "data-state": t.getIsSelected() ? "selected" : void 0, children: t.getVisibleCells().map((a) => /* @__PURE__ */ e(T, { children: A(a.column.columnDef.cell, a.getContext()) }, a.id)) });
162
+ function G({
163
+ table: e,
164
+ stickyHeader: n
165
+ }) {
166
+ return /* @__PURE__ */ a(
167
+ Te,
168
+ {
169
+ className: h(n && "bg-background sticky top-0 z-10"),
170
+ children: e.getHeaderGroups().map((l) => /* @__PURE__ */ a(C, { children: l.headers.map((t) => {
171
+ const i = t.column.getCanSort() ? t.column.getIsSorted() : !1, o = i === "asc" ? "ascending" : i === "desc" ? "descending" : t.column.getCanSort() ? "none" : void 0;
172
+ return /* @__PURE__ */ a(
173
+ ke,
174
+ {
175
+ "aria-sort": o,
176
+ colSpan: t.colSpan,
177
+ children: t.isPlaceholder ? null : A(
178
+ t.column.columnDef.header,
179
+ t.getContext()
180
+ )
181
+ },
182
+ t.id
183
+ );
184
+ }) }, l.id))
185
+ }
186
+ );
186
187
  }
187
- function U({
188
- rowCount: t,
189
- colCount: a
188
+ function L({ row: e }) {
189
+ return /* @__PURE__ */ a(C, { "data-state": e.getIsSelected() ? "selected" : void 0, children: e.getVisibleCells().map((n) => /* @__PURE__ */ a(x, { children: A(n.column.columnDef.cell, n.getContext()) }, n.id)) });
190
+ }
191
+ function B({
192
+ rowCount: e,
193
+ colCount: n
190
194
  }) {
191
- return /* @__PURE__ */ e(D, { children: Array.from({ length: t }).map((l, n) => /* @__PURE__ */ e(k, { children: Array.from({ length: a }).map((o, r) => /* @__PURE__ */ e(T, { children: /* @__PURE__ */ e(Te, { className: "h-4 w-full" }) }, `skeleton-${n}-${r}`)) }, `skeleton-${n}`)) });
195
+ return /* @__PURE__ */ a(T, { children: Array.from({ length: e }).map((l, t) => /* @__PURE__ */ a(C, { children: Array.from({ length: n }).map((i, o) => /* @__PURE__ */ a(x, { children: /* @__PURE__ */ a(Re, { className: "h-4 w-full" }) }, `skeleton-${t}-${o}`)) }, `skeleton-${t}`)) });
192
196
  }
193
- function Pe({
194
- table: t,
195
- dataHook: a,
197
+ function Ne({
198
+ table: e,
199
+ dataHook: n,
196
200
  trackingEl: l,
197
- trackingLabel: n,
198
- isLoading: o = !1,
199
- skeletonRowCount: r,
200
- noResultsMessage: i = "No results.",
201
+ trackingLabel: t,
202
+ isLoading: i = !1,
203
+ skeletonRowCount: o,
204
+ noResultsMessage: r = "No results.",
201
205
  stickyHeader: c = !1,
202
206
  className: d,
203
- footer: h,
204
- height: g,
205
- estimateSize: C = 48,
206
- overscan: u = 5
207
+ footer: s,
208
+ height: u,
209
+ estimateSize: p = 48,
210
+ overscan: g = 5
207
211
  }) {
208
- const s = t.getVisibleLeafColumns().length, w = r ?? t.getState().pagination.pageSize ?? 10, f = P.useRef(null), m = t.getRowModel().rows, v = ie({
209
- count: m.length,
210
- getScrollElement: () => f.current,
211
- estimateSize: () => C,
212
- overscan: u
213
- }), x = v.getVirtualItems(), F = v.getTotalSize(), N = x.length > 0 ? x[0].start : 0, z = x.length > 0 ? F - x[x.length - 1].end : 0;
214
- return /* @__PURE__ */ e(
212
+ const f = e.getVisibleLeafColumns().length, w = o ?? e.getState().pagination.pageSize ?? 10, P = m.useRef(null), v = e.getRowModel().rows, k = ce({
213
+ count: v.length,
214
+ getScrollElement: () => P.current,
215
+ estimateSize: () => p,
216
+ overscan: g
217
+ }), b = k.getVirtualItems(), I = k.getTotalSize(), y = b.length > 0 ? b[0].start : 0, N = b.length > 0 ? I - b[b.length - 1].end : 0;
218
+ return /* @__PURE__ */ a(
215
219
  "div",
216
220
  {
217
- ref: f,
218
- "aria-busy": o || void 0,
219
- className: b("border-border overflow-auto rounded-md border", d),
220
- "data-hook": a,
221
+ ref: P,
222
+ "aria-busy": i || void 0,
223
+ className: h("border-border overflow-auto rounded-md border", d),
224
+ "data-hook": n,
221
225
  "data-slot": "data-table-view",
222
226
  "data-tracking-el": l,
223
- "data-tracking-label": n,
224
- style: g != null ? { height: g } : void 0,
225
- children: /* @__PURE__ */ S(V, { dataHook: `${a}-table`, children: [
226
- /* @__PURE__ */ e(
227
- j,
228
- {
229
- className: b(c && "bg-background sticky top-0 z-10"),
230
- children: t.getHeaderGroups().map((R) => /* @__PURE__ */ e(k, { children: R.headers.map((p) => {
231
- const I = p.column.getCanSort() ? p.column.getIsSorted() : !1, M = I === "asc" ? "ascending" : I === "desc" ? "descending" : p.column.getCanSort() ? "none" : void 0;
232
- return /* @__PURE__ */ e(
233
- G,
234
- {
235
- "aria-sort": M,
236
- colSpan: p.colSpan,
237
- children: p.isPlaceholder ? null : A(
238
- p.column.columnDef.header,
239
- p.getContext()
240
- )
241
- },
242
- p.id
243
- );
244
- }) }, R.id))
245
- }
246
- ),
247
- /* @__PURE__ */ e(L, { children: o ? /* @__PURE__ */ S(D, { children: [
248
- /* @__PURE__ */ e(
249
- U,
227
+ "data-tracking-label": t,
228
+ style: u != null ? { height: u } : void 0,
229
+ children: /* @__PURE__ */ S(j, { dataHook: `${n}-table`, children: [
230
+ /* @__PURE__ */ a(G, { stickyHeader: c, table: e }),
231
+ /* @__PURE__ */ a(E, { children: i ? /* @__PURE__ */ S(T, { children: [
232
+ /* @__PURE__ */ a(
233
+ B,
250
234
  {
251
- colCount: s,
235
+ colCount: f,
252
236
  rowCount: w
253
237
  }
254
238
  ),
255
- /* @__PURE__ */ e(k, { className: "sr-only", children: /* @__PURE__ */ e(T, { colSpan: s, children: /* @__PURE__ */ e("div", { "aria-live": "polite", role: "status", children: "Loading data…" }) }) })
256
- ] }) : m.length > 0 ? /* @__PURE__ */ S(D, { children: [
257
- N > 0 && /* @__PURE__ */ e("tr", { "aria-hidden": "true", children: /* @__PURE__ */ e("td", { colSpan: s, style: { height: N } }) }),
258
- x.map((R) => {
259
- const p = m[R.index];
260
- return /* @__PURE__ */ e(B, { row: p }, p.id);
239
+ /* @__PURE__ */ a(C, { className: "sr-only", children: /* @__PURE__ */ a(x, { colSpan: f, children: /* @__PURE__ */ a("div", { "aria-live": "polite", role: "status", children: "Loading data…" }) }) })
240
+ ] }) : v.length > 0 ? /* @__PURE__ */ S(T, { children: [
241
+ y > 0 && /* @__PURE__ */ a("tr", { "aria-hidden": "true", children: /* @__PURE__ */ a("td", { colSpan: f, style: { height: y } }) }),
242
+ b.map(($) => {
243
+ const D = v[$.index];
244
+ return /* @__PURE__ */ a(L, { row: D }, D.id);
261
245
  }),
262
- z > 0 && /* @__PURE__ */ e("tr", { "aria-hidden": "true", children: /* @__PURE__ */ e("td", { colSpan: s, style: { height: z } }) })
263
- ] }) : /* @__PURE__ */ e(k, { children: /* @__PURE__ */ e(T, { colSpan: s, children: /* @__PURE__ */ e("div", { "aria-live": "polite", role: "status", children: i }) }) }) }),
264
- h
246
+ N > 0 && /* @__PURE__ */ a("tr", { "aria-hidden": "true", children: /* @__PURE__ */ a("td", { colSpan: f, style: { height: N } }) })
247
+ ] }) : /* @__PURE__ */ a(C, { children: /* @__PURE__ */ a(x, { colSpan: f, children: /* @__PURE__ */ a("div", { "aria-live": "polite", role: "status", children: r }) }) }) }),
248
+ s
265
249
  ] })
266
250
  }
267
251
  );
268
252
  }
269
- Pe.displayName = "VirtualizedDataTable";
253
+ Ne.displayName = "VirtualizedDataTable";
270
254
  function De({
271
- column: t,
272
- title: a,
255
+ column: e,
256
+ title: n,
273
257
  className: l,
274
- dataHook: n,
275
- trackingEl: o,
276
- trackingLabel: r,
277
- align: i = "left"
258
+ dataHook: t,
259
+ trackingEl: i,
260
+ trackingLabel: o,
261
+ align: r = "left"
278
262
  }) {
279
- if (!t.getCanSort())
280
- return /* @__PURE__ */ e(
263
+ if (!e.getCanSort())
264
+ return /* @__PURE__ */ a(
281
265
  "div",
282
266
  {
283
- className: b(
267
+ className: h(
284
268
  "text-muted-foreground text-left text-sm leading-normal font-medium",
285
- i === "right" && "text-right",
286
- i === "center" && "text-center",
269
+ r === "right" && "text-right",
270
+ r === "center" && "text-center",
287
271
  l
288
272
  ),
289
- "data-hook": n,
273
+ "data-hook": t,
290
274
  "data-slot": "data-table-column-header",
291
- "data-tracking-el": o,
292
- "data-tracking-label": r,
293
- children: a
275
+ "data-tracking-el": i,
276
+ "data-tracking-label": o,
277
+ children: n
294
278
  }
295
279
  );
296
- const c = t.getIsSorted(), d = c === "desc" ? `Sort by ${a}, currently descending` : c === "asc" ? `Sort by ${a}, currently ascending` : `Sort by ${a}`;
297
- return /* @__PURE__ */ e(
280
+ const c = e.getIsSorted(), d = c === "desc" ? `Sort by ${n}, currently descending` : c === "asc" ? `Sort by ${n}, currently ascending` : `Sort by ${n}`;
281
+ return /* @__PURE__ */ a(
298
282
  "div",
299
283
  {
300
- className: b(
284
+ className: h(
301
285
  "flex items-center",
302
- i === "right" && "justify-end",
303
- i === "center" && "justify-center",
286
+ r === "right" && "justify-end",
287
+ r === "center" && "justify-center",
304
288
  l
305
289
  ),
306
290
  "data-slot": "data-table-column-header",
307
- "data-tracking-el": o,
308
- "data-tracking-label": r,
291
+ "data-tracking-el": i,
292
+ "data-tracking-label": o,
309
293
  children: /* @__PURE__ */ S(
310
- E,
294
+ H,
311
295
  {
312
296
  "aria-label": d,
313
297
  className: "text-muted-foreground h-auto p-0 text-sm font-medium",
314
- dataHook: n || `column-header-${t.id}`,
298
+ dataHook: t || `column-header-${e.id}`,
315
299
  size: "sm",
316
300
  variant: "ghost",
317
- onClick: () => t.toggleSorting(c === "asc"),
301
+ onClick: () => e.toggleSorting(c === "asc"),
318
302
  children: [
319
- /* @__PURE__ */ e("span", { "aria-hidden": "true", children: a }),
320
- /* @__PURE__ */ e(
303
+ /* @__PURE__ */ a("span", { "aria-hidden": "true", children: n }),
304
+ /* @__PURE__ */ a(
321
305
  "span",
322
306
  {
323
307
  "aria-hidden": "true",
324
308
  className: "flex size-3 items-center justify-center",
325
- children: c === "desc" ? /* @__PURE__ */ e(re, { size: 12 }) : c === "asc" ? /* @__PURE__ */ e(se, { size: 12 }) : /* @__PURE__ */ e(ce, { size: 12 })
309
+ children: c === "desc" ? /* @__PURE__ */ a(de, { size: 12 }) : c === "asc" ? /* @__PURE__ */ a(ue, { size: 12 }) : /* @__PURE__ */ a(ge, { size: 12 })
326
310
  }
327
311
  )
328
312
  ]
@@ -332,234 +316,311 @@ function De({
332
316
  );
333
317
  }
334
318
  De.displayName = "DataTableColumnHeader";
335
- function Ne({
336
- row: t,
337
- dataHook: a,
338
- trackingEl: l,
339
- trackingLabel: n,
340
- ariaLabel: o = "Open row actions menu",
341
- children: r
319
+ function ze({
320
+ table: e,
321
+ ariaLabel: n = "Search table",
322
+ placeholder: l = "Search...",
323
+ ...t
342
324
  }) {
343
- return /* @__PURE__ */ S(ue, { children: [
344
- /* @__PURE__ */ e(me, { asChild: !0, "data-slot": "data-table-row-actions", children: /* @__PURE__ */ e(
345
- E,
325
+ const i = e.getState().globalFilter ?? "", o = (r) => {
326
+ e.setGlobalFilter(r);
327
+ };
328
+ return /* @__PURE__ */ S(he, { "data-slot": "data-table-search", ...t, children: [
329
+ /* @__PURE__ */ a(M, { className: "pl-3", children: /* @__PURE__ */ a(me, {}) }),
330
+ /* @__PURE__ */ a(
331
+ fe,
346
332
  {
347
- "aria-label": o,
348
- dataHook: a || `row-actions-${t.id}`,
349
- size: "sm",
350
- trackingEl: l,
351
- trackingLabel: n,
352
- variant: "ghost",
353
- children: /* @__PURE__ */ e(de, {})
333
+ "aria-label": n,
334
+ placeholder: l,
335
+ type: "text",
336
+ value: i,
337
+ onChange: (r) => o(r.target.value)
354
338
  }
355
- ) }),
356
- /* @__PURE__ */ e(
357
- pe,
339
+ ),
340
+ i && /* @__PURE__ */ a(M, { className: "pr-1", children: /* @__PURE__ */ a(
341
+ H,
358
342
  {
359
- align: "end",
360
- dataHook: a ? `${a}-menu` : `row-actions-${t.id}-menu`,
361
- children: r
343
+ "aria-label": "Clear search",
344
+ className: "h-auto p-1",
345
+ "data-slot": "data-table-search-clear",
346
+ dataHook: `${t.dataHook}-clear`,
347
+ variant: "ghost",
348
+ onClick: () => o(""),
349
+ children: /* @__PURE__ */ a(pe, { size: 14 })
362
350
  }
363
- )
351
+ ) })
364
352
  ] });
365
353
  }
366
- Ne.displayName = "DataTableRowActions";
367
- function ze({
368
- dataHook: t,
369
- trackingEl: a,
370
- trackingLabel: l,
371
- className: n,
372
- children: o
373
- }) {
374
- return /* @__PURE__ */ e(
375
- "div",
376
- {
377
- className: b("flex items-center gap-2", n),
378
- "data-hook": t,
379
- "data-slot": "data-table-toolbar-left",
380
- "data-tracking-el": a,
381
- "data-tracking-label": l,
382
- children: o
383
- }
354
+ ze.displayName = "DataTableSearch";
355
+ function Ie(e) {
356
+ const { pageIndex: n, pageSize: l } = e.getState().pagination, t = e.getRowCount(), i = e.getPageCount(), o = e.getCanPreviousPage(), r = e.getCanNextPage(), c = n + 1, d = t === 0 ? 0 : n * l + 1, s = Math.min(c * l, t), u = m.useCallback(
357
+ (w) => e.setPageIndex(w - 1),
358
+ [e]
359
+ ), p = m.useCallback(() => e.nextPage(), [e]), g = m.useCallback(() => e.previousPage(), [e]), f = m.useCallback(
360
+ (w) => e.setPageSize(w),
361
+ [e]
362
+ );
363
+ return m.useMemo(
364
+ () => ({
365
+ pageIndex: n,
366
+ pageSize: l,
367
+ totalRows: t,
368
+ totalPages: i,
369
+ startRow: d,
370
+ endRow: s,
371
+ currentPage: c,
372
+ canPrev: o,
373
+ canNext: r,
374
+ goToPage: u,
375
+ nextPage: p,
376
+ previousPage: g,
377
+ setPageSize: f
378
+ }),
379
+ [
380
+ n,
381
+ l,
382
+ t,
383
+ i,
384
+ d,
385
+ s,
386
+ c,
387
+ o,
388
+ r,
389
+ u,
390
+ p,
391
+ g,
392
+ f
393
+ ]
384
394
  );
385
395
  }
386
- ze.displayName = "DataTableToolbarLeft";
387
- function Ie({
388
- dataHook: t,
389
- trackingEl: a,
390
- trackingLabel: l,
391
- className: n,
392
- children: o
396
+ const F = m.createContext(null);
397
+ function U() {
398
+ const e = m.useContext(F);
399
+ if (!e)
400
+ throw new Error(
401
+ "DataTablePagination sub-components must be used within <DataTablePagination>"
402
+ );
403
+ return e;
404
+ }
405
+ function $e({
406
+ renderText: e,
407
+ className: n
393
408
  }) {
394
- return /* @__PURE__ */ e(
395
- "div",
409
+ const { info: l } = U(), { startRow: t, endRow: i, totalRows: o, pageIndex: r, pageSize: c } = l, d = e ? e({ startRow: t, endRow: i, totalRows: o, pageIndex: r, pageSize: c }) : o === 0 ? null : `${t}-${i} of ${o}`;
410
+ return d == null ? null : /* @__PURE__ */ a(
411
+ "span",
396
412
  {
397
- className: b("flex items-center gap-2", n),
398
- "data-hook": t,
399
- "data-slot": "data-table-toolbar-right",
400
- "data-tracking-el": a,
401
- "data-tracking-label": l,
402
- children: o
413
+ className: h("text-muted-foreground text-sm", n),
414
+ "data-slot": "data-table-pagination-row-count",
415
+ children: d
403
416
  }
404
417
  );
405
418
  }
406
- Ie.displayName = "DataTableToolbarRight";
407
- function $e({
408
- dataHook: t,
409
- trackingEl: a,
410
- trackingLabel: l,
411
- className: n,
412
- children: o
419
+ $e.displayName = "DataTablePaginationRowCount";
420
+ function _({
421
+ ariaLabel: e = "Table pagination",
422
+ dataHook: n,
423
+ className: l
413
424
  }) {
414
- return /* @__PURE__ */ e(
415
- "div",
425
+ const { info: t } = U(), i = be({
426
+ page: t.currentPage,
427
+ totalPages: t.totalPages,
428
+ siblingCount: 1,
429
+ boundaryCount: 1
430
+ });
431
+ return /* @__PURE__ */ a(
432
+ Se,
416
433
  {
417
- className: b(
418
- "flex flex-wrap items-center justify-between gap-2 py-4",
419
- n
420
- ),
421
- "data-hook": t,
422
- "data-slot": "data-table-toolbar",
423
- "data-tracking-el": a,
424
- "data-tracking-label": l,
425
- children: o
434
+ ariaLabel: e,
435
+ className: h("mx-0 w-auto justify-end", l),
436
+ dataHook: n ?? "pagination-nav",
437
+ children: /* @__PURE__ */ a(we, { children: i.map((o, r) => o === "previous" ? /* @__PURE__ */ a(z, { children: /* @__PURE__ */ a(
438
+ Ce,
439
+ {
440
+ disabled: !t.canPrev,
441
+ onClick: () => t.previousPage()
442
+ }
443
+ ) }, "previous") : o === "next" ? /* @__PURE__ */ a(z, { children: /* @__PURE__ */ a(
444
+ xe,
445
+ {
446
+ disabled: !t.canNext,
447
+ onClick: () => t.nextPage()
448
+ }
449
+ ) }, "next") : o === "ellipsis" ? /* @__PURE__ */ a(z, { children: /* @__PURE__ */ a(Pe, {}) }, `ellipsis-${r}`) : /* @__PURE__ */ a(z, { children: /* @__PURE__ */ a(
450
+ ve,
451
+ {
452
+ isActive: o === t.currentPage,
453
+ page: o,
454
+ onClick: () => t.goToPage(o)
455
+ }
456
+ ) }, o)) })
426
457
  }
427
458
  );
428
459
  }
429
- $e.displayName = "DataTableToolbar";
460
+ _.displayName = "DataTablePaginationNav";
430
461
  function Fe({
431
- table: t,
432
- ariaLabel: a = "Search table",
433
- placeholder: l = "Search...",
434
- ...n
462
+ table: e,
463
+ dataHook: n,
464
+ showRowCount: l = !0,
465
+ renderRowCount: t,
466
+ trackingEl: i,
467
+ trackingLabel: o,
468
+ className: r,
469
+ ariaLabel: c = "Table pagination",
470
+ children: d
435
471
  }) {
436
- const o = t.getState().globalFilter ?? "", r = (i) => {
437
- t.setGlobalFilter(i);
472
+ const s = Ie(e), u = m.useMemo(
473
+ () => ({ info: s }),
474
+ [s]
475
+ ), p = {
476
+ "data-hook": n,
477
+ "data-slot": "data-table-pagination",
478
+ "data-tracking-el": i,
479
+ "data-tracking-label": o
438
480
  };
439
- return /* @__PURE__ */ S(he, { ...n, children: [
440
- /* @__PURE__ */ e(
441
- be,
481
+ if (d)
482
+ return /* @__PURE__ */ a(F.Provider, { value: u, children: /* @__PURE__ */ a(
483
+ "div",
442
484
  {
443
- "aria-label": a,
444
- placeholder: l,
445
- type: "text",
446
- value: o,
447
- onChange: (i) => r(i.target.value)
485
+ className: h("flex w-full items-center gap-4", r),
486
+ ...p,
487
+ children: d
448
488
  }
449
- ),
450
- /* @__PURE__ */ e(fe, { className: "pr-3", children: /* @__PURE__ */ e(ge, {}) })
451
- ] });
452
- }
453
- Fe.displayName = "DataTableSearch";
454
- function Me({
455
- table: t,
456
- dataHook: a,
457
- trackingEl: l,
458
- trackingLabel: n,
459
- className: o,
460
- ariaLabel: r = "Table pagination"
461
- }) {
462
- const { pageIndex: i, pageSize: c } = t.getState().pagination, d = t.getRowCount(), h = t.getPageCount(), g = t.getCanPreviousPage(), C = t.getCanNextPage(), u = i + 1, s = d === 0 ? 0 : i * c + 1, w = Math.min(u * c, d), f = Se({
463
- page: u,
464
- totalPages: h,
465
- siblingCount: 1,
466
- boundaryCount: 1
467
- });
468
- return /* @__PURE__ */ S(
489
+ ) });
490
+ const g = !l || t === null ? null : t ? t({
491
+ startRow: s.startRow,
492
+ endRow: s.endRow,
493
+ totalRows: s.totalRows,
494
+ pageIndex: s.pageIndex,
495
+ pageSize: s.pageSize
496
+ }) : s.totalRows === 0 ? null : `${s.startRow}-${s.endRow} of ${s.totalRows}`;
497
+ return /* @__PURE__ */ a(F.Provider, { value: u, children: /* @__PURE__ */ S(
469
498
  "div",
470
499
  {
471
- className: b("flex items-center justify-end gap-4", o),
472
- "data-hook": a,
473
- "data-slot": "data-table-pagination",
474
- "data-tracking-el": l,
475
- "data-tracking-label": n,
500
+ className: h(
501
+ "flex w-full items-center gap-4",
502
+ g != null ? "justify-between" : "justify-end",
503
+ r
504
+ ),
505
+ ...p,
476
506
  children: [
477
- /* @__PURE__ */ e("span", { className: "text-muted-foreground text-sm", children: d === 0 ? "0 of 0" : `${s}-${w} of ${d}` }),
478
- /* @__PURE__ */ e(
479
- Ce,
507
+ g != null && /* @__PURE__ */ a("span", { className: "text-muted-foreground text-sm", children: g }),
508
+ /* @__PURE__ */ a(
509
+ _,
480
510
  {
481
- ariaLabel: r,
482
- className: "mx-0 w-auto justify-end",
483
- dataHook: `${a}-nav`,
484
- children: /* @__PURE__ */ e(we, { children: f.map((m, v) => m === "previous" ? /* @__PURE__ */ e($, { children: /* @__PURE__ */ e(
485
- xe,
486
- {
487
- disabled: !g,
488
- onClick: () => t.previousPage()
489
- }
490
- ) }, "previous") : m === "next" ? /* @__PURE__ */ e($, { children: /* @__PURE__ */ e(
491
- ke,
492
- {
493
- disabled: !C,
494
- onClick: () => t.nextPage()
495
- }
496
- ) }, "next") : m === "ellipsis" ? /* @__PURE__ */ e($, { children: /* @__PURE__ */ e(ve, {}) }, `ellipsis-${v}`) : /* @__PURE__ */ e($, { children: /* @__PURE__ */ e(
497
- Re,
498
- {
499
- isActive: m === u,
500
- page: m,
501
- onClick: () => t.setPageIndex(m - 1)
502
- }
503
- ) }, m)) })
511
+ ariaLabel: c,
512
+ dataHook: `${n}-nav`
504
513
  }
505
514
  )
506
515
  ]
507
516
  }
508
- );
517
+ ) });
509
518
  }
510
- Me.displayName = "DataTablePagination";
511
- function Ae({
512
- table: t,
513
- dataHook: a,
519
+ Fe.displayName = "DataTablePagination";
520
+ function Me({
521
+ table: e,
522
+ dataHook: n,
514
523
  trackingEl: l,
515
- trackingLabel: n
524
+ trackingLabel: t
516
525
  }) {
517
- return /* @__PURE__ */ e(
518
- H,
526
+ return /* @__PURE__ */ a(
527
+ V,
519
528
  {
520
529
  "aria-label": "Select all",
521
- checked: t.getIsAllPageRowsSelected() || t.getIsSomePageRowsSelected() && "indeterminate",
522
- dataHook: a || "select-all-checkbox",
530
+ checked: e.getIsAllPageRowsSelected() || e.getIsSomePageRowsSelected() && "indeterminate",
531
+ dataHook: n || "select-all-checkbox",
523
532
  trackingEl: l,
524
- trackingLabel: n,
525
- onCheckedChange: (o) => t.toggleAllPageRowsSelected(!!o)
533
+ trackingLabel: t,
534
+ onCheckedChange: (i) => e.toggleAllPageRowsSelected(!!i)
526
535
  }
527
536
  );
528
537
  }
529
- Ae.displayName = "DataTableSelectAllCheckbox";
530
- function Ee({
531
- row: t,
532
- dataHook: a,
538
+ Me.displayName = "DataTableSelectAllCheckbox";
539
+ function Ae({
540
+ row: e,
541
+ dataHook: n,
533
542
  trackingEl: l,
534
- trackingLabel: n
543
+ trackingLabel: t
535
544
  }) {
536
- return /* @__PURE__ */ e(
537
- H,
545
+ return /* @__PURE__ */ a(
546
+ V,
538
547
  {
539
548
  "aria-label": "Select row",
540
- checked: t.getIsSelected(),
541
- dataHook: a || `select-row-${t.id}`,
542
- disabled: !t.getCanSelect(),
549
+ checked: e.getIsSelected(),
550
+ dataHook: n || `select-row-${e.id}`,
551
+ disabled: !e.getCanSelect(),
543
552
  trackingEl: l,
544
- trackingLabel: n,
545
- onCheckedChange: (o) => t.toggleSelected(!!o)
553
+ trackingLabel: t,
554
+ onCheckedChange: (i) => e.toggleSelected(!!i)
555
+ }
556
+ );
557
+ }
558
+ Ae.displayName = "DataTableSelectRowCheckbox";
559
+ function He({
560
+ dataHook: e,
561
+ className: n,
562
+ children: l
563
+ }) {
564
+ return /* @__PURE__ */ a(
565
+ "div",
566
+ {
567
+ className: h(
568
+ "flex flex-col gap-3 py-4 sm:flex-row sm:items-center",
569
+ n
570
+ ),
571
+ "data-hook": e,
572
+ "data-slot": "data-table-toolbar",
573
+ children: l
574
+ }
575
+ );
576
+ }
577
+ He.displayName = "DataTableToolbar";
578
+ function Ve({
579
+ className: e,
580
+ children: n
581
+ }) {
582
+ return /* @__PURE__ */ a(
583
+ "div",
584
+ {
585
+ className: h(
586
+ "flex w-full min-w-0 items-center gap-2 sm:w-auto sm:flex-1",
587
+ e
588
+ ),
589
+ "data-slot": "data-table-toolbar-left",
590
+ children: n
591
+ }
592
+ );
593
+ }
594
+ Ve.displayName = "DataTableToolbarLeft";
595
+ function je({
596
+ className: e,
597
+ children: n
598
+ }) {
599
+ return /* @__PURE__ */ a(
600
+ "div",
601
+ {
602
+ className: h(
603
+ "flex w-full items-center justify-end gap-2 sm:w-auto",
604
+ e
605
+ ),
606
+ "data-slot": "data-table-toolbar-right",
607
+ children: n
546
608
  }
547
609
  );
548
610
  }
549
- Ee.displayName = "DataTableSelectRowCheckbox";
611
+ je.displayName = "DataTableToolbarRight";
550
612
  export {
551
613
  ye as DataTable,
552
614
  De as DataTableColumnHeader,
553
- Me as DataTablePagination,
554
- Ne as DataTableRowActions,
555
- Fe as DataTableSearch,
556
- Ae as DataTableSelectAllCheckbox,
557
- Ee as DataTableSelectRowCheckbox,
558
- $e as DataTableToolbar,
559
- ze as DataTableToolbarLeft,
560
- Ie as DataTableToolbarRight,
561
- Pe as VirtualizedDataTable,
562
- Ye as createColumnHelper,
563
- Ze as flexRender,
615
+ Fe as DataTablePagination,
616
+ _ as DataTablePaginationNav,
617
+ $e as DataTablePaginationRowCount,
618
+ ze as DataTableSearch,
619
+ Me as DataTableSelectAllCheckbox,
620
+ Ae as DataTableSelectRowCheckbox,
621
+ He as DataTableToolbar,
622
+ Ve as DataTableToolbarLeft,
623
+ je as DataTableToolbarRight,
624
+ Ne as VirtualizedDataTable,
564
625
  Qe as useDataTable
565
626
  };