@adapttable/mantine 0.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/CHANGELOG.md +37 -0
- package/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/index.cjs +2004 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +226 -0
- package/dist/index.d.ts +226 -0
- package/dist/index.js +1951 -0
- package/dist/index.js.map +1 -0
- package/package.json +88 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, RefObject, DependencyList } from 'react';
|
|
3
|
+
import { BaseDataTableProps, TableSource, UseServerDataOptions, UrlStateAdapter, UseSavedViewsOptions, ActiveFilterChip, FilterDef, TableLabels, UseSavedViewsResult } from '@adapttable/core';
|
|
4
|
+
export { ActionConfirm, ActiveFilterChip, BulkAction, CellProps, ColorScheme, ColumnDef, ConfirmHandler, ConfirmRequest, Direction, ExtraFilters, FilterDef, FilterOption, FilterType, FilterValue, InfiniteQueryLike, PageSelector, PaginatedResponse, PaginationMode, RowAction, SavedView, SortByOption, SortDirection, SortableValue, TableLabels, TableQuery, TableQueryParams, TableSource, UrlStateAdapter, UseBackendDataOptions, UseDataTableResult, UseFrontendDataOptions, UseSavedViewsOptions, UseSavedViewsResult, UseTableUrlStateOptions, UseTableUrlStateResult, createHistoryAdapter, createMemoryAdapter, defaultConfirm, defaultLabels, deriveSortByOptions, getHistoryAdapter, useBackendData, useDataTable, useFrontendData, useSavedViews, useTableUrlState } from '@adapttable/core';
|
|
5
|
+
|
|
6
|
+
/** Overridable sub-components. Each defaults to a styled Mantine part. */
|
|
7
|
+
interface DataTableSlots {
|
|
8
|
+
/** Replace the loading skeleton. */
|
|
9
|
+
skeleton?: ReactNode;
|
|
10
|
+
/** Replace the empty-state. */
|
|
11
|
+
empty?: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
/** Per-part class name overrides. */
|
|
14
|
+
interface DataTableClassNames {
|
|
15
|
+
root?: string;
|
|
16
|
+
toolbar?: string;
|
|
17
|
+
table?: string;
|
|
18
|
+
card?: string;
|
|
19
|
+
footer?: string;
|
|
20
|
+
}
|
|
21
|
+
/** Props for the Mantine `<DataTable>`. */
|
|
22
|
+
interface DataTableProps<TRow> extends Omit<BaseDataTableProps<TRow>, "source"> {
|
|
23
|
+
/**
|
|
24
|
+
* Full-control tier: a prebuilt source (`useFrontendData` /
|
|
25
|
+
* `useBackendData`). Omit it and pass `data` for the zero-ceremony tiers.
|
|
26
|
+
*/
|
|
27
|
+
source?: TableSource<TRow>;
|
|
28
|
+
/**
|
|
29
|
+
* Frontend tier: the raw rows — the table filters, sorts and pages them.
|
|
30
|
+
* Combined with `onQueryChange` it becomes the server tier: `data` is the
|
|
31
|
+
* current page, rendered as-is.
|
|
32
|
+
*/
|
|
33
|
+
data?: readonly TRow[];
|
|
34
|
+
/** Server tier: total row count across all pages (drives the pager). */
|
|
35
|
+
total?: number;
|
|
36
|
+
/** Server tier: a request is in flight. */
|
|
37
|
+
loading?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Server tier: fired with the consolidated query (page, limit, search,
|
|
40
|
+
* sort, filters) whenever it changes — including once on mount with the
|
|
41
|
+
* URL-restored values. Fetch in response and hand back `data` + `total`.
|
|
42
|
+
*/
|
|
43
|
+
onQueryChange?: UseServerDataOptions<TRow>["onQueryChange"];
|
|
44
|
+
/**
|
|
45
|
+
* Namespace for this table's URL params (`urlKey="left"` → `left.q`,
|
|
46
|
+
* `left.page`, …) so multiple tables can share one URL. Applies to the
|
|
47
|
+
* `data` / `onQueryChange` tiers; a prebuilt `source` owns its own state.
|
|
48
|
+
*/
|
|
49
|
+
urlKey?: string;
|
|
50
|
+
/**
|
|
51
|
+
* URL-state backend for the `data` / `onQueryChange` tiers. Defaults to
|
|
52
|
+
* the browser History API; supply a router adapter (react-router,
|
|
53
|
+
* Next.js) — or `createMemoryAdapter()` in tests — to integrate with an
|
|
54
|
+
* existing navigation stack.
|
|
55
|
+
*/
|
|
56
|
+
urlAdapter?: UrlStateAdapter;
|
|
57
|
+
/**
|
|
58
|
+
* Sync table state (search, sort, page, filters) to the URL. `false`
|
|
59
|
+
* keeps everything in memory — the table works identically, the address
|
|
60
|
+
* bar never changes, and any `urlAdapter` is ignored.
|
|
61
|
+
*
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
urlSync?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Saved views: capture the table's current URL state (search, sort, page,
|
|
67
|
+
* filters, column layout) under a name and re-apply it on demand. Setting
|
|
68
|
+
* this renders a Saved-views menu in the toolbar next to the Columns
|
|
69
|
+
* button. `adapter` / `urlKey` default to the table's own `urlAdapter` /
|
|
70
|
+
* `urlKey`, so usually only `storageKey` is needed.
|
|
71
|
+
*/
|
|
72
|
+
savedViews?: UseSavedViewsOptions;
|
|
73
|
+
/** Replace sub-components (skeleton, empty-state). */
|
|
74
|
+
slots?: DataTableSlots;
|
|
75
|
+
/** Per-part class name overrides. */
|
|
76
|
+
classNames?: DataTableClassNames;
|
|
77
|
+
/**
|
|
78
|
+
* Animate rows/cards on mount (dependency-free; honors reduced motion).
|
|
79
|
+
* Off by default.
|
|
80
|
+
*/
|
|
81
|
+
animate?: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Batteries-included Mantine data table. Drop in `columns`, a `rowKey`,
|
|
86
|
+
* and a data tier — raw `data` (frontend), `data` + `onQueryChange`
|
|
87
|
+
* (server), or a prebuilt `source` — to get a fully styled, sortable,
|
|
88
|
+
* filterable, paginated table with selection, bulk actions, RTL, dark
|
|
89
|
+
* mode, and optional entrance animation.
|
|
90
|
+
*
|
|
91
|
+
* @typeParam TRow - The row type.
|
|
92
|
+
*/
|
|
93
|
+
declare function DataTable<TRow>(props: Readonly<DataTableProps<TRow>>): react.JSX.Element;
|
|
94
|
+
|
|
95
|
+
/** Props for {@link ActiveFilterChips}. */
|
|
96
|
+
interface ActiveFilterChipsProps {
|
|
97
|
+
/** The chips to render. */
|
|
98
|
+
chips: readonly ActiveFilterChip[];
|
|
99
|
+
/** Optional clear-all handler; the link is hidden when omitted. */
|
|
100
|
+
onClearAll?: () => void;
|
|
101
|
+
/** Accessible label for the strip. */
|
|
102
|
+
label: string;
|
|
103
|
+
/** Clear-all link text. */
|
|
104
|
+
clearAllLabel: string;
|
|
105
|
+
}
|
|
106
|
+
/** A wrapping strip of removable filter chips. Renders nothing when empty. */
|
|
107
|
+
declare function ActiveFilterChips({ chips, onClearAll, label, clearAllLabel, }: Readonly<ActiveFilterChipsProps>): react.JSX.Element | null;
|
|
108
|
+
|
|
109
|
+
/** Props for {@link AutoFilterForm}. */
|
|
110
|
+
interface AutoFilterFormProps<TRow> {
|
|
111
|
+
/** The resolved declarative definitions, in render order. */
|
|
112
|
+
defs: readonly FilterDef<TRow>[];
|
|
113
|
+
/** The resolved source whose `extra` bag the controls read and write. */
|
|
114
|
+
source: TableSource<TRow>;
|
|
115
|
+
/** Resolved labels — the range widgets read the operator/value strings. */
|
|
116
|
+
labels: Required<TableLabels>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The auto-built filter form: one labeled, Mantine-native control per
|
|
120
|
+
* declarative {@link FilterDef}. Values live in the source's `extra` bag
|
|
121
|
+
* (so the URL, chips and — on frontend data — the predicate all follow);
|
|
122
|
+
* clearing a control writes the empty value, which drops the URL param.
|
|
123
|
+
* Range types render operator-first: an operator select plus one value
|
|
124
|
+
* input (two for "Between"), persisted as the inclusive pair.
|
|
125
|
+
*
|
|
126
|
+
* @typeParam TRow - The row type.
|
|
127
|
+
*/
|
|
128
|
+
declare function AutoFilterForm<TRow>({ defs, source, labels, }: Readonly<AutoFilterFormProps<TRow>>): react.JSX.Element;
|
|
129
|
+
|
|
130
|
+
/** Props for {@link EmptyState}. */
|
|
131
|
+
interface EmptyStateProps {
|
|
132
|
+
/** Headline text. */
|
|
133
|
+
title: string;
|
|
134
|
+
/** Optional supporting description. */
|
|
135
|
+
description?: string;
|
|
136
|
+
/** Optional custom icon (defaults to an inbox glyph). */
|
|
137
|
+
icon?: ReactNode;
|
|
138
|
+
/** Optional call-to-action (e.g. a clear-filters button). */
|
|
139
|
+
action?: ReactNode;
|
|
140
|
+
}
|
|
141
|
+
/** Centred "nothing to show" placeholder. */
|
|
142
|
+
declare function EmptyState({ title, description, icon, action, }: Readonly<EmptyStateProps>): react.JSX.Element;
|
|
143
|
+
|
|
144
|
+
/** Props for {@link ErrorState}. */
|
|
145
|
+
interface ErrorStateProps {
|
|
146
|
+
/** The error to surface. */
|
|
147
|
+
error: Error;
|
|
148
|
+
/** Title line. */
|
|
149
|
+
title: string;
|
|
150
|
+
/** Supporting message. */
|
|
151
|
+
message: string;
|
|
152
|
+
/** Retry button label. */
|
|
153
|
+
retryLabel: string;
|
|
154
|
+
/** Optional retry handler; the button is hidden when omitted. */
|
|
155
|
+
onRetry?: () => void;
|
|
156
|
+
/** Whether a retry is in flight. */
|
|
157
|
+
isRetrying?: boolean;
|
|
158
|
+
}
|
|
159
|
+
/** Inline error alert with an optional retry button. */
|
|
160
|
+
declare function ErrorState({ error, title, message, retryLabel, onRetry, isRetrying, }: Readonly<ErrorStateProps>): react.JSX.Element;
|
|
161
|
+
|
|
162
|
+
/** Props for {@link PaginationFooter}. */
|
|
163
|
+
interface PaginationFooterProps {
|
|
164
|
+
page: number;
|
|
165
|
+
totalPages: number;
|
|
166
|
+
limit: number;
|
|
167
|
+
total: number;
|
|
168
|
+
fromIndex: number;
|
|
169
|
+
toIndex: number;
|
|
170
|
+
onPageChange: (page: number) => void;
|
|
171
|
+
onLimitChange: (limit: number) => void;
|
|
172
|
+
labels: Required<TableLabels>;
|
|
173
|
+
}
|
|
174
|
+
/** Desktop pagination bar: page-size + range on the left, pager on the right. */
|
|
175
|
+
declare function PaginationFooter({ page, totalPages, limit, total, fromIndex, toIndex, onPageChange, onLimitChange, labels, }: Readonly<PaginationFooterProps>): react.JSX.Element;
|
|
176
|
+
|
|
177
|
+
/** Props for {@link SavedViewsMenu}. */
|
|
178
|
+
interface SavedViewsMenuProps {
|
|
179
|
+
/** The saved-views state from core's `useSavedViews`. */
|
|
180
|
+
views: UseSavedViewsResult;
|
|
181
|
+
/** Resolved table labels (e.g. `table.labels` from `useDataTable`). */
|
|
182
|
+
labels: Required<TableLabels>;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Saved-views menu: lists every captured view (click a name to apply it, the
|
|
186
|
+
* trailing ✕ to delete it) above a save row that captures the table's
|
|
187
|
+
* CURRENT URL state under the typed name. Pairs with core's `useSavedViews`
|
|
188
|
+
* and composes into the `toolbar` slot — or let `<DataTable savedViews>`
|
|
189
|
+
* mount it for you next to the Columns menu.
|
|
190
|
+
*/
|
|
191
|
+
declare function SavedViewsMenu({ views, labels, }: Readonly<SavedViewsMenuProps>): react.JSX.Element;
|
|
192
|
+
|
|
193
|
+
/** Props for {@link TableSkeleton}. */
|
|
194
|
+
interface TableSkeletonProps {
|
|
195
|
+
/** Number of placeholder columns. */
|
|
196
|
+
columns: number;
|
|
197
|
+
/** Number of placeholder rows. Defaults to 5. */
|
|
198
|
+
rows?: number;
|
|
199
|
+
/** Screen-reader text announcing the loading state. */
|
|
200
|
+
loadingLabel?: string;
|
|
201
|
+
}
|
|
202
|
+
/** Loading placeholder that mirrors the table shape to avoid layout shift. */
|
|
203
|
+
declare function TableSkeleton({ columns, rows, loadingLabel, }: Readonly<TableSkeletonProps>): react.JSX.Element;
|
|
204
|
+
|
|
205
|
+
/** Tuning for the mount stagger. */
|
|
206
|
+
interface MountStaggerOptions {
|
|
207
|
+
/** Master switch. When `false`, the hook is a no-op. */
|
|
208
|
+
enabled: boolean;
|
|
209
|
+
/** Per-item delay in ms. Defaults to 40. */
|
|
210
|
+
step?: number;
|
|
211
|
+
/** Tween duration in ms. Defaults to 320. */
|
|
212
|
+
duration?: number;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Dependency-free entrance stagger using the Web Animations API. Animates
|
|
216
|
+
* descendants marked with `data-stagger` once on mount (and whenever
|
|
217
|
+
* `deps` change), honoring `prefers-reduced-motion`. Works without GSAP;
|
|
218
|
+
* GSAP fans can swap in their own hook of the same shape.
|
|
219
|
+
*
|
|
220
|
+
* @param ref - Ref to the container whose `[data-stagger]` items animate.
|
|
221
|
+
* @param deps - Re-run the stagger when these change (e.g. the row set).
|
|
222
|
+
* @param options - See {@link MountStaggerOptions}.
|
|
223
|
+
*/
|
|
224
|
+
declare function useMountStagger(ref: RefObject<HTMLElement | null>, deps: DependencyList, options: MountStaggerOptions): void;
|
|
225
|
+
|
|
226
|
+
export { ActiveFilterChips, type ActiveFilterChipsProps, AutoFilterForm, type AutoFilterFormProps, DataTable, type DataTableClassNames, type DataTableProps, type DataTableSlots, EmptyState, type EmptyStateProps, ErrorState, type ErrorStateProps, type MountStaggerOptions, PaginationFooter, type PaginationFooterProps, SavedViewsMenu, type SavedViewsMenuProps, TableSkeleton, type TableSkeletonProps, useMountStagger };
|