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