@ggem-farming/ui 0.0.0-stage → 0.0.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.
Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -2
  3. package/dist/accordion/accordion.d.ts +41 -0
  4. package/dist/accordion/accordion.js +89 -0
  5. package/dist/avatar/avatar.d.ts +20 -0
  6. package/dist/avatar/avatar.js +38 -0
  7. package/dist/badge/badge.d.ts +16 -0
  8. package/dist/badge/badge.js +85 -0
  9. package/dist/breadcrumbs/breadcrumbs.d.ts +19 -0
  10. package/dist/breadcrumbs/breadcrumbs.js +44 -0
  11. package/dist/button/button.d.ts +16 -0
  12. package/dist/button/button.js +49 -0
  13. package/dist/button/icon-button.d.ts +17 -0
  14. package/dist/button/icon-button.js +33 -0
  15. package/dist/card/card.d.ts +16 -0
  16. package/dist/card/card.js +56 -0
  17. package/dist/checkbox/checkbox.d.ts +15 -0
  18. package/dist/checkbox/checkbox.js +47 -0
  19. package/dist/combobox/combobox.d.ts +37 -0
  20. package/dist/combobox/combobox.js +155 -0
  21. package/dist/command/command-palette.d.ts +50 -0
  22. package/dist/command/command-palette.js +170 -0
  23. package/dist/command/kbd.d.ts +6 -0
  24. package/dist/command/kbd.js +16 -0
  25. package/dist/data/data-table.d.ts +105 -0
  26. package/dist/data/data-table.js +269 -0
  27. package/dist/data/export-button.d.ts +19 -0
  28. package/dist/data/export-button.js +34 -0
  29. package/dist/data/filter-bar.d.ts +54 -0
  30. package/dist/data/filter-bar.js +187 -0
  31. package/dist/data/pagination.d.ts +13 -0
  32. package/dist/data/pagination.js +84 -0
  33. package/dist/data/selection-bar.d.ts +21 -0
  34. package/dist/data/selection-bar.js +31 -0
  35. package/dist/date/date-input.d.ts +41 -0
  36. package/dist/date/date-input.js +71 -0
  37. package/dist/dialog/confirm-dialog.d.ts +24 -0
  38. package/dist/dialog/confirm-dialog.js +77 -0
  39. package/dist/dialog/dialog.d.ts +46 -0
  40. package/dist/dialog/dialog.js +102 -0
  41. package/dist/dialog/form-panel.d.ts +28 -0
  42. package/dist/dialog/form-panel.js +51 -0
  43. package/dist/feedback/alert.d.ts +29 -0
  44. package/dist/feedback/alert.js +70 -0
  45. package/dist/feedback/progress.d.ts +25 -0
  46. package/dist/feedback/progress.js +54 -0
  47. package/dist/feedback/toaster.d.ts +7 -0
  48. package/dist/feedback/toaster.js +35 -0
  49. package/dist/field/field.d.ts +40 -0
  50. package/dist/field/field.js +83 -0
  51. package/dist/field/text-field.d.ts +9 -0
  52. package/dist/field/text-field.js +16 -0
  53. package/dist/file-input/file-input.d.ts +26 -0
  54. package/dist/file-input/file-input.js +149 -0
  55. package/dist/fonts.css +3 -0
  56. package/dist/index.d.ts +43 -0
  57. package/dist/index.js +43 -0
  58. package/dist/input/input.d.ts +13 -0
  59. package/dist/input/input.js +25 -0
  60. package/dist/layout/app-shell.d.ts +100 -0
  61. package/dist/layout/app-shell.js +433 -0
  62. package/dist/layout/page.d.ts +20 -0
  63. package/dist/layout/page.js +53 -0
  64. package/dist/layout/record.d.ts +39 -0
  65. package/dist/layout/record.js +79 -0
  66. package/dist/lib/cn.d.ts +3 -0
  67. package/dist/lib/cn.js +18 -0
  68. package/dist/lib/control.js +14 -0
  69. package/dist/lib/popup.js +20 -0
  70. package/dist/menu/menu.d.ts +45 -0
  71. package/dist/menu/menu.js +85 -0
  72. package/dist/popover/popover.d.ts +22 -0
  73. package/dist/popover/popover.js +39 -0
  74. package/dist/radio/radio.d.ts +12 -0
  75. package/dist/radio/radio.js +25 -0
  76. package/dist/select/select.d.ts +23 -0
  77. package/dist/select/select.js +66 -0
  78. package/dist/separator/separator.d.ts +6 -0
  79. package/dist/separator/separator.js +14 -0
  80. package/dist/stat/stat.d.ts +28 -0
  81. package/dist/stat/stat.js +55 -0
  82. package/dist/state/states.d.ts +36 -0
  83. package/dist/state/states.js +108 -0
  84. package/dist/styles.css +42 -0
  85. package/dist/switch/switch.d.ts +9 -0
  86. package/dist/switch/switch.js +18 -0
  87. package/dist/table/table.d.ts +28 -0
  88. package/dist/table/table.js +72 -0
  89. package/dist/tabs/tabs.d.ts +26 -0
  90. package/dist/tabs/tabs.js +45 -0
  91. package/dist/tooltip/tooltip.d.ts +17 -0
  92. package/dist/tooltip/tooltip.js +27 -0
  93. package/package.json +57 -4
@@ -0,0 +1,269 @@
1
+ import { Checkbox } from "../checkbox/checkbox.js";
2
+ import { cn } from "../lib/cn.js";
3
+ import { EmptyState, ErrorState, Skeleton } from "../state/states.js";
4
+ import { Pagination } from "./pagination.js";
5
+ import { useMemo } from "react";
6
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ import { ArrowDown, ArrowUp, ChevronsUpDown } from "lucide-react";
8
+ import { columnVisibilityFeature, createColumnHelper, createPaginatedRowModel, createSortedRowModel, rowPaginationFeature, rowSelectionFeature, rowSortingFeature, sortFn_alphanumeric, sortFn_basic, sortFn_datetime, sortFn_text, tableFeatures, useTable } from "@tanstack/react-table";
9
+ // src/data/data-table.tsx
10
+ /** The table features the kit registers: sorting, pagination, row selection, column visibility. */
11
+ const dataTableFeatures = tableFeatures({
12
+ rowSortingFeature,
13
+ sortedRowModel: createSortedRowModel(),
14
+ sortFns: {
15
+ alphanumeric: sortFn_alphanumeric,
16
+ text: sortFn_text,
17
+ datetime: sortFn_datetime,
18
+ basic: sortFn_basic
19
+ },
20
+ rowPaginationFeature,
21
+ paginatedRowModel: createPaginatedRowModel(),
22
+ rowSelectionFeature,
23
+ columnVisibilityFeature
24
+ });
25
+ /**
26
+ * Typed column helper. Build the list with `col.columns([...])` so each column keeps its own value
27
+ * type; annotating the array as `DataTableColumn<T>[]` would widen cell values to `any`.
28
+ * ```ts
29
+ * const col = createDataTableColumnHelper<Farmer>();
30
+ * const columns = col.columns([col.accessor('name', { header: 'Farmer' })]);
31
+ * ```
32
+ */
33
+ function createDataTableColumnHelper() {
34
+ return createColumnHelper();
35
+ }
36
+ const INTERACTIVE = "a, button, input, select, textarea, label, [role=\"checkbox\"], [role=\"menuitem\"]";
37
+ const EMPTY = [];
38
+ function sortLabel(direction) {
39
+ if (direction === "asc") return "ascending";
40
+ if (direction === "desc") return "descending";
41
+ return "none";
42
+ }
43
+ /**
44
+ * A data table that fills the remaining height, with sorting, paging, selection, loading, error
45
+ * and empty states. Narrow containers (under 42rem) show cards instead of a table.
46
+ */
47
+ function DataTable({ "aria-label": label, columns, data, getRowId, getRowLabel, rowCount, sorting, onSortingChange, pagination, onPaginationChange, columnVisibility, onColumnVisibilityChange, enableRowSelection = false, rowSelection, onRowSelectionChange, pageSizes = [
48
+ 25,
49
+ 50,
50
+ 100
51
+ ], onRowClick, loading = false, fetching = false, error, onRetry, empty, className }) {
52
+ const server = rowCount !== void 0;
53
+ const [firstPageSize = 1e6] = pageSizes || [];
54
+ const allColumns = useMemo(() => {
55
+ if (!enableRowSelection) return [...columns];
56
+ return [{
57
+ id: "__select",
58
+ enableSorting: false,
59
+ enableHiding: false,
60
+ meta: { card: false },
61
+ header: ({ table }) => /* @__PURE__ */ jsx(Checkbox, {
62
+ "aria-label": "Select all rows on this page",
63
+ checked: table.getIsAllPageRowsSelected(),
64
+ indeterminate: table.getIsSomePageRowsSelected() && !table.getIsAllPageRowsSelected(),
65
+ onCheckedChange: (checked) => {
66
+ table.toggleAllPageRowsSelected(checked);
67
+ }
68
+ }),
69
+ cell: ({ row }) => /* @__PURE__ */ jsx(Checkbox, {
70
+ "aria-label": `Select ${getRowLabel ? getRowLabel(row.original) : `row ${String(row.index + 1)}`}`,
71
+ checked: row.getIsSelected(),
72
+ onCheckedChange: (_checked, details) => {
73
+ row.getToggleSelectedHandler()(details.event);
74
+ }
75
+ })
76
+ }, ...columns];
77
+ }, [
78
+ columns,
79
+ enableRowSelection,
80
+ getRowLabel
81
+ ]);
82
+ const state = {
83
+ ...sorting && { sorting },
84
+ ...pagination && { pagination },
85
+ ...columnVisibility && { columnVisibility },
86
+ ...rowSelection && { rowSelection }
87
+ };
88
+ const table = useTable({
89
+ features: dataTableFeatures,
90
+ columns: allColumns,
91
+ data: data ?? EMPTY,
92
+ getRowId,
93
+ manualSorting: server,
94
+ sortDescFirst: false,
95
+ manualPagination: server,
96
+ ...server && { rowCount },
97
+ enableRowSelection,
98
+ initialState: { pagination: {
99
+ pageIndex: 0,
100
+ pageSize: firstPageSize
101
+ } },
102
+ state,
103
+ ...onSortingChange && { onSortingChange },
104
+ ...onPaginationChange && { onPaginationChange },
105
+ ...onColumnVisibilityChange && { onColumnVisibilityChange },
106
+ ...onRowSelectionChange && { onRowSelectionChange }
107
+ });
108
+ const rows = table.getRowModel().rows;
109
+ const headers = table.getHeaderGroups();
110
+ const visibleColumns = table.getVisibleLeafColumns();
111
+ const total = server ? rowCount : table.getPrePaginatedRowModel().rows.length;
112
+ const page = table.state.pagination;
113
+ const showInitialLoading = loading && rows.length === 0;
114
+ const showBlockingError = error !== void 0 && error !== null && error !== false && rows.length === 0;
115
+ const showEmpty = !showInitialLoading && !showBlockingError && rows.length === 0;
116
+ const rowClick = (row) => onRowClick && ((event) => {
117
+ if (event.target.closest(INTERACTIVE)) return;
118
+ onRowClick(row);
119
+ });
120
+ const alignClass = (align) => align === "right" ? "text-right" : "text-left";
121
+ const priorityClass = (priority) => priority === "low" ? "hidden @5xl:table-cell" : "";
122
+ const titleColumnId = visibleColumns.find((c) => c.columnDef.meta?.card === "title")?.id ?? visibleColumns.find((c) => c.id !== "__select" && c.columnDef.meta?.card !== false)?.id;
123
+ return /* @__PURE__ */ jsxs("div", {
124
+ className: cn("@container relative flex min-h-0 flex-1 flex-col", className),
125
+ children: [
126
+ fetching && rows.length > 0 && /* @__PURE__ */ jsx("div", {
127
+ className: "absolute inset-x-0 top-0 z-(--z-header) h-0.5 overflow-hidden",
128
+ "aria-hidden": true,
129
+ children: /* @__PURE__ */ jsx("div", { className: "h-full w-1/3 animate-[ggem-progress_1.2s_ease-in-out_infinite] bg-brand motion-reduce:w-full motion-reduce:animate-none" })
130
+ }),
131
+ error !== void 0 && error !== null && error !== false && rows.length > 0 && /* @__PURE__ */ jsx(ErrorState, {
132
+ variant: "banner",
133
+ title: `Couldn't refresh ${label.toLowerCase()}`,
134
+ description: error,
135
+ onRetry,
136
+ className: "m-3"
137
+ }),
138
+ showBlockingError ? /* @__PURE__ */ jsx(ErrorState, {
139
+ title: `Couldn't load ${label.toLowerCase()}`,
140
+ description: error,
141
+ onRetry,
142
+ className: "flex-1"
143
+ }) : showInitialLoading ? /* @__PURE__ */ jsxs("div", {
144
+ role: "status",
145
+ "aria-busy": "true",
146
+ className: "flex flex-col gap-px border-t border-border",
147
+ children: [/* @__PURE__ */ jsxs("span", {
148
+ className: "sr-only",
149
+ children: [
150
+ "Loading ",
151
+ label.toLowerCase(),
152
+ "…"
153
+ ]
154
+ }), Array.from({ length: 8 }, (_, i) => /* @__PURE__ */ jsxs("div", {
155
+ className: "flex items-center gap-4 border-b border-border px-5 py-3",
156
+ children: [
157
+ /* @__PURE__ */ jsx(Skeleton, { className: "size-6 rounded-full" }),
158
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-40" }),
159
+ /* @__PURE__ */ jsx(Skeleton, { className: "ml-auto h-4 w-20" })
160
+ ]
161
+ }, i))]
162
+ }) : showEmpty ? /* @__PURE__ */ jsx("div", {
163
+ className: "flex flex-1 flex-col justify-center border-t border-border",
164
+ children: empty ?? /* @__PURE__ */ jsx(EmptyState, {
165
+ title: "No results",
166
+ description: "Try changing or clearing the filters."
167
+ })
168
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
169
+ className: "hidden min-h-0 flex-1 overflow-auto border-t border-border @2xl:block",
170
+ children: /* @__PURE__ */ jsxs("table", {
171
+ "aria-label": label,
172
+ "aria-busy": fetching || void 0,
173
+ className: "w-full text-sm whitespace-nowrap",
174
+ children: [/* @__PURE__ */ jsx("thead", {
175
+ className: "sticky top-0 z-(--z-sticky) bg-surface-muted text-xs text-fg-muted",
176
+ children: headers.map((group) => /* @__PURE__ */ jsx("tr", {
177
+ className: "border-b border-border",
178
+ children: group.headers.map((header, i) => {
179
+ const meta = header.column.columnDef.meta;
180
+ const canSort = header.column.getCanSort();
181
+ const direction = header.column.getIsSorted();
182
+ const Icon = direction === "asc" ? ArrowUp : direction === "desc" ? ArrowDown : ChevronsUpDown;
183
+ return /* @__PURE__ */ jsx("th", {
184
+ scope: "col",
185
+ "aria-sort": canSort ? sortLabel(direction) : void 0,
186
+ className: cn("h-9 px-3 font-medium", i === 0 && "pl-5", i === group.headers.length - 1 && "pr-5", header.column.id === "__select" && "w-10", alignClass(meta?.align), priorityClass(meta?.priority)),
187
+ children: header.isPlaceholder ? null : canSort ? /* @__PURE__ */ jsxs("button", {
188
+ type: "button",
189
+ onClick: header.column.getToggleSortingHandler(),
190
+ className: cn("group inline-flex items-center gap-1 rounded-sm hover:text-fg focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus", meta?.align === "right" && "flex-row-reverse", direction && "text-fg"),
191
+ children: [/* @__PURE__ */ jsx(table.FlexRender, { header }), /* @__PURE__ */ jsx(Icon, {
192
+ className: cn("size-3.5", !direction && "opacity-40 group-hover:opacity-100"),
193
+ "aria-hidden": true
194
+ })]
195
+ }) : /* @__PURE__ */ jsx(table.FlexRender, { header })
196
+ }, header.id);
197
+ })
198
+ }, group.id))
199
+ }), /* @__PURE__ */ jsx("tbody", { children: rows.map((row) => /* @__PURE__ */ jsx("tr", {
200
+ onClick: rowClick(row.original),
201
+ "data-selected": row.getIsSelected() || void 0,
202
+ className: cn("border-b border-border hover:bg-surface-muted data-selected:bg-brand-soft/40", onRowClick && "cursor-pointer"),
203
+ children: row.getVisibleCells().map((cell, i, cells) => {
204
+ const meta = cell.column.columnDef.meta;
205
+ return /* @__PURE__ */ jsx("td", {
206
+ className: cn("h-11 px-3", i === 0 && "pl-5", i === cells.length - 1 && "pr-5", alignClass(meta?.align), meta?.align === "right" && "tabular-nums", priorityClass(meta?.priority)),
207
+ children: /* @__PURE__ */ jsx(table.FlexRender, { cell })
208
+ }, cell.id);
209
+ })
210
+ }, row.id)) })]
211
+ })
212
+ }), /* @__PURE__ */ jsx("ul", {
213
+ "aria-label": label,
214
+ className: "divide-y divide-border border-t border-border @2xl:hidden",
215
+ children: rows.map((row) => {
216
+ const cells = row.getVisibleCells();
217
+ const select = cells.find((c) => c.column.id === "__select");
218
+ const title = cells.find((c) => c.column.id === titleColumnId);
219
+ const subtitles = cells.filter((c) => c.column.columnDef.meta?.card === "subtitle");
220
+ const trailing = cells.filter((c) => c.column.columnDef.meta?.card === "trailing");
221
+ return /* @__PURE__ */ jsxs("li", {
222
+ onClick: rowClick(row.original),
223
+ className: cn("flex items-center gap-3 px-3 py-3", onRowClick && "cursor-pointer"),
224
+ children: [
225
+ select && /* @__PURE__ */ jsx(table.FlexRender, { cell: select }),
226
+ /* @__PURE__ */ jsxs("div", {
227
+ className: "min-w-0 flex-1",
228
+ children: [title && /* @__PURE__ */ jsx("div", {
229
+ className: "truncate font-medium",
230
+ children: /* @__PURE__ */ jsx(table.FlexRender, { cell: title })
231
+ }), subtitles.length > 0 && /* @__PURE__ */ jsx("div", {
232
+ className: "mt-0.5 flex min-w-0 flex-wrap gap-x-1.5 text-sm text-fg-muted",
233
+ children: subtitles.map((cell, i) => /* @__PURE__ */ jsxs("span", {
234
+ className: "truncate",
235
+ children: [i > 0 && /* @__PURE__ */ jsx("span", {
236
+ "aria-hidden": true,
237
+ children: "· "
238
+ }), /* @__PURE__ */ jsx(table.FlexRender, { cell })]
239
+ }, cell.id))
240
+ })]
241
+ }),
242
+ trailing.map((cell) => /* @__PURE__ */ jsx("div", {
243
+ className: "shrink-0",
244
+ children: /* @__PURE__ */ jsx(table.FlexRender, { cell })
245
+ }, cell.id))
246
+ ]
247
+ }, row.id);
248
+ })
249
+ })] }),
250
+ pageSizes && total > 0 && !showBlockingError && /* @__PURE__ */ jsx(Pagination, {
251
+ className: "border-t border-border px-3 py-2 lg:px-5",
252
+ pageIndex: page.pageIndex,
253
+ pageSize: page.pageSize,
254
+ rowCount: total,
255
+ pageSizes,
256
+ onPageIndexChange: (pageIndex) => {
257
+ table.setPageIndex(pageIndex);
258
+ },
259
+ onPageSizeChange: (pageSize) => {
260
+ table.setPagination({
261
+ pageIndex: 0,
262
+ pageSize
263
+ });
264
+ }
265
+ })
266
+ ]
267
+ });
268
+ }
269
+ export { DataTable, createDataTableColumnHelper, dataTableFeatures };
@@ -0,0 +1,19 @@
1
+ import { ButtonProps } from "../button/button.js";
2
+ export interface ExportButtonProps extends Omit<ButtonProps, 'onClick' | 'children'> {
3
+ /**
4
+ * Runs the export. If it returns a promise the button stays busy until it settles. Report the
5
+ * outcome yourself (e.g. a toast); a rejection only ends the busy state.
6
+ */
7
+ onExport: () => unknown;
8
+ /** Busy state controlled by the app, e.g. a mutation's `isPending`. */
9
+ pending?: boolean;
10
+ /** Defaults to "Export CSV". */
11
+ label?: string;
12
+ /** Defaults to "Exporting…". */
13
+ pendingLabel?: string;
14
+ }
15
+ /**
16
+ * Exports a table's rows. Put it in the table's toolbar and disable it when nothing matches. On
17
+ * phones only the icon shows; the label stays available to screen readers.
18
+ */
19
+ export declare function ExportButton({ onExport, pending: pendingProp, label, pendingLabel, variant, size, disabled, ...props }: ExportButtonProps): import("react").JSX.Element;
@@ -0,0 +1,34 @@
1
+ import { Button } from "../button/button.js";
2
+ import { useState } from "react";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { Download } from "lucide-react";
5
+ // src/data/export-button.tsx
6
+ /**
7
+ * Exports a table's rows. Put it in the table's toolbar and disable it when nothing matches. On
8
+ * phones only the icon shows; the label stays available to screen readers.
9
+ */
10
+ function ExportButton({ onExport, pending: pendingProp, label = "Export CSV", pendingLabel = "Exporting…", variant = "secondary", size = "sm", disabled, ...props }) {
11
+ const [running, setRunning] = useState(false);
12
+ const pending = Boolean(pendingProp) || running;
13
+ const run = async () => {
14
+ setRunning(true);
15
+ try {
16
+ await onExport();
17
+ } catch {} finally {
18
+ setRunning(false);
19
+ }
20
+ };
21
+ return /* @__PURE__ */ jsxs(Button, {
22
+ variant,
23
+ size,
24
+ disabled: disabled || pending,
25
+ "aria-busy": pending || void 0,
26
+ onClick: () => void run(),
27
+ ...props,
28
+ children: [/* @__PURE__ */ jsx(Download, { "aria-hidden": true }), /* @__PURE__ */ jsx("span", {
29
+ className: "sr-only sm:not-sr-only",
30
+ children: pending ? pendingLabel : label
31
+ })]
32
+ });
33
+ }
34
+ export { ExportButton };
@@ -0,0 +1,54 @@
1
+ import { ReactNode } from "react";
2
+ export interface SearchInputProps {
3
+ /** Name for screen readers, e.g. "Search farmers". */
4
+ 'aria-label': string;
5
+ value: string;
6
+ /** Called after typing pauses (`debounceMs`), and at once when cleared. */
7
+ onValueChange: (value: string) => void;
8
+ placeholder?: string;
9
+ debounceMs?: number;
10
+ className?: string;
11
+ }
12
+ /** A search box that waits for typing to pause before searching, with a clear button. */
13
+ export declare function SearchInput({ 'aria-label': label, value, onValueChange, placeholder, debounceMs, className }: SearchInputProps): import("react").JSX.Element;
14
+ export interface FilterChipProps {
15
+ /** The filter name, e.g. "Hub". */
16
+ label: string;
17
+ /** The applied value in words, e.g. "Chikwawa, Nsanje". */
18
+ value: ReactNode;
19
+ onRemove: () => void;
20
+ }
21
+ /** One applied filter, removable. */
22
+ export declare function FilterChip({ label, value, onRemove }: FilterChipProps): import("react").JSX.Element;
23
+ export interface FilterBarProps {
24
+ /** Usually a SearchInput. */
25
+ search?: ReactNode;
26
+ /** Filter controls (Selects, Comboboxes). Inline when there is room, else in a side panel. */
27
+ filters?: ReactNode;
28
+ /** Number of applied filters, shown on the phone "Filters" button. */
29
+ activeCount?: number;
30
+ /** FilterChips for applied filters. */
31
+ chips?: ReactNode;
32
+ /** Clears every filter and the search. Shown when chips are present. */
33
+ onClearAll?: () => void;
34
+ /** Right-aligned tools, e.g. a ColumnsMenu or sort menu. */
35
+ actions?: ReactNode;
36
+ className?: string;
37
+ }
38
+ /**
39
+ * The toolbar above a table. Below 48rem of width, filters move into a side panel opened from a
40
+ * "Filters" button, so the table stays on the first screen.
41
+ */
42
+ export declare function FilterBar({ search, filters, activeCount, chips, onClearAll, actions, className }: FilterBarProps): import("react").JSX.Element;
43
+ export interface ColumnsMenuProps {
44
+ /** Columns that can be shown or hidden, with readable names. */
45
+ columns: readonly {
46
+ id: string;
47
+ label: string;
48
+ }[];
49
+ /** Column ID → visible. Only `false` hides. */
50
+ visibility: Readonly<Record<string, boolean>>;
51
+ onVisibilityChange: (next: Record<string, boolean>) => void;
52
+ }
53
+ /** "Columns" menu to show or hide table columns; pass the same state to DataTable. */
54
+ export declare function ColumnsMenu({ columns, visibility, onVisibilityChange }: ColumnsMenuProps): import("react").JSX.Element;
@@ -0,0 +1,187 @@
1
+ import { Button } from "../button/button.js";
2
+ import { Dialog as Dialog$1, DialogBody, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "../dialog/dialog.js";
3
+ import { cn } from "../lib/cn.js";
4
+ import { controlFrame } from "../lib/control.js";
5
+ import { inlineIconButton } from "../lib/popup.js";
6
+ import { Menu as Menu$1, MenuCheckboxItem, MenuContent, MenuGroup, MenuGroupLabel, MenuTrigger } from "../menu/menu.js";
7
+ import { useEffect, useRef, useState } from "react";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ import { Columns3, ListFilter, Search, X } from "lucide-react";
10
+ import { Dialog } from "@base-ui/react/dialog";
11
+ // src/data/filter-bar.tsx
12
+ /** A search box that waits for typing to pause before searching, with a clear button. */
13
+ function SearchInput({ "aria-label": label, value, onValueChange, placeholder, debounceMs = 300, className }) {
14
+ const [text, setText] = useState(value);
15
+ const [lastValue, setLastValue] = useState(value);
16
+ if (value !== lastValue) {
17
+ setLastValue(value);
18
+ setText(value);
19
+ }
20
+ const latest = useRef(onValueChange);
21
+ useEffect(() => {
22
+ latest.current = onValueChange;
23
+ });
24
+ useEffect(() => {
25
+ if (text === value) return void 0;
26
+ const timer = setTimeout(() => {
27
+ latest.current(text);
28
+ }, debounceMs);
29
+ return () => {
30
+ clearTimeout(timer);
31
+ };
32
+ }, [
33
+ text,
34
+ value,
35
+ debounceMs
36
+ ]);
37
+ return /* @__PURE__ */ jsxs("div", {
38
+ className: cn(controlFrame, "flex h-8 items-center gap-1.5 pr-1 pl-2.5 pointer-coarse:h-11", "focus-within:outline-2 focus-within:-outline-offset-1 focus-within:outline-focus", className),
39
+ children: [
40
+ /* @__PURE__ */ jsx(Search, {
41
+ className: "size-4 shrink-0 text-fg-muted",
42
+ "aria-hidden": true
43
+ }),
44
+ /* @__PURE__ */ jsx("input", {
45
+ type: "search",
46
+ "aria-label": label,
47
+ value: text,
48
+ placeholder,
49
+ onChange: (e) => {
50
+ setText(e.target.value);
51
+ },
52
+ onKeyDown: (e) => {
53
+ if (e.key === "Enter") onValueChange(text);
54
+ },
55
+ className: "h-full min-w-0 flex-1 bg-transparent outline-hidden placeholder:text-fg-muted [&::-webkit-search-cancel-button]:hidden"
56
+ }),
57
+ text && /* @__PURE__ */ jsx("button", {
58
+ type: "button",
59
+ "aria-label": "Clear search",
60
+ className: inlineIconButton,
61
+ onClick: () => {
62
+ setText("");
63
+ onValueChange("");
64
+ },
65
+ children: /* @__PURE__ */ jsx(X, {
66
+ className: "size-3.5",
67
+ "aria-hidden": true
68
+ })
69
+ })
70
+ ]
71
+ });
72
+ }
73
+ /** One applied filter, removable. */
74
+ function FilterChip({ label, value, onRemove }) {
75
+ return /* @__PURE__ */ jsxs("span", {
76
+ className: "inline-flex h-7 max-w-full items-center gap-1 rounded-md border border-border bg-surface-muted pr-0.5 pl-2 text-sm pointer-coarse:h-11",
77
+ children: [
78
+ /* @__PURE__ */ jsx("span", {
79
+ className: "text-fg-muted",
80
+ children: label
81
+ }),
82
+ /* @__PURE__ */ jsx("span", {
83
+ className: "min-w-0 truncate font-medium",
84
+ children: value
85
+ }),
86
+ /* @__PURE__ */ jsx("button", {
87
+ type: "button",
88
+ "aria-label": `Remove filter: ${label}`,
89
+ className: inlineIconButton,
90
+ onClick: onRemove,
91
+ children: /* @__PURE__ */ jsx(X, {
92
+ className: "size-3.5",
93
+ "aria-hidden": true
94
+ })
95
+ })
96
+ ]
97
+ });
98
+ }
99
+ /**
100
+ * The toolbar above a table. Below 48rem of width, filters move into a side panel opened from a
101
+ * "Filters" button, so the table stays on the first screen.
102
+ */
103
+ function FilterBar({ search, filters, activeCount = 0, chips, onClearAll, actions, className }) {
104
+ return /* @__PURE__ */ jsxs("div", {
105
+ className: cn("@container flex flex-col gap-2 px-3 py-2.5 lg:px-5", className),
106
+ children: [/* @__PURE__ */ jsxs("div", {
107
+ className: "flex flex-wrap items-center gap-2",
108
+ children: [
109
+ search && /* @__PURE__ */ jsx("div", {
110
+ className: "w-full @md:w-64",
111
+ children: search
112
+ }),
113
+ filters && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
114
+ className: "hidden flex-wrap items-center gap-2 @3xl:flex [&_[role=combobox]]:w-auto [&>div:has(>input[role=combobox])]:w-56 [&>button[role=combobox]]:min-w-36",
115
+ children: filters
116
+ }), /* @__PURE__ */ jsxs(Dialog$1, { children: [/* @__PURE__ */ jsxs(DialogContent, {
117
+ placement: "right",
118
+ size: "sm",
119
+ children: [
120
+ /* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: "Filters" }) }),
121
+ /* @__PURE__ */ jsx(DialogBody, {
122
+ className: "flex flex-col gap-4 [&_[role=combobox]]:w-full",
123
+ children: filters
124
+ }),
125
+ /* @__PURE__ */ jsxs(DialogFooter, { children: [onClearAll && /* @__PURE__ */ jsx(Button, {
126
+ variant: "secondary",
127
+ onClick: onClearAll,
128
+ children: "Clear all"
129
+ }), /* @__PURE__ */ jsx(DialogClose, { render: /* @__PURE__ */ jsx(Button, { children: "Show results" }) })] })
130
+ ]
131
+ }), /* @__PURE__ */ jsx(FilterButton, { count: activeCount })] })] }),
132
+ actions && /* @__PURE__ */ jsx("div", {
133
+ className: "ml-auto flex items-center gap-1",
134
+ children: actions
135
+ })
136
+ ]
137
+ }), chips && /* @__PURE__ */ jsxs("div", {
138
+ className: "flex flex-wrap items-center gap-2",
139
+ children: [chips, onClearAll && /* @__PURE__ */ jsx(Button, {
140
+ variant: "ghost",
141
+ size: "sm",
142
+ onClick: onClearAll,
143
+ children: "Clear all"
144
+ })]
145
+ })]
146
+ });
147
+ }
148
+ function FilterButton({ count }) {
149
+ return /* @__PURE__ */ jsxs(DialogTriggerButton, { children: [
150
+ /* @__PURE__ */ jsx(ListFilter, {}),
151
+ " Filters",
152
+ count > 0 && /* @__PURE__ */ jsx("span", {
153
+ className: "rounded-full bg-primary px-1.5 text-xs font-semibold text-on-primary tabular-nums",
154
+ children: count
155
+ })
156
+ ] });
157
+ }
158
+ function DialogTriggerButton({ children }) {
159
+ return /* @__PURE__ */ jsx(Dialog.Trigger, { render: /* @__PURE__ */ jsx(Button, {
160
+ variant: "secondary",
161
+ size: "sm",
162
+ className: "@3xl:hidden",
163
+ children
164
+ }) });
165
+ }
166
+ /** "Columns" menu to show or hide table columns; pass the same state to DataTable. */
167
+ function ColumnsMenu({ columns, visibility, onVisibilityChange }) {
168
+ return /* @__PURE__ */ jsxs(Menu$1, { children: [/* @__PURE__ */ jsx(MenuTrigger, { render: /* @__PURE__ */ jsxs(Button, {
169
+ variant: "ghost",
170
+ size: "sm",
171
+ children: [/* @__PURE__ */ jsx(Columns3, {}), " Columns"]
172
+ }) }), /* @__PURE__ */ jsx(MenuContent, {
173
+ align: "end",
174
+ children: /* @__PURE__ */ jsxs(MenuGroup, { children: [/* @__PURE__ */ jsx(MenuGroupLabel, { children: "Visible columns" }), columns.map((column) => /* @__PURE__ */ jsx(MenuCheckboxItem, {
175
+ checked: visibility[column.id] !== false,
176
+ closeOnClick: false,
177
+ onCheckedChange: (checked) => {
178
+ onVisibilityChange({
179
+ ...visibility,
180
+ [column.id]: checked
181
+ });
182
+ },
183
+ children: column.label
184
+ }, column.id))] })
185
+ })] });
186
+ }
187
+ export { ColumnsMenu, FilterBar, FilterChip, SearchInput };
@@ -0,0 +1,13 @@
1
+ export interface PaginationProps {
2
+ /** Zero-based page index. */
3
+ pageIndex: number;
4
+ pageSize: number;
5
+ /** Total rows across all pages (from the server when paging there). */
6
+ rowCount: number;
7
+ onPageIndexChange: (pageIndex: number) => void;
8
+ onPageSizeChange: (pageSize: number) => void;
9
+ pageSizes?: readonly number[];
10
+ className?: string;
11
+ }
12
+ /** "Showing 1–25 of 3,527", rows per page, previous and next. */
13
+ export declare function Pagination({ pageIndex, pageSize, rowCount, onPageIndexChange, onPageSizeChange, pageSizes, className }: PaginationProps): import("react").JSX.Element;
@@ -0,0 +1,84 @@
1
+ import { IconButton } from "../button/icon-button.js";
2
+ import { cn } from "../lib/cn.js";
3
+ import { Select } from "../select/select.js";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ import { ChevronLeft, ChevronRight } from "lucide-react";
6
+ // src/data/pagination.tsx
7
+ const count = (n) => n.toLocaleString("en-GB");
8
+ /** "Showing 1–25 of 3,527", rows per page, previous and next. */
9
+ function Pagination({ pageIndex, pageSize, rowCount, onPageIndexChange, onPageSizeChange, pageSizes = [
10
+ 25,
11
+ 50,
12
+ 100
13
+ ], className }) {
14
+ const pageCount = Math.max(1, Math.ceil(rowCount / pageSize));
15
+ const first = rowCount === 0 ? 0 : pageIndex * pageSize + 1;
16
+ const last = Math.min(rowCount, (pageIndex + 1) * pageSize);
17
+ return /* @__PURE__ */ jsxs("nav", {
18
+ "aria-label": "Pagination",
19
+ className: cn("flex flex-wrap items-center justify-between gap-2 text-sm text-fg-muted", className),
20
+ children: [/* @__PURE__ */ jsxs("p", {
21
+ role: "status",
22
+ children: [
23
+ "Showing",
24
+ " ",
25
+ /* @__PURE__ */ jsxs("span", {
26
+ className: "text-fg tabular-nums",
27
+ children: [
28
+ count(first),
29
+ "–",
30
+ count(last)
31
+ ]
32
+ }),
33
+ " ",
34
+ "of ",
35
+ /* @__PURE__ */ jsx("span", {
36
+ className: "text-fg tabular-nums",
37
+ children: count(rowCount)
38
+ })
39
+ ]
40
+ }), /* @__PURE__ */ jsxs("div", {
41
+ className: "flex items-center gap-2",
42
+ children: [
43
+ /* @__PURE__ */ jsx("span", {
44
+ className: "hidden sm:inline",
45
+ "aria-hidden": true,
46
+ children: "Rows per page"
47
+ }),
48
+ /* @__PURE__ */ jsx(Select, {
49
+ "aria-label": "Rows per page",
50
+ options: pageSizes.map((size) => ({
51
+ value: size,
52
+ label: String(size)
53
+ })),
54
+ value: pageSize,
55
+ onValueChange: (size) => {
56
+ if (size !== null) onPageSizeChange(size);
57
+ },
58
+ className: "h-7 w-20"
59
+ }),
60
+ /* @__PURE__ */ jsx(IconButton, {
61
+ label: "Previous page",
62
+ variant: "secondary",
63
+ size: "sm",
64
+ disabled: pageIndex <= 0,
65
+ onClick: () => {
66
+ onPageIndexChange(pageIndex - 1);
67
+ },
68
+ children: /* @__PURE__ */ jsx(ChevronLeft, {})
69
+ }),
70
+ /* @__PURE__ */ jsx(IconButton, {
71
+ label: "Next page",
72
+ variant: "secondary",
73
+ size: "sm",
74
+ disabled: pageIndex >= pageCount - 1,
75
+ onClick: () => {
76
+ onPageIndexChange(pageIndex + 1);
77
+ },
78
+ children: /* @__PURE__ */ jsx(ChevronRight, {})
79
+ })
80
+ ]
81
+ })]
82
+ });
83
+ }
84
+ export { Pagination };