@underpin/ui 0.0.0 → 2.1.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.
- package/LICENSE +21 -0
- package/README.md +44 -1
- package/components/autocomplete.d.ts +25 -0
- package/components/autocomplete.js +71 -0
- package/components/autocomplete.js.map +1 -0
- package/components/avatar.d.ts +5 -0
- package/components/avatar.js +26 -0
- package/components/avatar.js.map +1 -0
- package/components/badge.d.ts +36 -0
- package/components/badge.js +140 -0
- package/components/badge.js.map +1 -0
- package/components/bar-list.d.ts +133 -0
- package/components/bar-list.js +204 -0
- package/components/bar-list.js.map +1 -0
- package/components/breakdown-card.d.ts +30 -0
- package/components/breakdown-card.js +43 -0
- package/components/breakdown-card.js.map +1 -0
- package/components/bulk-action-bar.d.ts +21 -0
- package/components/bulk-action-bar.js +38 -0
- package/components/bulk-action-bar.js.map +1 -0
- package/components/button-group.d.ts +21 -0
- package/components/button-group.js +32 -0
- package/components/button-group.js.map +1 -0
- package/components/button.d.ts +39 -0
- package/components/button.js +145 -0
- package/components/button.js.map +1 -0
- package/components/calendar.d.ts +27 -0
- package/components/calendar.js +95 -0
- package/components/calendar.js.map +1 -0
- package/components/callout.d.ts +26 -0
- package/components/callout.js +71 -0
- package/components/callout.js.map +1 -0
- package/components/card.d.ts +55 -0
- package/components/card.js +96 -0
- package/components/card.js.map +1 -0
- package/components/chart.d.ts +32 -0
- package/components/chart.js +43 -0
- package/components/chart.js.map +1 -0
- package/components/checkbox.d.ts +15 -0
- package/components/checkbox.js +42 -0
- package/components/checkbox.js.map +1 -0
- package/components/code-block.d.ts +21 -0
- package/components/code-block.js +35 -0
- package/components/code-block.js.map +1 -0
- package/components/collapse.d.ts +14 -0
- package/components/collapse.js +25 -0
- package/components/collapse.js.map +1 -0
- package/components/combobox.d.ts +71 -0
- package/components/combobox.js +155 -0
- package/components/combobox.js.map +1 -0
- package/components/copy-button.d.ts +29 -0
- package/components/copy-button.js +100 -0
- package/components/copy-button.js.map +1 -0
- package/components/copy-input.d.ts +15 -0
- package/components/copy-input.js +51 -0
- package/components/copy-input.js.map +1 -0
- package/components/data-table.d.ts +120 -0
- package/components/data-table.js +336 -0
- package/components/data-table.js.map +1 -0
- package/components/date-picker-trigger.d.ts +12 -0
- package/components/date-picker-trigger.js +30 -0
- package/components/date-picker-trigger.js.map +1 -0
- package/components/date-picker.d.ts +36 -0
- package/components/date-picker.js +70 -0
- package/components/date-picker.js.map +1 -0
- package/components/detail-row.d.ts +51 -0
- package/components/detail-row.js +77 -0
- package/components/detail-row.js.map +1 -0
- package/components/dialog.d.ts +121 -0
- package/components/dialog.js +327 -0
- package/components/dialog.js.map +1 -0
- package/components/disabled-reason.d.ts +31 -0
- package/components/disabled-reason.js +67 -0
- package/components/disabled-reason.js.map +1 -0
- package/components/empty-state.d.ts +41 -0
- package/components/empty-state.js +84 -0
- package/components/empty-state.js.map +1 -0
- package/components/entity-avatar.d.ts +54 -0
- package/components/entity-avatar.js +68 -0
- package/components/entity-avatar.js.map +1 -0
- package/components/form-section.d.ts +22 -0
- package/components/form-section.js +38 -0
- package/components/form-section.js.map +1 -0
- package/components/form.d.ts +199 -0
- package/components/form.js +456 -0
- package/components/form.js.map +1 -0
- package/components/formatted-number.d.ts +21 -0
- package/components/formatted-number.js +13 -0
- package/components/formatted-number.js.map +1 -0
- package/components/heading.d.ts +23 -0
- package/components/heading.js +44 -0
- package/components/heading.js.map +1 -0
- package/components/icon-swap.d.ts +15 -0
- package/components/icon-swap.js +29 -0
- package/components/icon-swap.js.map +1 -0
- package/components/inline-action.d.ts +21 -0
- package/components/inline-action.js +36 -0
- package/components/inline-action.js.map +1 -0
- package/components/input.d.ts +51 -0
- package/components/input.js +52 -0
- package/components/input.js.map +1 -0
- package/components/kbd.d.ts +17 -0
- package/components/kbd.js +34 -0
- package/components/kbd.js.map +1 -0
- package/components/label.d.ts +10 -0
- package/components/label.js +20 -0
- package/components/label.js.map +1 -0
- package/components/menu.d.ts +77 -0
- package/components/menu.js +189 -0
- package/components/menu.js.map +1 -0
- package/components/nav-button.d.ts +34 -0
- package/components/nav-button.js +71 -0
- package/components/nav-button.js.map +1 -0
- package/components/nav.d.ts +39 -0
- package/components/nav.js +68 -0
- package/components/nav.js.map +1 -0
- package/components/number-input.d.ts +16 -0
- package/components/number-input.js +25 -0
- package/components/number-input.js.map +1 -0
- package/components/page.d.ts +14 -0
- package/components/page.js +23 -0
- package/components/page.js.map +1 -0
- package/components/pagination.d.ts +73 -0
- package/components/pagination.js +212 -0
- package/components/pagination.js.map +1 -0
- package/components/ping.d.ts +38 -0
- package/components/ping.js +50 -0
- package/components/ping.js.map +1 -0
- package/components/popover.d.ts +5 -0
- package/components/popover.js +25 -0
- package/components/popover.js.map +1 -0
- package/components/radio-group.d.ts +35 -0
- package/components/radio-group.js +81 -0
- package/components/radio-group.js.map +1 -0
- package/components/relative-time.d.ts +25 -0
- package/components/relative-time.js +51 -0
- package/components/relative-time.js.map +1 -0
- package/components/saved-mark.d.ts +15 -0
- package/components/saved-mark.js +45 -0
- package/components/saved-mark.js.map +1 -0
- package/components/search-input.d.ts +13 -0
- package/components/search-input.js +44 -0
- package/components/search-input.js.map +1 -0
- package/components/section-header.d.ts +83 -0
- package/components/section-header.js +170 -0
- package/components/section-header.js.map +1 -0
- package/components/segmented-control.d.ts +24 -0
- package/components/segmented-control.js +70 -0
- package/components/segmented-control.js.map +1 -0
- package/components/select.d.ts +28 -0
- package/components/select.js +129 -0
- package/components/select.js.map +1 -0
- package/components/shortcut-keys.d.ts +14 -0
- package/components/shortcut-keys.js +32 -0
- package/components/shortcut-keys.js.map +1 -0
- package/components/shortcuts-dialog.d.ts +10 -0
- package/components/shortcuts-dialog.js +92 -0
- package/components/shortcuts-dialog.js.map +1 -0
- package/components/skeleton.d.ts +8 -0
- package/components/skeleton.js +23 -0
- package/components/skeleton.js.map +1 -0
- package/components/sparkline.d.ts +25 -0
- package/components/sparkline.js +70 -0
- package/components/sparkline.js.map +1 -0
- package/components/stack.d.ts +21 -0
- package/components/stack.js +45 -0
- package/components/stack.js.map +1 -0
- package/components/stat-strip.d.ts +43 -0
- package/components/stat-strip.js +151 -0
- package/components/stat-strip.js.map +1 -0
- package/components/steps.d.ts +19 -0
- package/components/steps.js +25 -0
- package/components/steps.js.map +1 -0
- package/components/switch.d.ts +16 -0
- package/components/switch.js +29 -0
- package/components/switch.js.map +1 -0
- package/components/table-toolbar.d.ts +55 -0
- package/components/table-toolbar.js +119 -0
- package/components/table-toolbar.js.map +1 -0
- package/components/table.d.ts +276 -0
- package/components/table.js +572 -0
- package/components/table.js.map +1 -0
- package/components/tabs.d.ts +36 -0
- package/components/tabs.js +120 -0
- package/components/tabs.js.map +1 -0
- package/components/text-link.d.ts +16 -0
- package/components/text-link.js +32 -0
- package/components/text-link.js.map +1 -0
- package/components/textarea.d.ts +10 -0
- package/components/textarea.js +23 -0
- package/components/textarea.js.map +1 -0
- package/components/theme.d.ts +28 -0
- package/components/theme.js +158 -0
- package/components/theme.js.map +1 -0
- package/components/time-series-chart.d.ts +122 -0
- package/components/time-series-chart.js +722 -0
- package/components/time-series-chart.js.map +1 -0
- package/components/toaster.d.ts +3 -0
- package/components/toaster.js +44 -0
- package/components/toaster.js.map +1 -0
- package/components/tooltip.d.ts +64 -0
- package/components/tooltip.js +126 -0
- package/components/tooltip.js.map +1 -0
- package/components/view-picker.d.ts +20 -0
- package/components/view-picker.js +24 -0
- package/components/view-picker.js.map +1 -0
- package/fonts/inter-OFL.txt +93 -0
- package/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/fonts/inter-cyrillic.woff2 +0 -0
- package/fonts/inter-greek-ext.woff2 +0 -0
- package/fonts/inter-greek.woff2 +0 -0
- package/fonts/inter-latin-ext.woff2 +0 -0
- package/fonts/inter-latin.woff2 +0 -0
- package/fonts/inter-vietnamese.woff2 +0 -0
- package/fonts.css +83 -0
- package/lib/animation.d.ts +14 -0
- package/lib/animation.js +20 -0
- package/lib/animation.js.map +1 -0
- package/lib/aria.d.ts +5 -0
- package/lib/aria.js +12 -0
- package/lib/aria.js.map +1 -0
- package/lib/chart-curve.d.ts +13 -0
- package/lib/chart-curve.js +79 -0
- package/lib/chart-curve.js.map +1 -0
- package/lib/classes.d.ts +134 -0
- package/lib/classes.js +152 -0
- package/lib/classes.js.map +1 -0
- package/lib/color.d.ts +25 -0
- package/lib/color.js +149 -0
- package/lib/color.js.map +1 -0
- package/lib/data-table-state.d.ts +87 -0
- package/lib/data-table-state.js +92 -0
- package/lib/data-table-state.js.map +1 -0
- package/lib/day.d.ts +9 -0
- package/lib/day.js +20 -0
- package/lib/day.js.map +1 -0
- package/lib/design-tokens.d.ts +56 -0
- package/lib/design-tokens.js +196 -0
- package/lib/design-tokens.js.map +1 -0
- package/lib/icon.d.ts +17 -0
- package/lib/icon.js +34 -0
- package/lib/icon.js.map +1 -0
- package/lib/icons.d.ts +29 -0
- package/lib/icons.js +34 -0
- package/lib/icons.js.map +1 -0
- package/lib/interactive.d.ts +21 -0
- package/lib/interactive.js +31 -0
- package/lib/interactive.js.map +1 -0
- package/lib/load-more.d.ts +14 -0
- package/lib/load-more.js +27 -0
- package/lib/load-more.js.map +1 -0
- package/lib/media.d.ts +58 -0
- package/lib/media.js +116 -0
- package/lib/media.js.map +1 -0
- package/lib/segmented.d.ts +57 -0
- package/lib/segmented.js +83 -0
- package/lib/segmented.js.map +1 -0
- package/lib/shortcuts.d.ts +94 -0
- package/lib/shortcuts.js +271 -0
- package/lib/shortcuts.js.map +1 -0
- package/lib/slot.d.ts +9 -0
- package/lib/slot.js +18 -0
- package/lib/slot.js.map +1 -0
- package/lib/time-series.d.ts +100 -0
- package/lib/time-series.js +144 -0
- package/lib/time-series.js.map +1 -0
- package/lib/tone.d.ts +6 -0
- package/lib/tone.js +0 -0
- package/lib/variants.d.ts +12 -0
- package/lib/variants.js +14 -0
- package/lib/variants.js.map +1 -0
- package/package.json +122 -3
- package/styles.css +630 -0
- package/tokens.d.ts +104 -0
- package/tokens.js +108 -0
- package/tokens.js.map +1 -0
- package/publish.log +0 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { DataTableFeatures, DataTableState } from "../lib/data-table-state.js";
|
|
2
|
+
import { PaginationLabels } from "./pagination.js";
|
|
3
|
+
import { TableProps, TableRowProps } from "./table.js";
|
|
4
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
5
|
+
import { ReactNode } from "react";
|
|
6
|
+
import { RowData, TableOptions } from "@tanstack/react-table";
|
|
7
|
+
/** The words of a `DataTable`, each a prop with an English default. */
|
|
8
|
+
export interface DataTableLabels {
|
|
9
|
+
selectAll: string;
|
|
10
|
+
/** The checkbox of one row, named by `getRowLabel`. */
|
|
11
|
+
selectRow: (name: string) => string;
|
|
12
|
+
/** The column picker's button. */
|
|
13
|
+
columns: string;
|
|
14
|
+
/** The count of an infinite table's band, from the formatted number of loaded rows. */
|
|
15
|
+
rowCount: (count: string) => ReactNode;
|
|
16
|
+
/** The bulk action bar's count, from the formatted number of selected rows. */
|
|
17
|
+
selected: (count: string) => ReactNode;
|
|
18
|
+
/** Names the bulk action bar for a screen reader. */
|
|
19
|
+
selection: string;
|
|
20
|
+
clearSelection: string;
|
|
21
|
+
loadingMore: ReactNode;
|
|
22
|
+
endOfList: ReactNode;
|
|
23
|
+
/** The paged band's words. */
|
|
24
|
+
pagination?: Partial<PaginationLabels>;
|
|
25
|
+
}
|
|
26
|
+
/** The footer of a table whose rows come a page at a time. Page and page size live in `state`. */
|
|
27
|
+
interface DataTablePages {
|
|
28
|
+
type: "pages";
|
|
29
|
+
/** Every row the query matches, across all pages. */
|
|
30
|
+
total: number;
|
|
31
|
+
/** The page sizes the reader picks from. Left out, the band has no per-page select. */
|
|
32
|
+
perPageOptions?: number[];
|
|
33
|
+
}
|
|
34
|
+
/** The footer of a table that loads the next batch as its end scrolls into view. */
|
|
35
|
+
interface DataTableInfinite {
|
|
36
|
+
type: "infinite";
|
|
37
|
+
hasMore: boolean;
|
|
38
|
+
isLoadingMore: boolean;
|
|
39
|
+
/** Asks for the next batch. Pass a stable callback. */
|
|
40
|
+
onLoadMore: () => void;
|
|
41
|
+
/** False after a failed batch, so the band does not ask for it again at once. */
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
/** The count at the start of the band. Left out, it is the number of loaded rows. */
|
|
44
|
+
count?: ReactNode;
|
|
45
|
+
}
|
|
46
|
+
export type DataTablePagination = DataTablePages | DataTableInfinite;
|
|
47
|
+
export interface DataTableChangeOptions {
|
|
48
|
+
/**
|
|
49
|
+
* True when the table corrects the state itself (a page past the end), so a router adapter
|
|
50
|
+
* replaces the history entry rather than adding one the reader would land back on.
|
|
51
|
+
*/
|
|
52
|
+
replace: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** What the toolbar render prop receives. */
|
|
55
|
+
export interface DataTableToolbarContext {
|
|
56
|
+
state: DataTableState;
|
|
57
|
+
/** Changes part of the state under the paging rules: a new search or filter goes to page 1. */
|
|
58
|
+
setState: (change: Partial<DataTableState>) => void;
|
|
59
|
+
/** A menu that shows and hides the columns that allow it, for the toolbar's `end`. */
|
|
60
|
+
columnPicker: ReactNode;
|
|
61
|
+
}
|
|
62
|
+
export interface DataTableProps<TData extends RowData> extends Pick<TableProps, "variant" | "layout" | "className" | "containerClassName"> {
|
|
63
|
+
/** Built with `createDataTableColumnHelper`. Keep the array stable between renders. */
|
|
64
|
+
columns: TableOptions<DataTableFeatures, TData>["columns"];
|
|
65
|
+
/** The rows to show: this page's, or every batch loaded so far. Keep it stable too. */
|
|
66
|
+
data: TData[];
|
|
67
|
+
/** A stable id per row, which a selection is kept by. */
|
|
68
|
+
getRowId: (row: TData) => string;
|
|
69
|
+
/** Names a row for a screen reader: its checkbox reads "Select <name>". Defaults to its id. */
|
|
70
|
+
getRowLabel?: (row: TData) => string;
|
|
71
|
+
"aria-label": string;
|
|
72
|
+
state: DataTableState;
|
|
73
|
+
onStateChange: (state: DataTableState, options: DataTableChangeOptions) => void;
|
|
74
|
+
pagination?: DataTablePagination;
|
|
75
|
+
/**
|
|
76
|
+
* A request is in flight. With no rows yet the table shows skeleton rows; with rows, it keeps
|
|
77
|
+
* them and dims them until the new ones land.
|
|
78
|
+
*/
|
|
79
|
+
loading?: boolean;
|
|
80
|
+
/** Stands in for the rows when there are none: a `TableMessage` (empty, filtered, error). */
|
|
81
|
+
message?: ReactNode;
|
|
82
|
+
/** The row's link. A row with one opens from anywhere on it, through `DataTableRowLink`. */
|
|
83
|
+
getRowHref?: (row: TData) => string | undefined;
|
|
84
|
+
/** Renders the row link through a router's link component; it receives the `href`. */
|
|
85
|
+
renderRowLink?: useRender.ComponentProps<"a">["render"];
|
|
86
|
+
/** Fades a row whose record is archived or blocked, all but its menu and checkbox. */
|
|
87
|
+
isRowInactive?: (row: TData) => boolean;
|
|
88
|
+
/** Adds a checkbox column. A function disables the box of each row it returns false for. */
|
|
89
|
+
enableRowSelection?: boolean | ((row: TData) => boolean);
|
|
90
|
+
/** The bulk action bar's buttons for the selected rows, shown while any are selected. */
|
|
91
|
+
bulkActions?: (rows: TData[], clear: () => void) => ReactNode;
|
|
92
|
+
/** Saves the columns the reader hides, per table, in `localStorage`. */
|
|
93
|
+
storageKey?: string;
|
|
94
|
+
/** The row above the table: a `TableToolbar`. */
|
|
95
|
+
toolbar?: (context: DataTableToolbarContext) => ReactNode;
|
|
96
|
+
size?: TableRowProps["size"];
|
|
97
|
+
/** Formats each figure in the reader's locale. */
|
|
98
|
+
format?: (value: number) => string;
|
|
99
|
+
labels?: Partial<DataTableLabels>;
|
|
100
|
+
}
|
|
101
|
+
interface DataTableRowLinkProps {
|
|
102
|
+
className?: string;
|
|
103
|
+
children: ReactNode;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The record's name, inside a `DataTable` column's cell: a link over the whole row when the
|
|
107
|
+
* table has `getRowHref`, plain text when it has none or the row returns none.
|
|
108
|
+
*/
|
|
109
|
+
export declare function DataTableRowLink({ className, children }: DataTableRowLinkProps): import("react").JSX.Element;
|
|
110
|
+
/**
|
|
111
|
+
* A table drawn from react-table column definitions: the app writes columns, the wrapper draws
|
|
112
|
+
* the head, the rows, the footer band, the checkbox column and the bulk action bar. Its state
|
|
113
|
+
* (page, page size, sort, search, filters) is controlled and never read from the URL, so each
|
|
114
|
+
* app keeps it in its own router. The server sorts, filters and pages: `data` is the rows to
|
|
115
|
+
* show, in order. Paging follows one set of rules: the page is 1-based, a page past the end
|
|
116
|
+
* shows the last one, a change of sort, search, filter or page size goes back to page 1, and
|
|
117
|
+
* the old rows stay dimmed while the next ones load.
|
|
118
|
+
*/
|
|
119
|
+
export declare function DataTable<TData extends RowData>({ columns, data, getRowId, getRowLabel, "aria-label": ariaLabel, state, onStateChange, pagination, loading, message, getRowHref, renderRowLink, isRowInactive, enableRowSelection, bulkActions, storageKey, toolbar, size, format, labels: labelsProp, variant, layout, className, containerClassName }: DataTableProps<TData>): import("react").JSX.Element;
|
|
120
|
+
export {};
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { DATA_TABLE_FEATURES, changeDataTableState, clampPage, formatRowSetKey, getPageCount, readColumnVisibility, writeColumnVisibility } from "../lib/data-table-state.js";
|
|
3
|
+
import { ChevronDownIcon } from "../lib/icons.js";
|
|
4
|
+
import { cn } from "../lib/variants.js";
|
|
5
|
+
import { BulkActionBar } from "./bulk-action-bar.js";
|
|
6
|
+
import { Button } from "./button.js";
|
|
7
|
+
import { Menu, MenuCheckboxItem, MenuContent, MenuTrigger } from "./menu.js";
|
|
8
|
+
import { Pagination, PaginationInfinite } from "./pagination.js";
|
|
9
|
+
import { Table, TableBody, TableCheckboxCell, TableColumnScope, TableHead, TableHeader, TableRow, TableRowLink, TableSkeletonRow } from "./table.js";
|
|
10
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { createContext, use, useEffect, useMemo, useRef, useState } from "react";
|
|
12
|
+
import { FlexRender, functionalUpdate, useTable } from "@tanstack/react-table";
|
|
13
|
+
// src/components/data-table.tsx
|
|
14
|
+
/** The id of the checkbox column a table with selection opens with. */
|
|
15
|
+
const SELECT_COLUMN_ID = "select";
|
|
16
|
+
/** Skeleton rows on a first load, and at the end of the list while the next batch loads. */
|
|
17
|
+
const FIRST_LOAD_ROWS = 5;
|
|
18
|
+
const MORE_ROWS = 3;
|
|
19
|
+
const DATA_TABLE_LABELS = {
|
|
20
|
+
selectAll: "Select all",
|
|
21
|
+
selectRow: (name) => `Select ${name}`,
|
|
22
|
+
columns: "Columns",
|
|
23
|
+
rowCount: (count) => `${count} rows`,
|
|
24
|
+
selected: (count) => `${count} selected`,
|
|
25
|
+
selection: "Selection",
|
|
26
|
+
clearSelection: "Clear selection",
|
|
27
|
+
loadingMore: "Loading more…",
|
|
28
|
+
endOfList: "End of list"
|
|
29
|
+
};
|
|
30
|
+
const SelectionContext = createContext({
|
|
31
|
+
labels: DATA_TABLE_LABELS,
|
|
32
|
+
setRange: () => {},
|
|
33
|
+
isRange: () => false
|
|
34
|
+
});
|
|
35
|
+
const RowLinkContext = createContext({});
|
|
36
|
+
/**
|
|
37
|
+
* The record's name, inside a `DataTable` column's cell: a link over the whole row when the
|
|
38
|
+
* table has `getRowHref`, plain text when it has none or the row returns none.
|
|
39
|
+
*/
|
|
40
|
+
function DataTableRowLink({ className, children }) {
|
|
41
|
+
const { href, render } = use(RowLinkContext);
|
|
42
|
+
if (!href) return /* @__PURE__ */ jsx("span", {
|
|
43
|
+
className: cn("truncate", className),
|
|
44
|
+
children
|
|
45
|
+
});
|
|
46
|
+
return /* @__PURE__ */ jsx(TableRowLink, {
|
|
47
|
+
href,
|
|
48
|
+
render,
|
|
49
|
+
className,
|
|
50
|
+
children
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function getMeta(column) {
|
|
54
|
+
return column.columnDef.meta ?? {};
|
|
55
|
+
}
|
|
56
|
+
/** The order a sortable column's head announces. */
|
|
57
|
+
function getSortOrder(sorted) {
|
|
58
|
+
if (!sorted) return "none";
|
|
59
|
+
return sorted === "asc" ? "ascending" : "descending";
|
|
60
|
+
}
|
|
61
|
+
/** The column's name in the picker: its `label`, or its header when that is a string. */
|
|
62
|
+
function formatColumnLabel(column) {
|
|
63
|
+
const { header } = column.columnDef;
|
|
64
|
+
return getMeta(column).label ?? (typeof header === "string" ? header : column.id);
|
|
65
|
+
}
|
|
66
|
+
function DataTableHead({ header }) {
|
|
67
|
+
const { column } = header;
|
|
68
|
+
const { align, priority, sortable } = getMeta(column);
|
|
69
|
+
const sorted = column.getIsSorted();
|
|
70
|
+
function onSort() {
|
|
71
|
+
column.toggleSorting(sorted ? sorted === "asc" : sortable === "descending");
|
|
72
|
+
}
|
|
73
|
+
if (column.id === SELECT_COLUMN_ID) return /* @__PURE__ */ jsx(FlexRender, { header });
|
|
74
|
+
return /* @__PURE__ */ jsx(TableHead, {
|
|
75
|
+
align,
|
|
76
|
+
priority,
|
|
77
|
+
sort: sortable ? getSortOrder(sorted) : void 0,
|
|
78
|
+
onSort: sortable ? onSort : void 0,
|
|
79
|
+
children: /* @__PURE__ */ jsx(FlexRender, { header })
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function SelectHead({ table }) {
|
|
83
|
+
const { labels } = use(SelectionContext);
|
|
84
|
+
return /* @__PURE__ */ jsx(TableCheckboxCell, {
|
|
85
|
+
header: true,
|
|
86
|
+
label: labels.selectAll,
|
|
87
|
+
checked: table.getIsAllPageRowsSelected(),
|
|
88
|
+
indeterminate: table.getIsSomePageRowsSelected(),
|
|
89
|
+
onCheckedChange: (checked) => table.toggleAllPageRowsSelected(checked)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function SelectCell({ row }) {
|
|
93
|
+
const { labels, getRowLabel, setRange, isRange } = use(SelectionContext);
|
|
94
|
+
return /* @__PURE__ */ jsx(TableCheckboxCell, {
|
|
95
|
+
label: labels.selectRow(getRowLabel?.(row.original) ?? row.id),
|
|
96
|
+
checked: row.getIsSelected(),
|
|
97
|
+
disabled: !row.getCanSelect(),
|
|
98
|
+
onClickCapture: (event) => setRange(event.shiftKey),
|
|
99
|
+
onKeyDownCapture: (event) => setRange(event.shiftKey),
|
|
100
|
+
onCheckedChange: (checked) => row.getToggleSelectedHandler()({
|
|
101
|
+
target: { checked },
|
|
102
|
+
shiftKey: isRange()
|
|
103
|
+
})
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function DataTableCell({ cell }) {
|
|
107
|
+
const { align, priority } = getMeta(cell.column);
|
|
108
|
+
return /* @__PURE__ */ jsx(TableColumnScope, {
|
|
109
|
+
align,
|
|
110
|
+
priority,
|
|
111
|
+
children: /* @__PURE__ */ jsx(FlexRender, { cell })
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function DataTableRow({ row, size, inactive, href, render }) {
|
|
115
|
+
const link = useMemo(() => ({
|
|
116
|
+
href,
|
|
117
|
+
render
|
|
118
|
+
}), [href, render]);
|
|
119
|
+
return /* @__PURE__ */ jsx(RowLinkContext, {
|
|
120
|
+
value: link,
|
|
121
|
+
children: /* @__PURE__ */ jsx(TableRow, {
|
|
122
|
+
size,
|
|
123
|
+
selected: row.getIsSelected(),
|
|
124
|
+
inactive,
|
|
125
|
+
children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx(DataTableCell, { cell }, cell.id))
|
|
126
|
+
})
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A table drawn from react-table column definitions: the app writes columns, the wrapper draws
|
|
131
|
+
* the head, the rows, the footer band, the checkbox column and the bulk action bar. Its state
|
|
132
|
+
* (page, page size, sort, search, filters) is controlled and never read from the URL, so each
|
|
133
|
+
* app keeps it in its own router. The server sorts, filters and pages: `data` is the rows to
|
|
134
|
+
* show, in order. Paging follows one set of rules: the page is 1-based, a page past the end
|
|
135
|
+
* shows the last one, a change of sort, search, filter or page size goes back to page 1, and
|
|
136
|
+
* the old rows stay dimmed while the next ones load.
|
|
137
|
+
*/
|
|
138
|
+
function DataTable({ columns, data, getRowId, getRowLabel, "aria-label": ariaLabel, state, onStateChange, pagination, loading = false, message, getRowHref, renderRowLink, isRowInactive, enableRowSelection, bulkActions, storageKey, toolbar, size = "default", format = String, labels: labelsProp, variant, layout, className, containerClassName }) {
|
|
139
|
+
const labels = {
|
|
140
|
+
...DATA_TABLE_LABELS,
|
|
141
|
+
...labelsProp
|
|
142
|
+
};
|
|
143
|
+
const tableRef = useRef(null);
|
|
144
|
+
const rangeRef = useRef(false);
|
|
145
|
+
const [rowSelection, setRowSelection] = useState({});
|
|
146
|
+
const [columnVisibility, setColumnVisibility] = useState({});
|
|
147
|
+
const rowSetKey = formatRowSetKey(state);
|
|
148
|
+
const [selectionKey, setSelectionKey] = useState(rowSetKey);
|
|
149
|
+
const selectable = Boolean(enableRowSelection);
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
if (storageKey) setColumnVisibility(readColumnVisibility(storageKey));
|
|
152
|
+
}, [storageKey]);
|
|
153
|
+
const sorting = state.sort ? [state.sort] : [];
|
|
154
|
+
function setState(change) {
|
|
155
|
+
onStateChange(changeDataTableState(state, change), { replace: false });
|
|
156
|
+
}
|
|
157
|
+
function onSortingChange(updater) {
|
|
158
|
+
const [sort] = functionalUpdate(updater, sorting);
|
|
159
|
+
setState({ sort });
|
|
160
|
+
}
|
|
161
|
+
function onColumnVisibilityChange(updater) {
|
|
162
|
+
const next = functionalUpdate(updater, columnVisibility);
|
|
163
|
+
setColumnVisibility(next);
|
|
164
|
+
if (storageKey) writeColumnVisibility(storageKey, next);
|
|
165
|
+
}
|
|
166
|
+
const allColumns = useMemo(() => {
|
|
167
|
+
if (!selectable) return columns;
|
|
168
|
+
return [{
|
|
169
|
+
id: SELECT_COLUMN_ID,
|
|
170
|
+
enableHiding: false,
|
|
171
|
+
enableSorting: false,
|
|
172
|
+
meta: {
|
|
173
|
+
width: "2.25rem",
|
|
174
|
+
skeleton: false
|
|
175
|
+
},
|
|
176
|
+
header: ({ table }) => /* @__PURE__ */ jsx(SelectHead, { table }),
|
|
177
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(SelectCell, { row })
|
|
178
|
+
}, ...columns];
|
|
179
|
+
}, [columns, selectable]);
|
|
180
|
+
const table = useTable({
|
|
181
|
+
features: DATA_TABLE_FEATURES,
|
|
182
|
+
columns: allColumns,
|
|
183
|
+
data,
|
|
184
|
+
getRowId,
|
|
185
|
+
state: {
|
|
186
|
+
sorting,
|
|
187
|
+
rowSelection,
|
|
188
|
+
columnVisibility
|
|
189
|
+
},
|
|
190
|
+
onSortingChange,
|
|
191
|
+
onRowSelectionChange: setRowSelection,
|
|
192
|
+
onColumnVisibilityChange,
|
|
193
|
+
manualSorting: true,
|
|
194
|
+
enableSortingRemoval: false,
|
|
195
|
+
enableMultiSort: false,
|
|
196
|
+
enableRowSelection: typeof enableRowSelection === "function" ? (row) => enableRowSelection(row.original) : selectable
|
|
197
|
+
});
|
|
198
|
+
if (selectionKey !== rowSetKey) {
|
|
199
|
+
setSelectionKey(rowSetKey);
|
|
200
|
+
table.resetRowSelection(true);
|
|
201
|
+
}
|
|
202
|
+
function clearSelection() {
|
|
203
|
+
table.resetRowSelection(true);
|
|
204
|
+
}
|
|
205
|
+
const selection = {
|
|
206
|
+
labels,
|
|
207
|
+
getRowLabel,
|
|
208
|
+
setRange: (range) => {
|
|
209
|
+
rangeRef.current = range;
|
|
210
|
+
},
|
|
211
|
+
isRange: () => rangeRef.current
|
|
212
|
+
};
|
|
213
|
+
const tableColumns = table.getVisibleLeafColumns().map((column) => {
|
|
214
|
+
const meta = getMeta(column);
|
|
215
|
+
return {
|
|
216
|
+
width: meta.width ?? "minmax(0,1fr)",
|
|
217
|
+
priority: meta.priority,
|
|
218
|
+
align: meta.align,
|
|
219
|
+
skeleton: meta.skeleton
|
|
220
|
+
};
|
|
221
|
+
});
|
|
222
|
+
const headers = table.getHeaderGroups().at(-1)?.headers ?? [];
|
|
223
|
+
const { rows } = table.getRowModel();
|
|
224
|
+
const selectedRows = table.getSelectedRowModel().rows.map((row) => row.original);
|
|
225
|
+
const paged = pagination?.type === "pages" ? pagination : void 0;
|
|
226
|
+
const infinite = pagination?.type === "infinite" ? pagination : void 0;
|
|
227
|
+
const perPage = state.perPage ?? 25;
|
|
228
|
+
const pageCount = paged ? getPageCount(paged.total, perPage) : 1;
|
|
229
|
+
const page = clampPage(state.page ?? 1, pageCount);
|
|
230
|
+
const pastEnd = paged !== void 0 && !loading && (state.page ?? 1) !== page;
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
if (pastEnd) onStateChange({
|
|
233
|
+
...state,
|
|
234
|
+
page
|
|
235
|
+
}, { replace: true });
|
|
236
|
+
}, [pastEnd, page]);
|
|
237
|
+
function onPageChange(next) {
|
|
238
|
+
setState({ page: next });
|
|
239
|
+
const element = tableRef.current;
|
|
240
|
+
if (element && element.getBoundingClientRect().top < 0) element.scrollIntoView({ block: "start" });
|
|
241
|
+
}
|
|
242
|
+
const hideable = table.getAllLeafColumns().filter((column) => column.getCanHide());
|
|
243
|
+
const columnPicker = hideable.length > 0 && /* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(MenuTrigger, {
|
|
244
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
245
|
+
variant: "secondary",
|
|
246
|
+
suffix: /* @__PURE__ */ jsx(ChevronDownIcon, {})
|
|
247
|
+
}),
|
|
248
|
+
children: labels.columns
|
|
249
|
+
}), /* @__PURE__ */ jsx(MenuContent, {
|
|
250
|
+
label: labels.columns,
|
|
251
|
+
align: "end",
|
|
252
|
+
children: hideable.map((column) => /* @__PURE__ */ jsx(MenuCheckboxItem, {
|
|
253
|
+
checked: column.getIsVisible(),
|
|
254
|
+
closeOnClick: false,
|
|
255
|
+
onCheckedChange: (checked) => column.toggleVisibility(checked),
|
|
256
|
+
children: formatColumnLabel(column)
|
|
257
|
+
}, column.id))
|
|
258
|
+
})] });
|
|
259
|
+
const firstLoad = loading && rows.length === 0;
|
|
260
|
+
const dimmed = loading && rows.length > 0;
|
|
261
|
+
const loadingMore = infinite?.isLoadingMore === true && rows.length > 0;
|
|
262
|
+
const footer = paged ? /* @__PURE__ */ jsx(Pagination, {
|
|
263
|
+
page,
|
|
264
|
+
pageCount,
|
|
265
|
+
total: paged.total,
|
|
266
|
+
perPage,
|
|
267
|
+
perPageOptions: paged.perPageOptions,
|
|
268
|
+
loading,
|
|
269
|
+
format,
|
|
270
|
+
labels: labels.pagination,
|
|
271
|
+
onPageChange,
|
|
272
|
+
onPerPageChange: (next) => setState({ perPage: next })
|
|
273
|
+
}) : infinite && rows.length > 0 ? /* @__PURE__ */ jsx(PaginationInfinite, {
|
|
274
|
+
count: infinite.count ?? labels.rowCount(format(rows.length)),
|
|
275
|
+
hasMore: infinite.hasMore,
|
|
276
|
+
loading: infinite.isLoadingMore,
|
|
277
|
+
enabled: infinite.enabled,
|
|
278
|
+
loadingLabel: labels.loadingMore,
|
|
279
|
+
endLabel: labels.endOfList,
|
|
280
|
+
onLoadMore: infinite.onLoadMore
|
|
281
|
+
}) : void 0;
|
|
282
|
+
const tableElement = /* @__PURE__ */ jsx(SelectionContext, {
|
|
283
|
+
value: selection,
|
|
284
|
+
children: /* @__PURE__ */ jsxs(Table, {
|
|
285
|
+
ref: tableRef,
|
|
286
|
+
"aria-label": ariaLabel,
|
|
287
|
+
"aria-busy": loading || loadingMore || void 0,
|
|
288
|
+
columns: tableColumns,
|
|
289
|
+
variant,
|
|
290
|
+
layout,
|
|
291
|
+
footer,
|
|
292
|
+
className,
|
|
293
|
+
containerClassName,
|
|
294
|
+
children: [/* @__PURE__ */ jsx(TableHeader, { children: headers.map((header) => /* @__PURE__ */ jsx(DataTableHead, { header }, header.id)) }), /* @__PURE__ */ jsxs(TableBody, {
|
|
295
|
+
className: cn("transition-opacity", dimmed && "opacity-50"),
|
|
296
|
+
children: [firstLoad ? Array.from({ length: FIRST_LOAD_ROWS }, (_, index) => /* @__PURE__ */ jsx(TableSkeletonRow, {
|
|
297
|
+
size,
|
|
298
|
+
index
|
|
299
|
+
}, index)) : rows.length === 0 ? message : rows.map((row) => /* @__PURE__ */ jsx(DataTableRow, {
|
|
300
|
+
row,
|
|
301
|
+
size,
|
|
302
|
+
inactive: isRowInactive?.(row.original),
|
|
303
|
+
href: getRowHref?.(row.original),
|
|
304
|
+
render: renderRowLink
|
|
305
|
+
}, row.id)), loadingMore && Array.from({ length: MORE_ROWS }, (_, index) => /* @__PURE__ */ jsx(TableSkeletonRow, {
|
|
306
|
+
size,
|
|
307
|
+
index: rows.length + index
|
|
308
|
+
}, index))]
|
|
309
|
+
})]
|
|
310
|
+
})
|
|
311
|
+
});
|
|
312
|
+
const bar = bulkActions && /* @__PURE__ */ jsx(BulkActionBar, {
|
|
313
|
+
count: selectedRows.length,
|
|
314
|
+
label: labels.selected(format(selectedRows.length)),
|
|
315
|
+
"aria-label": labels.selection,
|
|
316
|
+
clearLabel: labels.clearSelection,
|
|
317
|
+
onClear: clearSelection,
|
|
318
|
+
children: bulkActions(selectedRows, clearSelection)
|
|
319
|
+
});
|
|
320
|
+
if (!toolbar) return /* @__PURE__ */ jsxs(Fragment, { children: [tableElement, bar] });
|
|
321
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
322
|
+
className: "flex flex-col gap-3",
|
|
323
|
+
children: [
|
|
324
|
+
toolbar({
|
|
325
|
+
state,
|
|
326
|
+
setState,
|
|
327
|
+
columnPicker
|
|
328
|
+
}),
|
|
329
|
+
tableElement,
|
|
330
|
+
bar
|
|
331
|
+
]
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
export { DataTable, DataTableRowLink };
|
|
335
|
+
|
|
336
|
+
//# sourceMappingURL=data-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table.js","names":[],"sources":["../../src/components/data-table.tsx"],"sourcesContent":["\"use client\"\n\nimport type { useRender } from \"@base-ui/react/use-render\"\nimport {\n type Cell,\n type Column,\n type ColumnDef,\n type ColumnVisibilityState,\n FlexRender,\n functionalUpdate,\n type Header,\n type Row,\n type RowData,\n type RowSelectionState,\n type SortingState,\n type Table as ReactTable,\n type TableOptions,\n type Updater,\n useTable,\n} from \"@tanstack/react-table\"\nimport {\n createContext,\n type ReactNode,\n type MouseEvent as ReactMouseEvent,\n type KeyboardEvent as ReactKeyboardEvent,\n use,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\"\nimport {\n changeDataTableState,\n clampPage,\n DATA_TABLE_FEATURES,\n type DataTableFeatures,\n type DataTableState,\n DEFAULT_PER_PAGE,\n formatRowSetKey,\n getPageCount,\n readColumnVisibility,\n writeColumnVisibility,\n} from \"../lib/data-table-state\"\nimport { ChevronDownIcon } from \"../lib/icons\"\nimport { cn } from \"../lib/variants\"\nimport { BulkActionBar } from \"./bulk-action-bar\"\nimport { Button } from \"./button\"\nimport { Menu, MenuCheckboxItem, MenuContent, MenuTrigger } from \"./menu\"\nimport { Pagination, PaginationInfinite, type PaginationLabels } from \"./pagination\"\nimport {\n Table,\n TableBody,\n TableCheckboxCell,\n type TableColumn,\n TableColumnScope,\n TableHead,\n TableHeader,\n type TableProps,\n TableRow,\n type TableRowProps,\n TableRowLink,\n TableSkeletonRow,\n} from \"./table\"\n\n/** The id of the checkbox column a table with selection opens with. */\nconst SELECT_COLUMN_ID = \"select\"\n\n/** Skeleton rows on a first load, and at the end of the list while the next batch loads. */\nconst FIRST_LOAD_ROWS = 5\nconst MORE_ROWS = 3\n\n/** The words of a `DataTable`, each a prop with an English default. */\nexport interface DataTableLabels {\n selectAll: string\n /** The checkbox of one row, named by `getRowLabel`. */\n selectRow: (name: string) => string\n /** The column picker's button. */\n columns: string\n /** The count of an infinite table's band, from the formatted number of loaded rows. */\n rowCount: (count: string) => ReactNode\n /** The bulk action bar's count, from the formatted number of selected rows. */\n selected: (count: string) => ReactNode\n /** Names the bulk action bar for a screen reader. */\n selection: string\n clearSelection: string\n loadingMore: ReactNode\n endOfList: ReactNode\n /** The paged band's words. */\n pagination?: Partial<PaginationLabels>\n}\n\nconst DATA_TABLE_LABELS: DataTableLabels = {\n selectAll: \"Select all\",\n selectRow: name => `Select ${name}`,\n columns: \"Columns\",\n rowCount: count => `${count} rows`,\n selected: count => `${count} selected`,\n selection: \"Selection\",\n clearSelection: \"Clear selection\",\n loadingMore: \"Loading more…\",\n endOfList: \"End of list\",\n}\n\n/** The footer of a table whose rows come a page at a time. Page and page size live in `state`. */\ninterface DataTablePages {\n type: \"pages\"\n /** Every row the query matches, across all pages. */\n total: number\n /** The page sizes the reader picks from. Left out, the band has no per-page select. */\n perPageOptions?: number[]\n}\n\n/** The footer of a table that loads the next batch as its end scrolls into view. */\ninterface DataTableInfinite {\n type: \"infinite\"\n hasMore: boolean\n isLoadingMore: boolean\n /** Asks for the next batch. Pass a stable callback. */\n onLoadMore: () => void\n /** False after a failed batch, so the band does not ask for it again at once. */\n enabled?: boolean\n /** The count at the start of the band. Left out, it is the number of loaded rows. */\n count?: ReactNode\n}\n\nexport type DataTablePagination = DataTablePages | DataTableInfinite\n\nexport interface DataTableChangeOptions {\n /**\n * True when the table corrects the state itself (a page past the end), so a router adapter\n * replaces the history entry rather than adding one the reader would land back on.\n */\n replace: boolean\n}\n\n/** What the toolbar render prop receives. */\nexport interface DataTableToolbarContext {\n state: DataTableState\n /** Changes part of the state under the paging rules: a new search or filter goes to page 1. */\n setState: (change: Partial<DataTableState>) => void\n /** A menu that shows and hides the columns that allow it, for the toolbar's `end`. */\n columnPicker: ReactNode\n}\n\nexport interface DataTableProps<TData extends RowData> extends Pick<\n TableProps,\n \"variant\" | \"layout\" | \"className\" | \"containerClassName\"\n> {\n /** Built with `createDataTableColumnHelper`. Keep the array stable between renders. */\n columns: TableOptions<DataTableFeatures, TData>[\"columns\"]\n /** The rows to show: this page's, or every batch loaded so far. Keep it stable too. */\n data: TData[]\n /** A stable id per row, which a selection is kept by. */\n getRowId: (row: TData) => string\n /** Names a row for a screen reader: its checkbox reads \"Select <name>\". Defaults to its id. */\n getRowLabel?: (row: TData) => string\n \"aria-label\": string\n state: DataTableState\n onStateChange: (state: DataTableState, options: DataTableChangeOptions) => void\n pagination?: DataTablePagination\n /**\n * A request is in flight. With no rows yet the table shows skeleton rows; with rows, it keeps\n * them and dims them until the new ones land.\n */\n loading?: boolean\n /** Stands in for the rows when there are none: a `TableMessage` (empty, filtered, error). */\n message?: ReactNode\n /** The row's link. A row with one opens from anywhere on it, through `DataTableRowLink`. */\n getRowHref?: (row: TData) => string | undefined\n /** Renders the row link through a router's link component; it receives the `href`. */\n renderRowLink?: useRender.ComponentProps<\"a\">[\"render\"]\n /** Fades a row whose record is archived or blocked, all but its menu and checkbox. */\n isRowInactive?: (row: TData) => boolean\n /** Adds a checkbox column. A function disables the box of each row it returns false for. */\n enableRowSelection?: boolean | ((row: TData) => boolean)\n /** The bulk action bar's buttons for the selected rows, shown while any are selected. */\n bulkActions?: (rows: TData[], clear: () => void) => ReactNode\n /** Saves the columns the reader hides, per table, in `localStorage`. */\n storageKey?: string\n /** The row above the table: a `TableToolbar`. */\n toolbar?: (context: DataTableToolbarContext) => ReactNode\n size?: TableRowProps[\"size\"]\n /** Formats each figure in the reader's locale. */\n format?: (value: number) => string\n labels?: Partial<DataTableLabels>\n}\n\ninterface SelectionValue {\n labels: Pick<DataTableLabels, \"selectAll\" | \"selectRow\">\n /** The table's `getRowLabel`, which a checkbox calls with its own row's record. */\n getRowLabel?: (row: unknown) => string\n /** Notes whether Shift was held on a checkbox press, which turns the click into a range. */\n setRange: (range: boolean) => void\n isRange: () => boolean\n}\n\nconst SelectionContext = createContext<SelectionValue>({\n labels: DATA_TABLE_LABELS,\n setRange: () => {},\n isRange: () => false,\n})\n\ninterface RowLinkValue {\n href?: string\n render?: useRender.ComponentProps<\"a\">[\"render\"]\n}\n\nconst RowLinkContext = createContext<RowLinkValue>({})\n\ninterface DataTableRowLinkProps {\n className?: string\n children: ReactNode\n}\n\n/**\n * The record's name, inside a `DataTable` column's cell: a link over the whole row when the\n * table has `getRowHref`, plain text when it has none or the row returns none.\n */\nexport function DataTableRowLink({ className, children }: DataTableRowLinkProps) {\n const { href, render } = use(RowLinkContext)\n\n if (!href) return <span className={cn(\"truncate\", className)}>{children}</span>\n\n return (\n <TableRowLink href={href} render={render} className={className}>\n {children}\n </TableRowLink>\n )\n}\n\nfunction getMeta<TData extends RowData>(column: {\n columnDef: ColumnDef<DataTableFeatures, TData, unknown>\n}) {\n return column.columnDef.meta ?? {}\n}\n\n/** The order a sortable column's head announces. */\nfunction getSortOrder(sorted: false | \"asc\" | \"desc\") {\n if (!sorted) return \"none\"\n return sorted === \"asc\" ? \"ascending\" : \"descending\"\n}\n\n/** The column's name in the picker: its `label`, or its header when that is a string. */\nfunction formatColumnLabel<TData extends RowData>(\n column: Column<DataTableFeatures, TData, unknown>,\n) {\n const { header } = column.columnDef\n return getMeta(column).label ?? (typeof header === \"string\" ? header : column.id)\n}\n\ninterface HeadProps<TData extends RowData> {\n header: Header<DataTableFeatures, TData, unknown>\n}\n\nfunction DataTableHead<TData extends RowData>({ header }: HeadProps<TData>) {\n const { column } = header\n const { align, priority, sortable } = getMeta(column)\n const sorted = column.getIsSorted()\n\n // A second click flips the order; the first takes the column's own first direction.\n function onSort() {\n column.toggleSorting(sorted ? sorted === \"asc\" : sortable === \"descending\")\n }\n\n // The checkbox column draws its own head, the select-all box.\n if (column.id === SELECT_COLUMN_ID) return <FlexRender header={header} />\n\n return (\n <TableHead\n align={align}\n priority={priority}\n sort={sortable ? getSortOrder(sorted) : undefined}\n onSort={sortable ? onSort : undefined}\n >\n <FlexRender header={header} />\n </TableHead>\n )\n}\n\ninterface SelectHeadProps<TData extends RowData> {\n table: ReactTable<DataTableFeatures, TData>\n}\n\nfunction SelectHead<TData extends RowData>({ table }: SelectHeadProps<TData>) {\n const { labels } = use(SelectionContext)\n\n return (\n <TableCheckboxCell\n header\n label={labels.selectAll}\n checked={table.getIsAllPageRowsSelected()}\n indeterminate={table.getIsSomePageRowsSelected()}\n onCheckedChange={checked => table.toggleAllPageRowsSelected(checked)}\n />\n )\n}\n\ninterface SelectCellProps<TData extends RowData> {\n row: Row<DataTableFeatures, TData>\n}\n\nfunction SelectCell<TData extends RowData>({ row }: SelectCellProps<TData>) {\n const { labels, getRowLabel, setRange, isRange } = use(SelectionContext)\n\n return (\n <TableCheckboxCell\n label={labels.selectRow(getRowLabel?.(row.original) ?? row.id)}\n checked={row.getIsSelected()}\n disabled={!row.getCanSelect()}\n onClickCapture={(event: ReactMouseEvent) => setRange(event.shiftKey)}\n onKeyDownCapture={(event: ReactKeyboardEvent) => setRange(event.shiftKey)}\n onCheckedChange={checked =>\n row.getToggleSelectedHandler()({ target: { checked }, shiftKey: isRange() })\n }\n />\n )\n}\n\ninterface CellProps<TData extends RowData> {\n cell: Cell<DataTableFeatures, TData, unknown>\n}\n\nfunction DataTableCell<TData extends RowData>({ cell }: CellProps<TData>) {\n const { align, priority } = getMeta(cell.column)\n\n return (\n <TableColumnScope align={align} priority={priority}>\n <FlexRender cell={cell} />\n </TableColumnScope>\n )\n}\n\ninterface DataTableRowProps<TData extends RowData> {\n row: Row<DataTableFeatures, TData>\n size: TableRowProps[\"size\"]\n inactive?: boolean\n href?: string\n render?: useRender.ComponentProps<\"a\">[\"render\"]\n}\n\nfunction DataTableRow<TData extends RowData>({\n row,\n size,\n inactive,\n href,\n render,\n}: DataTableRowProps<TData>) {\n const link = useMemo(() => ({ href, render }), [href, render])\n\n return (\n <RowLinkContext value={link}>\n <TableRow size={size} selected={row.getIsSelected()} inactive={inactive}>\n {row.getVisibleCells().map(cell => (\n <DataTableCell key={cell.id} cell={cell} />\n ))}\n </TableRow>\n </RowLinkContext>\n )\n}\n\n/**\n * A table drawn from react-table column definitions: the app writes columns, the wrapper draws\n * the head, the rows, the footer band, the checkbox column and the bulk action bar. Its state\n * (page, page size, sort, search, filters) is controlled and never read from the URL, so each\n * app keeps it in its own router. The server sorts, filters and pages: `data` is the rows to\n * show, in order. Paging follows one set of rules: the page is 1-based, a page past the end\n * shows the last one, a change of sort, search, filter or page size goes back to page 1, and\n * the old rows stay dimmed while the next ones load.\n */\nexport function DataTable<TData extends RowData>({\n columns,\n data,\n getRowId,\n getRowLabel,\n \"aria-label\": ariaLabel,\n state,\n onStateChange,\n pagination,\n loading = false,\n message,\n getRowHref,\n renderRowLink,\n isRowInactive,\n enableRowSelection,\n bulkActions,\n storageKey,\n toolbar,\n size = \"default\",\n format = String,\n labels: labelsProp,\n variant,\n layout,\n className,\n containerClassName,\n}: DataTableProps<TData>) {\n const labels = { ...DATA_TABLE_LABELS, ...labelsProp }\n const tableRef = useRef<HTMLTableElement>(null)\n const rangeRef = useRef(false)\n\n const [rowSelection, setRowSelection] = useState<RowSelectionState>({})\n const [columnVisibility, setColumnVisibility] = useState<ColumnVisibilityState>({})\n\n const rowSetKey = formatRowSetKey(state)\n const [selectionKey, setSelectionKey] = useState(rowSetKey)\n const selectable = Boolean(enableRowSelection)\n\n // Read after mounting, so a server render and the first client render agree: storage is\n // outside React, and a server has none.\n useEffect(() => {\n // oxlint-disable-next-line react/set-state-in-effect\n if (storageKey) setColumnVisibility(readColumnVisibility(storageKey))\n }, [storageKey])\n\n const sorting: SortingState = state.sort ? [state.sort] : []\n\n function setState(change: Partial<DataTableState>) {\n onStateChange(changeDataTableState(state, change), { replace: false })\n }\n\n function onSortingChange(updater: Updater<SortingState>) {\n const [sort] = functionalUpdate(updater, sorting)\n setState({ sort })\n }\n\n function onColumnVisibilityChange(updater: Updater<ColumnVisibilityState>) {\n const next = functionalUpdate(updater, columnVisibility)\n setColumnVisibility(next)\n if (storageKey) writeColumnVisibility(storageKey, next)\n }\n\n // Keyed on whether rows select, not on the callback, which a caller often writes inline.\n const allColumns = useMemo(() => {\n if (!selectable) return columns\n\n const select: ColumnDef<DataTableFeatures, TData, unknown> = {\n id: SELECT_COLUMN_ID,\n enableHiding: false,\n enableSorting: false,\n meta: { width: \"2.25rem\", skeleton: false },\n header: ({ table }) => <SelectHead table={table} />,\n cell: ({ row }) => <SelectCell row={row} />,\n }\n return [select, ...columns]\n }, [columns, selectable])\n\n const table = useTable({\n features: DATA_TABLE_FEATURES,\n columns: allColumns,\n data,\n getRowId,\n state: { sorting, rowSelection, columnVisibility },\n onSortingChange,\n onRowSelectionChange: setRowSelection,\n onColumnVisibilityChange,\n manualSorting: true,\n enableSortingRemoval: false,\n enableMultiSort: false,\n enableRowSelection:\n typeof enableRowSelection === \"function\"\n ? row => enableRowSelection(row.original)\n : selectable,\n })\n\n // A selection covers the rows on screen: a new page, sort, search or filter clears it, and\n // the Shift range starts over with it.\n if (selectionKey !== rowSetKey) {\n setSelectionKey(rowSetKey)\n table.resetRowSelection(true)\n }\n\n function clearSelection() {\n table.resetRowSelection(true)\n }\n\n const selection: SelectionValue = {\n labels,\n // Every row the context reaches is a `TData`, which is what `getRowLabel` takes.\n getRowLabel: getRowLabel as SelectionValue[\"getRowLabel\"],\n setRange: range => {\n rangeRef.current = range\n },\n isRange: () => rangeRef.current,\n }\n\n const tableColumns: TableColumn[] = table.getVisibleLeafColumns().map(column => {\n const meta = getMeta(column)\n return {\n width: meta.width ?? \"minmax(0,1fr)\",\n priority: meta.priority,\n align: meta.align,\n skeleton: meta.skeleton,\n }\n })\n const headers = table.getHeaderGroups().at(-1)?.headers ?? []\n const { rows } = table.getRowModel()\n const selectedRows = table.getSelectedRowModel().rows.map(row => row.original)\n\n const paged = pagination?.type === \"pages\" ? pagination : undefined\n const infinite = pagination?.type === \"infinite\" ? pagination : undefined\n const perPage = state.perPage ?? DEFAULT_PER_PAGE\n const pageCount = paged ? getPageCount(paged.total, perPage) : 1\n const page = clampPage(state.page ?? 1, pageCount)\n\n // A page past the end (a stale link, rows deleted since) moves the state to the last page, so\n // the app asks for rows that exist.\n const pastEnd = paged !== undefined && !loading && (state.page ?? 1) !== page\n useEffect(() => {\n if (pastEnd) onStateChange({ ...state, page }, { replace: true })\n // Only a new clamp asks again: the app's state catching up ends it.\n // oxlint-disable-next-line react-hooks/exhaustive-deps\n }, [pastEnd, page])\n\n function onPageChange(next: number) {\n setState({ page: next })\n // The rows change under the reader: bring the table's top back when it has scrolled away.\n const element = tableRef.current\n if (element && element.getBoundingClientRect().top < 0) {\n element.scrollIntoView({ block: \"start\" })\n }\n }\n\n const hideable = table.getAllLeafColumns().filter(column => column.getCanHide())\n const columnPicker = hideable.length > 0 && (\n <Menu>\n <MenuTrigger render={<Button variant=\"secondary\" suffix={<ChevronDownIcon />} />}>\n {labels.columns}\n </MenuTrigger>\n <MenuContent label={labels.columns} align=\"end\">\n {hideable.map(column => (\n <MenuCheckboxItem\n key={column.id}\n checked={column.getIsVisible()}\n closeOnClick={false}\n onCheckedChange={checked => column.toggleVisibility(checked)}\n >\n {formatColumnLabel(column)}\n </MenuCheckboxItem>\n ))}\n </MenuContent>\n </Menu>\n )\n\n const firstLoad = loading && rows.length === 0\n const dimmed = loading && rows.length > 0\n const loadingMore = infinite?.isLoadingMore === true && rows.length > 0\n\n const footer = paged ? (\n <Pagination\n page={page}\n pageCount={pageCount}\n total={paged.total}\n perPage={perPage}\n perPageOptions={paged.perPageOptions}\n loading={loading}\n format={format}\n labels={labels.pagination}\n onPageChange={onPageChange}\n onPerPageChange={next => setState({ perPage: next })}\n />\n ) : infinite && rows.length > 0 ? (\n <PaginationInfinite\n count={infinite.count ?? labels.rowCount(format(rows.length))}\n hasMore={infinite.hasMore}\n loading={infinite.isLoadingMore}\n enabled={infinite.enabled}\n loadingLabel={labels.loadingMore}\n endLabel={labels.endOfList}\n onLoadMore={infinite.onLoadMore}\n />\n ) : undefined\n\n const tableElement = (\n <SelectionContext value={selection}>\n <Table\n ref={tableRef}\n aria-label={ariaLabel}\n aria-busy={loading || loadingMore || undefined}\n columns={tableColumns}\n variant={variant}\n layout={layout}\n footer={footer}\n className={className}\n containerClassName={containerClassName}\n >\n <TableHeader>\n {headers.map(header => (\n <DataTableHead key={header.id} header={header} />\n ))}\n </TableHeader>\n <TableBody className={cn(\"transition-opacity\", dimmed && \"opacity-50\")}>\n {firstLoad\n ? Array.from({ length: FIRST_LOAD_ROWS }, (_, index) => (\n <TableSkeletonRow key={index} size={size} index={index} />\n ))\n : rows.length === 0\n ? message\n : rows.map(row => (\n <DataTableRow\n key={row.id}\n row={row}\n size={size}\n inactive={isRowInactive?.(row.original)}\n href={getRowHref?.(row.original)}\n render={renderRowLink}\n />\n ))}\n {loadingMore &&\n Array.from({ length: MORE_ROWS }, (_, index) => (\n <TableSkeletonRow key={index} size={size} index={rows.length + index} />\n ))}\n </TableBody>\n </Table>\n </SelectionContext>\n )\n\n const bar = bulkActions && (\n <BulkActionBar\n count={selectedRows.length}\n label={labels.selected(format(selectedRows.length))}\n aria-label={labels.selection}\n clearLabel={labels.clearSelection}\n onClear={clearSelection}\n >\n {bulkActions(selectedRows, clearSelection)}\n </BulkActionBar>\n )\n\n if (!toolbar) {\n return (\n <>\n {tableElement}\n {bar}\n </>\n )\n }\n\n return (\n <div className=\"flex flex-col gap-3\">\n {toolbar({ state, setState, columnPicker })}\n {tableElement}\n {bar}\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;AAiEA,MAAM,mBAAmB;;AAGzB,MAAM,kBAAkB;AACxB,MAAM,YAAY;AAsBlB,MAAM,oBAAqC;CACzC,WAAW;CACX,YAAW,SAAQ,UAAU;CAC7B,SAAS;CACT,WAAU,UAAS,GAAG,MAAM;CAC5B,WAAU,UAAS,GAAG,MAAM;CAC5B,WAAW;CACX,gBAAgB;CAChB,aAAa;CACb,WAAW;AACb;AA+FA,MAAM,mBAAmB,cAA8B;CACrD,QAAQ;CACR,gBAAgB,CAAC;CACjB,eAAe;AACjB,CAAC;AAOD,MAAM,iBAAiB,cAA4B,CAAC,CAAC;;;;;AAWrD,SAAgB,iBAAiB,EAAE,WAAW,YAAmC;CAC/E,MAAM,EAAE,MAAM,WAAW,IAAI,cAAc;CAE3C,IAAI,CAAC,MAAM,OAAO,oBAAC,QAAD;EAAM,WAAW,GAAG,YAAY,SAAS;EAAI;CAAe,CAAA;CAE9E,OACE,oBAAC,cAAD;EAAo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AA5B,OAAO,EAAqB,CACjD,EACU,CAAA,GACb,qBAAC,WAAD;IAAW,WAAW,GAAG,sBAAsB,UAAU,YAAY;IAArE,UAAA,CACG,YACG,MAAM,KAAK,EAAE,QAAQ,gBAAgB,IAAI,GAAG,UAC1C,oBAAC,kBAAD;KAAoC;KAAa;IAAQ,GAAlC,KAAkC,CAC1D,IACD,KAAK,WAAW,IACd,UACA,KAAK,KAAI,QACP,oBAAC,cAAD;KAEO;KACC;KACN,UAAU,gBAAgB,IAAI,QAAQ;KACtC,MAAM,aAAa,IAAI,QAAQ;KAC/B,QAAQ;IACT,GANM,IAAI,EAMV,CACF,GACN,eACC,MAAM,KAAK,EAAE,QAAQ,UAAU,IAAI,GAAG,UACpC,oBAAC,kBAAD;KAAoC;KAAM,OAAO,KAAK,SAAS;IAAQ,GAAhD,KAAgD,CACxE,CACM;GACN,CAAA,CAAA;;CACS,CAAA;CAGpB,MAAM,MAAM,eACV,oBAAC,eAAD;EACE,OAAO,aAAa;EACpB,OAAO,OAAO,SAAS,OAAO,aAAa,MAAM,CAAC;EAClD,cAAY,OAAO;EACnB,YAAY,OAAO;EACnB,SAAS;EAER,UAAA,YAAY,cAAc,cAAc;CAC5B,CAAA;CAGjB,IAAI,CAAC,SACH,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,cACA,GACD,EAAA,CAAA;CAIN,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACG,QAAQ;IAAE;IAAO;IAAU;GAAa,CAAC;GACzC;GACA;EACE;;AAET"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { VariantProps } from "../lib/variants.js";
|
|
2
|
+
import { DatePickerProps } from "./date-picker.js";
|
|
3
|
+
import { inputVariants } from "./input.js";
|
|
4
|
+
import { ComponentProps } from "react";
|
|
5
|
+
export type DatePickerTriggerProps = Omit<ComponentProps<"button">, "value" | "children"> & Pick<VariantProps<typeof inputVariants>, "size"> & Pick<DatePickerProps, "value" | "placeholder" | "formatDay">;
|
|
6
|
+
/**
|
|
7
|
+
* The date picker's trigger, kept apart from the calendar so a form can show it while the
|
|
8
|
+
* picker itself still loads. It holds a value, so it is a field like a select's trigger, with
|
|
9
|
+
* the field's ground and edge, rather than a button: in a form it sits flush with the inputs
|
|
10
|
+
* around it. A toolbar's period picker runs a command instead and stays a `Button`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function DatePickerTrigger({ value, placeholder, formatDay, size, className, ...props }: DatePickerTriggerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { CalendarIcon } from "../lib/icons.js";
|
|
3
|
+
import { cn } from "../lib/variants.js";
|
|
4
|
+
import { inputVariants } from "./input.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/components/date-picker-trigger.tsx
|
|
7
|
+
/**
|
|
8
|
+
* The date picker's trigger, kept apart from the calendar so a form can show it while the
|
|
9
|
+
* picker itself still loads. It holds a value, so it is a field like a select's trigger, with
|
|
10
|
+
* the field's ground and edge, rather than a button: in a form it sits flush with the inputs
|
|
11
|
+
* around it. A toolbar's period picker runs a command instead and stays a `Button`.
|
|
12
|
+
*/
|
|
13
|
+
function DatePickerTrigger({ value, placeholder = "Pick a date", formatDay, size, className, ...props }) {
|
|
14
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
15
|
+
type: "button",
|
|
16
|
+
className: inputVariants({
|
|
17
|
+
interactive: true,
|
|
18
|
+
size,
|
|
19
|
+
className: cn("flex items-center gap-2 text-start tabular-nums", "data-popup-open:border-edge-solid data-popup-open:bg-fill-subtle active:not-disabled:bg-fill-subtle", className)
|
|
20
|
+
}),
|
|
21
|
+
...props,
|
|
22
|
+
children: [/* @__PURE__ */ jsx(CalendarIcon, { className: "size-3.5 shrink-0 text-ink-muted" }), /* @__PURE__ */ jsx("span", {
|
|
23
|
+
className: cn("truncate", !value && "text-ink-muted"),
|
|
24
|
+
children: value ? formatDay(value) : placeholder
|
|
25
|
+
})]
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export { DatePickerTrigger };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=date-picker-trigger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-picker-trigger.js","names":[],"sources":["../../src/components/date-picker-trigger.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ComponentProps } from \"react\"\nimport { CalendarIcon } from \"../lib/icons\"\nimport { cn, type VariantProps } from \"../lib/variants\"\nimport type { DatePickerProps } from \"./date-picker\"\nimport { inputVariants } from \"./input\"\n\nexport type DatePickerTriggerProps = Omit<ComponentProps<\"button\">, \"value\" | \"children\"> &\n Pick<VariantProps<typeof inputVariants>, \"size\"> &\n Pick<DatePickerProps, \"value\" | \"placeholder\" | \"formatDay\">\n\n/**\n * The date picker's trigger, kept apart from the calendar so a form can show it while the\n * picker itself still loads. It holds a value, so it is a field like a select's trigger, with\n * the field's ground and edge, rather than a button: in a form it sits flush with the inputs\n * around it. A toolbar's period picker runs a command instead and stays a `Button`.\n */\nexport function DatePickerTrigger({\n value,\n placeholder = \"Pick a date\",\n formatDay,\n size,\n className,\n ...props\n}: DatePickerTriggerProps) {\n return (\n <button\n type=\"button\"\n className={inputVariants({\n interactive: true,\n size,\n className: cn(\n \"flex items-center gap-2 text-start tabular-nums\",\n \"data-popup-open:border-edge-solid data-popup-open:bg-fill-subtle active:not-disabled:bg-fill-subtle\",\n className,\n ),\n })}\n {...props}\n >\n <CalendarIcon className=\"size-3.5 shrink-0 text-ink-muted\" />\n <span className={cn(\"truncate\", !value && \"text-ink-muted\")}>\n {value ? formatDay(value) : placeholder}\n </span>\n </button>\n )\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,SAAgB,kBAAkB,EAChC,OACA,cAAc,eACd,WACA,MACA,WACA,GAAG,SACsB;CACzB,OACE,qBAAC,UAAD;EACE,MAAK;EACL,WAAW,cAAc;GACvB,aAAa;GACb;GACA,WAAW,GACT,mDACA,uGACA,SACF;EACF,CAAC;EACD,GAAI;EAXN,UAAA,CAaE,oBAAC,cAAD,EAAc,WAAU,mCAAoC,CAAA,GAC5D,oBAAC,QAAD;GAAM,WAAW,GAAG,YAAY,CAAC,SAAS,gBAAgB;GACvD,UAAA,QAAQ,UAAU,KAAK,IAAI;EACxB,CAAA,CACA;;AAEZ"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface DatePickerProps {
|
|
2
|
+
/** The selected day as "YYYY-MM-DD", or empty for none. */
|
|
3
|
+
value?: string;
|
|
4
|
+
onChange: (value: string) => void;
|
|
5
|
+
/** Earliest and latest selectable day, both "YYYY-MM-DD" and both inclusive. */
|
|
6
|
+
min?: string;
|
|
7
|
+
max?: string;
|
|
8
|
+
/** Shown on the trigger while nothing is selected. */
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Names the selected "YYYY-MM-DD" day on the trigger. The app supplies it, so the day reads
|
|
12
|
+
* in the app's own locale and time zone like every other date beside it.
|
|
13
|
+
*/
|
|
14
|
+
formatDay: (day: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Lets the reader remove the date: a second click on the selected day, or the Clear button
|
|
17
|
+
* under the calendar. Set it on an optional date; a required one only ever changes.
|
|
18
|
+
*/
|
|
19
|
+
clearable?: boolean;
|
|
20
|
+
id?: string;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
/** Why the date cannot be changed: the trigger stays focusable, reads it, and never opens. */
|
|
23
|
+
disabledReason?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
/** Labels the trigger for screen readers, for a field with no visible `<label>`. */
|
|
26
|
+
"aria-label"?: string;
|
|
27
|
+
"aria-describedby"?: string;
|
|
28
|
+
"aria-invalid"?: boolean;
|
|
29
|
+
"aria-required"?: boolean;
|
|
30
|
+
onBlur?: () => void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A single date, picked from a calendar in a popover. Replaces `<input type="date">`, whose
|
|
34
|
+
* widget every browser draws its own way and none of them on brand.
|
|
35
|
+
*/
|
|
36
|
+
export declare function DatePicker({ value, onChange, min, max, placeholder, formatDay, clearable, id, disabled, disabledReason, className, ...props }: DatePickerProps): import("react").JSX.Element;
|