@faast-app/ui 0.0.0-stage → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/dist/components/Alert.d.ts +30 -0
- package/dist/components/Alert.js +19 -0
- package/dist/components/AppShell.d.ts +63 -0
- package/dist/components/AppShell.js +80 -0
- package/dist/components/Avatar.d.ts +18 -0
- package/dist/components/Avatar.js +21 -0
- package/dist/components/Badge.d.ts +24 -0
- package/dist/components/Badge.js +10 -0
- package/dist/components/Button.d.ts +71 -0
- package/dist/components/Button.js +40 -0
- package/dist/components/Card.d.ts +23 -0
- package/dist/components/Card.js +17 -0
- package/dist/components/Chip.d.ts +16 -0
- package/dist/components/Chip.js +9 -0
- package/dist/components/Choice.d.ts +38 -0
- package/dist/components/Choice.js +53 -0
- package/dist/components/Dialog.d.ts +44 -0
- package/dist/components/Dialog.js +51 -0
- package/dist/components/EmptyState.d.ts +16 -0
- package/dist/components/EmptyState.js +8 -0
- package/dist/components/FileDropArea.d.ts +62 -0
- package/dist/components/FileDropArea.js +90 -0
- package/dist/components/FormField.d.ts +35 -0
- package/dist/components/FormField.js +32 -0
- package/dist/components/HelpMenu.d.ts +46 -0
- package/dist/components/HelpMenu.js +104 -0
- package/dist/components/Icon.d.ts +24 -0
- package/dist/components/Icon.js +195 -0
- package/dist/components/Input.d.ts +37 -0
- package/dist/components/Input.js +31 -0
- package/dist/components/KpiStrip.d.ts +32 -0
- package/dist/components/KpiStrip.js +14 -0
- package/dist/components/LockScreen.d.ts +34 -0
- package/dist/components/LockScreen.js +22 -0
- package/dist/components/Logo.d.ts +27 -0
- package/dist/components/Logo.js +12 -0
- package/dist/components/Navigation.d.ts +37 -0
- package/dist/components/Navigation.js +29 -0
- package/dist/components/OptionList.d.ts +27 -0
- package/dist/components/OptionList.js +18 -0
- package/dist/components/OtpInput.d.ts +31 -0
- package/dist/components/OtpInput.js +102 -0
- package/dist/components/Pagination.d.ts +31 -0
- package/dist/components/Pagination.js +41 -0
- package/dist/components/PasswordField.d.ts +32 -0
- package/dist/components/PasswordField.js +29 -0
- package/dist/components/SegmentedControl.d.ts +35 -0
- package/dist/components/SegmentedControl.js +52 -0
- package/dist/components/Select.d.ts +15 -0
- package/dist/components/Select.js +10 -0
- package/dist/components/SessionTimeoutDialog.d.ts +39 -0
- package/dist/components/SessionTimeoutDialog.js +62 -0
- package/dist/components/Spinner.d.ts +25 -0
- package/dist/components/Spinner.js +15 -0
- package/dist/components/StatTiles.d.ts +35 -0
- package/dist/components/StatTiles.js +12 -0
- package/dist/components/Stepper.d.ts +26 -0
- package/dist/components/Stepper.js +26 -0
- package/dist/components/StickyActionBar.d.ts +28 -0
- package/dist/components/StickyActionBar.js +12 -0
- package/dist/components/Table.d.ts +69 -0
- package/dist/components/Table.js +73 -0
- package/dist/components/TenantMark.d.ts +27 -0
- package/dist/components/TenantMark.js +15 -0
- package/dist/components/Timeline.d.ts +31 -0
- package/dist/components/Timeline.js +18 -0
- package/dist/components/Toast.d.ts +43 -0
- package/dist/components/Toast.js +46 -0
- package/dist/components/Toggletip.d.ts +26 -0
- package/dist/components/Toggletip.js +47 -0
- package/dist/components/Tooltip.d.ts +24 -0
- package/dist/components/Tooltip.js +73 -0
- package/dist/components/Tour.d.ts +66 -0
- package/dist/components/Tour.js +161 -0
- package/dist/components/TourOffer.d.ts +22 -0
- package/dist/components/TourOffer.js +33 -0
- package/dist/components/WelcomeDialog.d.ts +45 -0
- package/dist/components/WelcomeDialog.js +38 -0
- package/dist/data-table/components/ClientDataTable.d.ts +22 -0
- package/dist/data-table/components/ClientDataTable.js +29 -0
- package/dist/data-table/components/DataTableFooter.d.ts +11 -0
- package/dist/data-table/components/DataTableFooter.js +16 -0
- package/dist/data-table/components/DataTableView.d.ts +9 -0
- package/dist/data-table/components/DataTableView.js +95 -0
- package/dist/data-table/components/ServerDataTable.d.ts +16 -0
- package/dist/data-table/components/ServerDataTable.js +17 -0
- package/dist/data-table/core/columnVisibility.d.ts +15 -0
- package/dist/data-table/core/columnVisibility.js +34 -0
- package/dist/data-table/core/constants.d.ts +20 -0
- package/dist/data-table/core/constants.js +21 -0
- package/dist/data-table/core/filters/registry.d.ts +33 -0
- package/dist/data-table/core/filters/registry.js +393 -0
- package/dist/data-table/core/filters/types.d.ts +88 -0
- package/dist/data-table/core/filters/types.js +1 -0
- package/dist/data-table/core/group.d.ts +15 -0
- package/dist/data-table/core/group.js +73 -0
- package/dist/data-table/core/paginate.d.ts +13 -0
- package/dist/data-table/core/paginate.js +27 -0
- package/dist/data-table/core/query.d.ts +65 -0
- package/dist/data-table/core/query.js +138 -0
- package/dist/data-table/core/search.d.ts +10 -0
- package/dist/data-table/core/search.js +35 -0
- package/dist/data-table/core/selection.d.ts +24 -0
- package/dist/data-table/core/selection.js +59 -0
- package/dist/data-table/core/sort.d.ts +14 -0
- package/dist/data-table/core/sort.js +41 -0
- package/dist/data-table/core/text.d.ts +5 -0
- package/dist/data-table/core/text.js +27 -0
- package/dist/data-table/core/types.d.ts +40 -0
- package/dist/data-table/core/types.js +1 -0
- package/dist/data-table/core/url.d.ts +43 -0
- package/dist/data-table/core/url.js +194 -0
- package/dist/data-table/hooks/common.d.ts +14 -0
- package/dist/data-table/hooks/common.js +30 -0
- package/dist/data-table/hooks/small-hooks.d.ts +12 -0
- package/dist/data-table/hooks/small-hooks.js +111 -0
- package/dist/data-table/hooks/useClientDataTable.d.ts +35 -0
- package/dist/data-table/hooks/useClientDataTable.js +311 -0
- package/dist/data-table/hooks/useServerDataTable.d.ts +38 -0
- package/dist/data-table/hooks/useServerDataTable.js +209 -0
- package/dist/data-table/hooks/useServerRows.d.ts +27 -0
- package/dist/data-table/hooks/useServerRows.js +82 -0
- package/dist/data-table/hooks/useTableState.d.ts +39 -0
- package/dist/data-table/hooks/useTableState.js +219 -0
- package/dist/data-table/index.d.ts +42 -0
- package/dist/data-table/index.js +22 -0
- package/dist/data-table/labels.d.ts +77 -0
- package/dist/data-table/labels.js +77 -0
- package/dist/data-table/toolbar/ActiveFilters.d.ts +10 -0
- package/dist/data-table/toolbar/ActiveFilters.js +53 -0
- package/dist/data-table/toolbar/BulkActionBar.d.ts +15 -0
- package/dist/data-table/toolbar/BulkActionBar.js +22 -0
- package/dist/data-table/toolbar/ColumnVisibilityDialog.d.ts +7 -0
- package/dist/data-table/toolbar/ColumnVisibilityDialog.js +15 -0
- package/dist/data-table/toolbar/DataTableToolbar.d.ts +19 -0
- package/dist/data-table/toolbar/DataTableToolbar.js +12 -0
- package/dist/data-table/toolbar/FilterFields.d.ts +11 -0
- package/dist/data-table/toolbar/FilterFields.js +58 -0
- package/dist/data-table/toolbar/FiltersControl.d.ts +34 -0
- package/dist/data-table/toolbar/FiltersControl.js +70 -0
- package/dist/data-table/toolbar/PageSizeSelect.d.ts +7 -0
- package/dist/data-table/toolbar/PageSizeSelect.js +12 -0
- package/dist/data-table/toolbar/QuickFilters.d.ts +7 -0
- package/dist/data-table/toolbar/QuickFilters.js +9 -0
- package/dist/data-table/toolbar/ResultsCount.d.ts +7 -0
- package/dist/data-table/toolbar/ResultsCount.js +9 -0
- package/dist/data-table/toolbar/SearchField.d.ts +36 -0
- package/dist/data-table/toolbar/SearchField.js +64 -0
- package/dist/data-table/toolbar/SortSelect.d.ts +10 -0
- package/dist/data-table/toolbar/SortSelect.js +30 -0
- package/dist/data-table/types.d.ts +334 -0
- package/dist/data-table/types.js +1 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +49 -0
- package/dist/kit/catalogo.html +5281 -0
- package/dist/kit/faast-kit.css +5129 -0
- package/dist/kit/markup.json +127 -0
- package/dist/styles.css +4668 -0
- package/dist/theme/ThemeProvider.d.ts +33 -0
- package/dist/theme/ThemeProvider.js +77 -0
- package/dist/theme/ThemeToggle.d.ts +16 -0
- package/dist/theme/ThemeToggle.js +27 -0
- package/dist/utils/cx.d.ts +2 -0
- package/dist/utils/cx.js +4 -0
- package/dist/utils/devWarn.d.ts +2 -0
- package/dist/utils/devWarn.js +10 -0
- package/dist/utils/tourGeometry.d.ts +61 -0
- package/dist/utils/tourGeometry.js +135 -0
- package/dist/utils/useFloatingPosition.d.ts +9 -0
- package/dist/utils/useFloatingPosition.js +45 -0
- package/dist/utils/useModalDialog.d.ts +7 -0
- package/dist/utils/useModalDialog.js +49 -0
- package/dist/utils/useTourAnchorRect.d.ts +6 -0
- package/dist/utils/useTourAnchorRect.js +40 -0
- package/package.json +53 -4
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type PageSize } from '../core/constants.js';
|
|
2
|
+
import type { CoreFilterDef } from '../core/filters/types.js';
|
|
3
|
+
import type { QueryChangeMeta, SortState, TableQuery } from '../core/types.js';
|
|
4
|
+
import type { DataTableLabels } from '../labels.js';
|
|
5
|
+
import type { DraftFilters, GroupDef } from '../types.js';
|
|
6
|
+
export interface UseTableStateOptions<TRow> {
|
|
7
|
+
filters: readonly CoreFilterDef<TRow>[];
|
|
8
|
+
groups: readonly GroupDef<TRow>[];
|
|
9
|
+
defaultSort: SortState | null;
|
|
10
|
+
defaultQuery?: Partial<TableQuery>;
|
|
11
|
+
query?: TableQuery;
|
|
12
|
+
onQueryChange?: (next: TableQuery, meta: QueryChangeMeta) => void;
|
|
13
|
+
pageSizeOptions?: readonly PageSize[];
|
|
14
|
+
labels: DataTableLabels;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* State shared by both tables: the applied query (controlled or not), the debounced search
|
|
18
|
+
* input and the draft filters. Selection, expansion and column visibility are not part of it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function useTableState<TRow>(options: UseTableStateOptions<TRow>): {
|
|
21
|
+
query: TableQuery;
|
|
22
|
+
controlled: boolean;
|
|
23
|
+
searchInput: string;
|
|
24
|
+
setSearchInput: (value: string) => void;
|
|
25
|
+
flushSearch: () => void;
|
|
26
|
+
clearSearch: () => void;
|
|
27
|
+
draft: DraftFilters;
|
|
28
|
+
setQuickFilter: (id: string) => import("../core/query.js").QueryResult;
|
|
29
|
+
removeFilter: (id: string) => void;
|
|
30
|
+
clearFilters: () => void;
|
|
31
|
+
clearFilterFields: () => void;
|
|
32
|
+
setSort: (sort: SortState | null) => import("../core/query.js").QueryResult;
|
|
33
|
+
toggleSort: (columnId: string) => import("../core/query.js").QueryResult;
|
|
34
|
+
setPage: (page: number) => import("../core/query.js").QueryResult;
|
|
35
|
+
setPageSize: (size: PageSize) => void;
|
|
36
|
+
setGroupBy: (id: string | null) => void;
|
|
37
|
+
clamp: (pageCount: number) => import("../core/query.js").QueryResult;
|
|
38
|
+
pageSizeOptions: readonly (100 | 10 | 25 | 50)[];
|
|
39
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { SEARCH_DEBOUNCE_MS, isPageSize, PAGE_SIZE_OPTIONS, } from '../core/constants.js';
|
|
3
|
+
import { filterValuesEqual, isFilterValueEmpty, sanitizeFilterValues, validateFilterValue, } from '../core/filters/registry.js';
|
|
4
|
+
import { createDefaultQuery, emptyFilterValues, nextSort, normalizeQuery, reduceQuery, } from '../core/query.js';
|
|
5
|
+
import { devWarn } from '../../utils/devWarn.js';
|
|
6
|
+
/**
|
|
7
|
+
* State shared by both tables: the applied query (controlled or not), the debounced search
|
|
8
|
+
* input and the draft filters. Selection, expansion and column visibility are not part of it.
|
|
9
|
+
*/
|
|
10
|
+
export function useTableState(options) {
|
|
11
|
+
const { filters, groups, defaultSort, labels } = options;
|
|
12
|
+
const lockedGroup = groups.find((g) => g.locked);
|
|
13
|
+
const controlled = options.query !== undefined;
|
|
14
|
+
const [internal, setInternal] = useState(() => createDefaultQuery({
|
|
15
|
+
sort: defaultSort,
|
|
16
|
+
groupBy: lockedGroup?.id ?? null,
|
|
17
|
+
...options.defaultQuery,
|
|
18
|
+
}));
|
|
19
|
+
const pageSizeOptions = options.pageSizeOptions ?? PAGE_SIZE_OPTIONS;
|
|
20
|
+
// A controlled query comes from outside (URL): never trust its page size or page.
|
|
21
|
+
const safe = useMemo(() => (options.query ? normalizeQuery(options.query, pageSizeOptions) : null), [options.query, pageSizeOptions]);
|
|
22
|
+
const query = safe ? safe.query : internal;
|
|
23
|
+
const queryFixed = safe?.fixed ?? false;
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (queryFixed) {
|
|
26
|
+
devWarn('The controlled `query` had an invalid `pageSize` or `page`; defaults were used.');
|
|
27
|
+
}
|
|
28
|
+
}, [queryFixed]);
|
|
29
|
+
const queryRef = useRef(query);
|
|
30
|
+
const controlledRef = useRef(controlled);
|
|
31
|
+
const onChangeRef = useRef(options.onQueryChange);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
queryRef.current = query;
|
|
34
|
+
controlledRef.current = controlled;
|
|
35
|
+
onChangeRef.current = options.onQueryChange;
|
|
36
|
+
});
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (controlled && !options.onQueryChange) {
|
|
39
|
+
devWarn('`query` was passed without `onQueryChange`: the table is read-only.');
|
|
40
|
+
}
|
|
41
|
+
}, [controlled, options.onQueryChange]);
|
|
42
|
+
const dispatch = useCallback((action) => {
|
|
43
|
+
const result = reduceQuery(queryRef.current, action);
|
|
44
|
+
if (!result.changed)
|
|
45
|
+
return result;
|
|
46
|
+
if (controlledRef.current && !onChangeRef.current)
|
|
47
|
+
return result;
|
|
48
|
+
queryRef.current = result.query;
|
|
49
|
+
if (!controlledRef.current)
|
|
50
|
+
setInternal(result.query);
|
|
51
|
+
onChangeRef.current?.(result.query, result.meta);
|
|
52
|
+
return result;
|
|
53
|
+
}, []);
|
|
54
|
+
// ---- search: typed text is local; it is applied after 300 ms idle or on Enter ----
|
|
55
|
+
const [search, setSearch] = useState({
|
|
56
|
+
input: query.search,
|
|
57
|
+
pending: false,
|
|
58
|
+
seen: query.search,
|
|
59
|
+
});
|
|
60
|
+
if (query.search !== search.seen) {
|
|
61
|
+
// The applied search changed (commit, back button, URL edit): adopt it unless typing.
|
|
62
|
+
setSearch({
|
|
63
|
+
input: search.pending ? search.input : query.search,
|
|
64
|
+
pending: search.pending,
|
|
65
|
+
seen: query.search,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const timer = useRef(null);
|
|
69
|
+
const inputRef = useRef(search.input);
|
|
70
|
+
const cancelTimer = useCallback(() => {
|
|
71
|
+
if (timer.current !== null)
|
|
72
|
+
clearTimeout(timer.current);
|
|
73
|
+
timer.current = null;
|
|
74
|
+
}, []);
|
|
75
|
+
useEffect(() => cancelTimer, [cancelTimer]);
|
|
76
|
+
const commitSearch = useCallback((value) => {
|
|
77
|
+
cancelTimer();
|
|
78
|
+
setSearch((s) => ({ ...s, pending: false }));
|
|
79
|
+
dispatch({ type: 'search', value });
|
|
80
|
+
}, [cancelTimer, dispatch]);
|
|
81
|
+
const setSearchInput = useCallback((value) => {
|
|
82
|
+
inputRef.current = value;
|
|
83
|
+
setSearch((s) => ({ ...s, input: value, pending: true }));
|
|
84
|
+
cancelTimer();
|
|
85
|
+
timer.current = setTimeout(() => commitSearch(value), SEARCH_DEBOUNCE_MS);
|
|
86
|
+
}, [cancelTimer, commitSearch]);
|
|
87
|
+
const flushSearch = useCallback(() => commitSearch(inputRef.current), [commitSearch]);
|
|
88
|
+
const clearSearch = useCallback(() => {
|
|
89
|
+
inputRef.current = '';
|
|
90
|
+
setSearch((s) => ({ ...s, input: '' }));
|
|
91
|
+
commitSearch('');
|
|
92
|
+
}, [commitSearch]);
|
|
93
|
+
// ---- draft filters: edited freely, applied only on demand ----
|
|
94
|
+
const [draftState, setDraftState] = useState({
|
|
95
|
+
values: query.filters,
|
|
96
|
+
errors: {},
|
|
97
|
+
seen: query.filters,
|
|
98
|
+
});
|
|
99
|
+
if (query.filters !== draftState.seen) {
|
|
100
|
+
const dirty = !filterValuesEqual(filters, draftState.values, draftState.seen);
|
|
101
|
+
setDraftState({
|
|
102
|
+
values: dirty ? draftState.values : query.filters,
|
|
103
|
+
errors: dirty ? draftState.errors : {},
|
|
104
|
+
seen: query.filters,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const draftRef = useRef(draftState);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
draftRef.current = draftState;
|
|
110
|
+
});
|
|
111
|
+
const draftSet = useCallback((id, value) => {
|
|
112
|
+
setDraftState((s) => {
|
|
113
|
+
const values = emptyFilterValues(Object.entries(s.values));
|
|
114
|
+
values[id] = value;
|
|
115
|
+
const errors = { ...s.errors };
|
|
116
|
+
delete errors[id];
|
|
117
|
+
return { ...s, values, errors };
|
|
118
|
+
});
|
|
119
|
+
}, []);
|
|
120
|
+
const draftApply = useCallback(() => {
|
|
121
|
+
const current = draftRef.current;
|
|
122
|
+
const errors = {};
|
|
123
|
+
for (const def of filters) {
|
|
124
|
+
const value = current.values[def.id];
|
|
125
|
+
if (isFilterValueEmpty(def, value))
|
|
126
|
+
continue;
|
|
127
|
+
const error = validateFilterValue(def, value);
|
|
128
|
+
if (error) {
|
|
129
|
+
errors[def.id] =
|
|
130
|
+
error.code === 'custom'
|
|
131
|
+
? (error.message ?? labels.filterErrors['invalid-option'])
|
|
132
|
+
: labels.filterErrors[error.code];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (Object.keys(errors).length > 0) {
|
|
136
|
+
setDraftState((s) => ({ ...s, errors }));
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
const applied = sanitizeFilterValues(filters, current.values);
|
|
140
|
+
setDraftState({ values: applied, errors: {}, seen: applied });
|
|
141
|
+
dispatch({ type: 'filters', value: applied });
|
|
142
|
+
return true;
|
|
143
|
+
}, [filters, labels, dispatch]);
|
|
144
|
+
const draftDiscard = useCallback(() => setDraftState({
|
|
145
|
+
values: queryRef.current.filters,
|
|
146
|
+
errors: {},
|
|
147
|
+
seen: queryRef.current.filters,
|
|
148
|
+
}), []);
|
|
149
|
+
const draftClear = useCallback(() => setDraftState((s) => ({ ...s, values: emptyFilterValues(), errors: {} })), []);
|
|
150
|
+
const isDirty = useMemo(() => !filterValuesEqual(filters, draftState.values, query.filters), [filters, draftState.values, query.filters]);
|
|
151
|
+
const draft = useMemo(() => ({
|
|
152
|
+
values: draftState.values,
|
|
153
|
+
errors: draftState.errors,
|
|
154
|
+
isDirty,
|
|
155
|
+
set: draftSet,
|
|
156
|
+
apply: draftApply,
|
|
157
|
+
discard: draftDiscard,
|
|
158
|
+
clear: draftClear,
|
|
159
|
+
}), [draftState, isDirty, draftSet, draftApply, draftDiscard, draftClear]);
|
|
160
|
+
// ---- immediate changes ----
|
|
161
|
+
const setQuickFilter = useCallback((id) => dispatch({ type: 'quickFilter', value: id }), [dispatch]);
|
|
162
|
+
const removeFilter = useCallback((id) => {
|
|
163
|
+
const next = emptyFilterValues(Object.entries(queryRef.current.filters).filter(([key]) => key !== id));
|
|
164
|
+
setDraftState((s) => {
|
|
165
|
+
const values = emptyFilterValues(Object.entries(s.values).filter(([key]) => key !== id));
|
|
166
|
+
return { ...s, values };
|
|
167
|
+
});
|
|
168
|
+
dispatch({ type: 'filters', value: next });
|
|
169
|
+
}, [dispatch]);
|
|
170
|
+
const clearFilters = useCallback(() => {
|
|
171
|
+
cancelTimer();
|
|
172
|
+
inputRef.current = '';
|
|
173
|
+
setSearch((s) => ({ ...s, input: '', pending: false }));
|
|
174
|
+
setDraftState((s) => ({ ...s, values: emptyFilterValues(), errors: {} }));
|
|
175
|
+
dispatch({ type: 'reset' });
|
|
176
|
+
}, [cancelTimer, dispatch]);
|
|
177
|
+
const clearFilterFields = useCallback(() => {
|
|
178
|
+
setDraftState((s) => ({ ...s, values: emptyFilterValues(), errors: {} }));
|
|
179
|
+
dispatch({ type: 'clearFilters' });
|
|
180
|
+
}, [dispatch]);
|
|
181
|
+
const setSort = useCallback((sort) => dispatch({ type: 'sort', value: sort }), [dispatch]);
|
|
182
|
+
const toggleSort = useCallback((columnId) => dispatch({
|
|
183
|
+
type: 'sort',
|
|
184
|
+
value: nextSort(queryRef.current.sort, columnId, defaultSort),
|
|
185
|
+
}), [dispatch, defaultSort]);
|
|
186
|
+
const setPage = useCallback((page) => dispatch({ type: 'page', value: page }), [dispatch]);
|
|
187
|
+
const setPageSize = useCallback((size) => {
|
|
188
|
+
if (isPageSize(size) && pageSizeOptions.includes(size))
|
|
189
|
+
dispatch({ type: 'pageSize', value: size });
|
|
190
|
+
}, [dispatch, pageSizeOptions]);
|
|
191
|
+
const setGroupBy = useCallback((id) => {
|
|
192
|
+
if (id === null && lockedGroup)
|
|
193
|
+
return;
|
|
194
|
+
if (id !== null && !groups.some((g) => g.id === id))
|
|
195
|
+
return;
|
|
196
|
+
dispatch({ type: 'group', value: id });
|
|
197
|
+
}, [dispatch, groups, lockedGroup]);
|
|
198
|
+
const clamp = useCallback((pageCount) => dispatch({ type: 'clamp', pageCount }), [dispatch]);
|
|
199
|
+
return {
|
|
200
|
+
query,
|
|
201
|
+
controlled,
|
|
202
|
+
searchInput: search.input,
|
|
203
|
+
setSearchInput,
|
|
204
|
+
flushSearch,
|
|
205
|
+
clearSearch,
|
|
206
|
+
draft,
|
|
207
|
+
setQuickFilter,
|
|
208
|
+
removeFilter,
|
|
209
|
+
clearFilters,
|
|
210
|
+
clearFilterFields,
|
|
211
|
+
setSort,
|
|
212
|
+
toggleSort,
|
|
213
|
+
setPage,
|
|
214
|
+
setPageSize,
|
|
215
|
+
setGroupBy,
|
|
216
|
+
clamp,
|
|
217
|
+
pageSizeOptions,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export { ClientDataTable } from './components/ClientDataTable.js';
|
|
2
|
+
export type { ClientDataTableProps } from './components/ClientDataTable.js';
|
|
3
|
+
export { ServerDataTable } from './components/ServerDataTable.js';
|
|
4
|
+
export type { ServerDataTableProps } from './components/ServerDataTable.js';
|
|
5
|
+
export { DataTableFooter } from './components/DataTableFooter.js';
|
|
6
|
+
export type { DataTableFooterProps } from './components/DataTableFooter.js';
|
|
7
|
+
export { DataTableToolbar } from './toolbar/DataTableToolbar.js';
|
|
8
|
+
export type { DataTableToolbarProps } from './toolbar/DataTableToolbar.js';
|
|
9
|
+
export { SearchField } from './toolbar/SearchField.js';
|
|
10
|
+
export type { SearchFieldProps } from './toolbar/SearchField.js';
|
|
11
|
+
export { QuickFilters } from './toolbar/QuickFilters.js';
|
|
12
|
+
export type { QuickFiltersProps } from './toolbar/QuickFilters.js';
|
|
13
|
+
export { ActiveFilters } from './toolbar/ActiveFilters.js';
|
|
14
|
+
export type { ActiveFiltersProps } from './toolbar/ActiveFilters.js';
|
|
15
|
+
export { FiltersControl, FilterPanel, FiltersDialog } from './toolbar/FiltersControl.js';
|
|
16
|
+
export type { FiltersControlProps, FilterPanelProps, FiltersDialogProps, } from './toolbar/FiltersControl.js';
|
|
17
|
+
export { SortSelect } from './toolbar/SortSelect.js';
|
|
18
|
+
export type { SortSelectProps } from './toolbar/SortSelect.js';
|
|
19
|
+
export { ColumnVisibilityDialog } from './toolbar/ColumnVisibilityDialog.js';
|
|
20
|
+
export type { ColumnVisibilityDialogProps } from './toolbar/ColumnVisibilityDialog.js';
|
|
21
|
+
export { BulkActionBar } from './toolbar/BulkActionBar.js';
|
|
22
|
+
export type { BulkActionBarProps } from './toolbar/BulkActionBar.js';
|
|
23
|
+
export { PageSizeSelect } from './toolbar/PageSizeSelect.js';
|
|
24
|
+
export type { PageSizeSelectProps } from './toolbar/PageSizeSelect.js';
|
|
25
|
+
export { ResultsCount } from './toolbar/ResultsCount.js';
|
|
26
|
+
export type { ResultsCountProps } from './toolbar/ResultsCount.js';
|
|
27
|
+
export { useClientDataTable } from './hooks/useClientDataTable.js';
|
|
28
|
+
export type { UseClientDataTableOptions } from './hooks/useClientDataTable.js';
|
|
29
|
+
export { useServerDataTable } from './hooks/useServerDataTable.js';
|
|
30
|
+
export type { UseServerDataTableOptions } from './hooks/useServerDataTable.js';
|
|
31
|
+
export { useServerRows, DataTableResponseError } from './hooks/useServerRows.js';
|
|
32
|
+
export type { FetchPage, ServerRowsData } from './hooks/useServerRows.js';
|
|
33
|
+
export { DEFAULT_DATA_TABLE_LABELS } from './labels.js';
|
|
34
|
+
export type { DataTableLabels } from './labels.js';
|
|
35
|
+
export { ALL_QUICK_FILTER, DEFAULT_PAGE_SIZE, LOADING_ANNOUNCE_DELAY_MS, MAX_PAGE_SIZE, PAGE_SIZE_OPTIONS, SEARCH_DEBOUNCE_MS, } from './core/constants.js';
|
|
36
|
+
export { createDefaultQuery } from './core/query.js';
|
|
37
|
+
export { parseTableQuery, serializeTableQuery, tableUrlKeys } from './core/url.js';
|
|
38
|
+
export type { ParsedTableQuery, TableUrlSchema, UrlIssue } from './core/url.js';
|
|
39
|
+
export { parseColumnVisibility } from './core/columnVisibility.js';
|
|
40
|
+
export { isCalendarDate, parseNumberInput } from './core/filters/registry.js';
|
|
41
|
+
export type { DateRangeValue, NumberRangeValue } from './core/filters/types.js';
|
|
42
|
+
export type { CellContext, ClientTableController, ColumnDef, ColumnVisibilityApi, ColumnVisibilityOptions, CustomFilterDef, DataTableRenderProps, DraftFilters, ExpansionApi, FilterDef, FilterOption, FilterOptionTone, FilterValues, GroupDef, HeaderCheckState, MobileSlot, PageGroup, PageSize, QueryChangeMeta, QuickFilterDef, RowId, RowModelOptions, RowSelectability, SelectionApi, ServerFilterDef, ServerPage, ServerTableController, SortDirection, SortState, TableA11y, TableController, TableQuery, TableStatus, } from './types.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { ClientDataTable } from './components/ClientDataTable.js';
|
|
2
|
+
export { ServerDataTable } from './components/ServerDataTable.js';
|
|
3
|
+
export { DataTableFooter } from './components/DataTableFooter.js';
|
|
4
|
+
export { DataTableToolbar } from './toolbar/DataTableToolbar.js';
|
|
5
|
+
export { SearchField } from './toolbar/SearchField.js';
|
|
6
|
+
export { QuickFilters } from './toolbar/QuickFilters.js';
|
|
7
|
+
export { ActiveFilters } from './toolbar/ActiveFilters.js';
|
|
8
|
+
export { FiltersControl, FilterPanel, FiltersDialog } from './toolbar/FiltersControl.js';
|
|
9
|
+
export { SortSelect } from './toolbar/SortSelect.js';
|
|
10
|
+
export { ColumnVisibilityDialog } from './toolbar/ColumnVisibilityDialog.js';
|
|
11
|
+
export { BulkActionBar } from './toolbar/BulkActionBar.js';
|
|
12
|
+
export { PageSizeSelect } from './toolbar/PageSizeSelect.js';
|
|
13
|
+
export { ResultsCount } from './toolbar/ResultsCount.js';
|
|
14
|
+
export { useClientDataTable } from './hooks/useClientDataTable.js';
|
|
15
|
+
export { useServerDataTable } from './hooks/useServerDataTable.js';
|
|
16
|
+
export { useServerRows, DataTableResponseError } from './hooks/useServerRows.js';
|
|
17
|
+
export { DEFAULT_DATA_TABLE_LABELS } from './labels.js';
|
|
18
|
+
export { ALL_QUICK_FILTER, DEFAULT_PAGE_SIZE, LOADING_ANNOUNCE_DELAY_MS, MAX_PAGE_SIZE, PAGE_SIZE_OPTIONS, SEARCH_DEBOUNCE_MS, } from './core/constants.js';
|
|
19
|
+
export { createDefaultQuery } from './core/query.js';
|
|
20
|
+
export { parseTableQuery, serializeTableQuery, tableUrlKeys } from './core/url.js';
|
|
21
|
+
export { parseColumnVisibility } from './core/columnVisibility.js';
|
|
22
|
+
export { isCalendarDate, parseNumberInput } from './core/filters/registry.js';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { PaginationLabels } from '../components/Pagination.js';
|
|
2
|
+
import type { FilterErrorCode } from './core/types.js';
|
|
3
|
+
import type { SortDirection } from './core/types.js';
|
|
4
|
+
/** Every user-facing string of the data tables (Spanish, sentence case). */
|
|
5
|
+
export interface DataTableLabels {
|
|
6
|
+
search: string;
|
|
7
|
+
searchClear: string;
|
|
8
|
+
filters: string;
|
|
9
|
+
/** Accessible name of the filters button while `n` filters are applied. */
|
|
10
|
+
filtersWithCount: (n: number) => string;
|
|
11
|
+
/** First option of select filters (no filter). */
|
|
12
|
+
anyOption: string;
|
|
13
|
+
applyFilters: string;
|
|
14
|
+
clearFilters: string;
|
|
15
|
+
unappliedChanges: string;
|
|
16
|
+
activeFilters: string;
|
|
17
|
+
removeFilter: (chip: string) => string;
|
|
18
|
+
quickFilters: string;
|
|
19
|
+
results: (n: number) => string;
|
|
20
|
+
range: (from: number, to: number, total: number) => string;
|
|
21
|
+
pageSize: string;
|
|
22
|
+
sortBy: string;
|
|
23
|
+
sortOption: (header: string, direction: SortDirection) => string;
|
|
24
|
+
sortDefault: string;
|
|
25
|
+
sortedAnnouncement: (header: string, direction: SortDirection) => string;
|
|
26
|
+
groupBy: string;
|
|
27
|
+
noGrouping: string;
|
|
28
|
+
columns: string;
|
|
29
|
+
columnsDescription: string;
|
|
30
|
+
resetColumns: string;
|
|
31
|
+
done: string;
|
|
32
|
+
close: string;
|
|
33
|
+
/** Visible labels of the range fields. */
|
|
34
|
+
from: string;
|
|
35
|
+
to: string;
|
|
36
|
+
min: string;
|
|
37
|
+
max: string;
|
|
38
|
+
yes: string;
|
|
39
|
+
rangeFrom: (value: string) => string;
|
|
40
|
+
rangeTo: (value: string) => string;
|
|
41
|
+
rangeBetween: (from: string, to: string) => string;
|
|
42
|
+
filterErrors: Record<Exclude<FilterErrorCode, 'custom'>, string>;
|
|
43
|
+
selectRow: (rowLabel: string) => string;
|
|
44
|
+
/** Header checkbox, client table: scope is every result across pages. */
|
|
45
|
+
selectAllResults: (n: number) => string;
|
|
46
|
+
/** Header checkbox, server table: scope is the current page. */
|
|
47
|
+
selectPage: (n: number) => string;
|
|
48
|
+
selectAll: string;
|
|
49
|
+
selected: (n: number) => string;
|
|
50
|
+
selectedHidden: (k: number) => string;
|
|
51
|
+
notSelectable: (k: number) => string;
|
|
52
|
+
clearSelection: string;
|
|
53
|
+
showSelected: string;
|
|
54
|
+
selectionPruned: (n: number) => string;
|
|
55
|
+
bulkActions: string;
|
|
56
|
+
expand: (rowLabel: string) => string;
|
|
57
|
+
collapse: (rowLabel: string) => string;
|
|
58
|
+
detailOf: (rowLabel: string) => string;
|
|
59
|
+
showDetail: string;
|
|
60
|
+
hideDetail: string;
|
|
61
|
+
rowActions: string;
|
|
62
|
+
selectColumn: string;
|
|
63
|
+
expandColumn: string;
|
|
64
|
+
groupContinues: string;
|
|
65
|
+
groupRows: (n: number) => string;
|
|
66
|
+
loading: string;
|
|
67
|
+
refreshing: string;
|
|
68
|
+
error: string;
|
|
69
|
+
refreshError: string;
|
|
70
|
+
retry: string;
|
|
71
|
+
emptyTitle: string;
|
|
72
|
+
noResultsTitle: string;
|
|
73
|
+
noResultsDescription: string;
|
|
74
|
+
pagination?: Partial<PaginationLabels>;
|
|
75
|
+
}
|
|
76
|
+
export declare const DEFAULT_DATA_TABLE_LABELS: DataTableLabels;
|
|
77
|
+
export declare function mergeLabels(labels?: Partial<DataTableLabels>): DataTableLabels;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
2
|
+
const nf = new Intl.NumberFormat('es');
|
|
3
|
+
export const DEFAULT_DATA_TABLE_LABELS = {
|
|
4
|
+
search: 'Buscar',
|
|
5
|
+
searchClear: 'Limpiar búsqueda',
|
|
6
|
+
filters: 'Filtros',
|
|
7
|
+
filtersWithCount: (n) => `Filtros, ${n} ${n === 1 ? 'activo' : 'activos'}`,
|
|
8
|
+
anyOption: 'Todos',
|
|
9
|
+
applyFilters: 'Aplicar filtros',
|
|
10
|
+
clearFilters: 'Limpiar filtros',
|
|
11
|
+
unappliedChanges: 'Tienes cambios sin aplicar.',
|
|
12
|
+
activeFilters: 'Filtros activos',
|
|
13
|
+
removeFilter: (chip) => `Quitar filtro ${chip}`,
|
|
14
|
+
quickFilters: 'Filtrar resultados',
|
|
15
|
+
results: (n) => plural(n, 'resultado', 'resultados'),
|
|
16
|
+
range: (from, to, total) => `Mostrando ${from}–${to} de ${nf.format(total)}`,
|
|
17
|
+
pageSize: 'Filas por página',
|
|
18
|
+
sortBy: 'Ordenar por',
|
|
19
|
+
sortOption: (header, direction) => `${header} (${direction === 'ascending' ? 'ascendente' : 'descendente'})`,
|
|
20
|
+
sortDefault: 'Orden predeterminado',
|
|
21
|
+
sortedAnnouncement: (header, direction) => `Ordenado por ${header}, ${direction === 'ascending' ? 'ascendente' : 'descendente'}`,
|
|
22
|
+
groupBy: 'Agrupar por',
|
|
23
|
+
noGrouping: 'Sin agrupar',
|
|
24
|
+
columns: 'Columnas',
|
|
25
|
+
columnsDescription: 'Elige las columnas que quieres ver.',
|
|
26
|
+
resetColumns: 'Restablecer columnas',
|
|
27
|
+
done: 'Listo',
|
|
28
|
+
close: 'Cerrar',
|
|
29
|
+
from: 'Desde',
|
|
30
|
+
to: 'Hasta',
|
|
31
|
+
min: 'Mínimo',
|
|
32
|
+
max: 'Máximo',
|
|
33
|
+
yes: 'Sí',
|
|
34
|
+
rangeFrom: (value) => `Desde ${value}`,
|
|
35
|
+
rangeTo: (value) => `Hasta ${value}`,
|
|
36
|
+
rangeBetween: (from, to) => `${from} a ${to}`,
|
|
37
|
+
filterErrors: {
|
|
38
|
+
'invalid-number': 'Escribe un número válido, por ejemplo 1500 o 1500,50.',
|
|
39
|
+
'invalid-date': 'Escribe una fecha válida.',
|
|
40
|
+
'invalid-range': 'El valor inicial no puede ser mayor que el final.',
|
|
41
|
+
'out-of-bounds': 'El valor está fuera del rango permitido.',
|
|
42
|
+
'too-long': 'El valor es demasiado largo.',
|
|
43
|
+
'invalid-option': 'Elige una opción de la lista.',
|
|
44
|
+
},
|
|
45
|
+
selectRow: (rowLabel) => `Seleccionar ${rowLabel}`,
|
|
46
|
+
selectAllResults: (n) => `Seleccionar todo (${plural(n, 'resultado', 'resultados')})`,
|
|
47
|
+
selectPage: (n) => `Seleccionar las ${n} filas de esta página`,
|
|
48
|
+
selectAll: 'Seleccionar todo',
|
|
49
|
+
selected: (n) => plural(n, 'seleccionado', 'seleccionados'),
|
|
50
|
+
selectedHidden: (k) => `${k} no se muestran con los filtros actuales`,
|
|
51
|
+
notSelectable: (k) => k === 1 ? '1 fila no se puede seleccionar' : `${k} filas no se pueden seleccionar`,
|
|
52
|
+
clearSelection: 'Limpiar selección',
|
|
53
|
+
showSelected: 'Ver seleccionados',
|
|
54
|
+
selectionPruned: (n) => `${plural(n, 'elemento quitado', 'elementos quitados')} de la selección.`,
|
|
55
|
+
bulkActions: 'Acciones sobre la selección',
|
|
56
|
+
expand: (rowLabel) => `Ver detalle de ${rowLabel}`,
|
|
57
|
+
collapse: (rowLabel) => `Ocultar detalle de ${rowLabel}`,
|
|
58
|
+
detailOf: (rowLabel) => `Detalle de ${rowLabel}`,
|
|
59
|
+
showDetail: 'Ver detalle',
|
|
60
|
+
hideDetail: 'Ocultar detalle',
|
|
61
|
+
rowActions: 'Acciones',
|
|
62
|
+
selectColumn: 'Selección',
|
|
63
|
+
expandColumn: 'Detalle',
|
|
64
|
+
groupContinues: '(continúa)',
|
|
65
|
+
groupRows: (n) => plural(n, 'fila', 'filas'),
|
|
66
|
+
loading: 'Cargando…',
|
|
67
|
+
refreshing: 'Actualizando…',
|
|
68
|
+
error: 'No se pudo cargar la información.',
|
|
69
|
+
refreshError: 'No se pudo actualizar. Se muestran los datos anteriores.',
|
|
70
|
+
retry: 'Reintentar',
|
|
71
|
+
emptyTitle: 'Aún no hay registros.',
|
|
72
|
+
noResultsTitle: 'Sin resultados',
|
|
73
|
+
noResultsDescription: 'Ningún registro coincide con los filtros o la búsqueda.',
|
|
74
|
+
};
|
|
75
|
+
export function mergeLabels(labels) {
|
|
76
|
+
return labels ? { ...DEFAULT_DATA_TABLE_LABELS, ...labels } : DEFAULT_DATA_TABLE_LABELS;
|
|
77
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TableController } from '../types.js';
|
|
2
|
+
export interface ActiveFiltersProps<TRow> {
|
|
3
|
+
table: TableController<TRow>;
|
|
4
|
+
className?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Applied filters as removable chips plus "Limpiar filtros". Removing a chip focuses the next
|
|
8
|
+
* chip, else the previous one, else the "Filtros" trigger (or the search field).
|
|
9
|
+
*/
|
|
10
|
+
export declare function ActiveFilters<TRow>({ table, className }: ActiveFiltersProps<TRow>): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { Button } from '../../components/Button.js';
|
|
4
|
+
import { Chip } from '../../components/Chip.js';
|
|
5
|
+
import { cx } from '../../utils/cx.js';
|
|
6
|
+
/**
|
|
7
|
+
* Applied filters as removable chips plus "Limpiar filtros". Removing a chip focuses the next
|
|
8
|
+
* chip, else the previous one, else the "Filtros" trigger (or the search field).
|
|
9
|
+
*/
|
|
10
|
+
export function ActiveFilters({ table, className }) {
|
|
11
|
+
const { activeFilters: chips, labels, a11y } = table;
|
|
12
|
+
const refs = useRef(new Map());
|
|
13
|
+
const pending = useRef(null);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const job = pending.current;
|
|
16
|
+
if (!job)
|
|
17
|
+
return;
|
|
18
|
+
if (job.kind === 'clear') {
|
|
19
|
+
if (chips.length > 0)
|
|
20
|
+
return;
|
|
21
|
+
pending.current = null;
|
|
22
|
+
if (!a11y.focusTarget('filters'))
|
|
23
|
+
a11y.focusTarget('search');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (chips.some((chip) => chip.id === job.removedId))
|
|
27
|
+
return;
|
|
28
|
+
pending.current = null;
|
|
29
|
+
const next = job.focusId ? refs.current.get(job.focusId) : undefined;
|
|
30
|
+
if (next)
|
|
31
|
+
next.focus();
|
|
32
|
+
else if (!a11y.focusTarget('filters'))
|
|
33
|
+
a11y.focusTarget('search');
|
|
34
|
+
});
|
|
35
|
+
if (chips.length === 0)
|
|
36
|
+
return null;
|
|
37
|
+
return (_jsxs("div", { className: cx('faast-dt__active', className), children: [_jsx("ul", { className: "faast-dt__active-list", "aria-label": labels.activeFilters, children: chips.map((chip, index) => (_jsx("li", { children: _jsx(Chip, { ref: (element) => {
|
|
38
|
+
if (element)
|
|
39
|
+
refs.current.set(chip.id, element);
|
|
40
|
+
else
|
|
41
|
+
refs.current.delete(chip.id);
|
|
42
|
+
}, removable: true, label: chip.text, "aria-label": labels.removeFilter(chip.text), onClick: () => {
|
|
43
|
+
pending.current = {
|
|
44
|
+
kind: 'chip',
|
|
45
|
+
removedId: chip.id,
|
|
46
|
+
focusId: chips[index + 1]?.id ?? chips[index - 1]?.id ?? null,
|
|
47
|
+
};
|
|
48
|
+
table.removeFilter(chip.id);
|
|
49
|
+
} }) }, chip.id))) }), _jsx(Button, { variant: "ghost", onClick: () => {
|
|
50
|
+
pending.current = { kind: 'clear' };
|
|
51
|
+
table.clearFilters();
|
|
52
|
+
}, children: labels.clearFilters })] }));
|
|
53
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { SelectionApi, TableController } from '../types.js';
|
|
3
|
+
export interface BulkActionBarProps<TRow> {
|
|
4
|
+
table: TableController<TRow>;
|
|
5
|
+
/** Bulk actions; they always receive the full selection (`selectedRows`, `selectedIds`). */
|
|
6
|
+
children?: (selection: SelectionApi<TRow>) => ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Selection summary and bulk actions. Client tables: "12 de 230 seleccionados" and, when a
|
|
11
|
+
* filter hides some of them, "3 no se muestran con los filtros actuales" with "Ver
|
|
12
|
+
* seleccionados". Server tables: "12 seleccionados" (page scope). Sticky at the bottom on
|
|
13
|
+
* phones (safe-area aware). It is announced, not focused, when it appears.
|
|
14
|
+
*/
|
|
15
|
+
export declare function BulkActionBar<TRow>({ table, children, className }: BulkActionBarProps<TRow>): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from '../../components/Button.js';
|
|
3
|
+
import { cx } from '../../utils/cx.js';
|
|
4
|
+
/**
|
|
5
|
+
* Selection summary and bulk actions. Client tables: "12 de 230 seleccionados" and, when a
|
|
6
|
+
* filter hides some of them, "3 no se muestran con los filtros actuales" with "Ver
|
|
7
|
+
* seleccionados". Server tables: "12 seleccionados" (page scope). Sticky at the bottom on
|
|
8
|
+
* phones (safe-area aware). It is announced, not focused, when it appears.
|
|
9
|
+
*/
|
|
10
|
+
export function BulkActionBar({ table, children, className }) {
|
|
11
|
+
const { selection, labels } = table;
|
|
12
|
+
if (!selection)
|
|
13
|
+
return null;
|
|
14
|
+
const count = selection.selectedCount;
|
|
15
|
+
const hasSelection = count > 0;
|
|
16
|
+
const allSelected = selection.header.state === 'all';
|
|
17
|
+
return (_jsxs("div", { className: cx('faast-dt__bulk', hasSelection && 'faast-dt__bulk--active', className), role: "region", "aria-label": labels.bulkActions, children: [!allSelected && selection.scopeCount > 0 && (_jsx(Button, { variant: "secondary", className: "faast-dt__select-all", onClick: selection.selectAll, children: selection.scope === 'page' ? labels.selectPage(selection.scopeCount) : labels.selectAll })), hasSelection && (_jsxs(_Fragment, { children: [_jsxs("p", { className: "faast-dt__bulk-text", children: [_jsx("span", { className: "faast-num", children: labels.selected(count) }), selection.hiddenCount > 0 && (_jsxs("span", { className: "faast-dt__bulk-hidden", children: [' · ', labels.selectedHidden(selection.hiddenCount)] }))] }), selection.hiddenCount > 0 && (_jsx(Button, { variant: "ghost", onClick: selection.showSelected, children: labels.showSelected })), _jsx("div", { className: "faast-dt__bulk-actions", children: children?.(selection) }), _jsx(Button, { variant: "ghost", onClick: () => {
|
|
18
|
+
selection.clear();
|
|
19
|
+
if (!table.a11y.focusTarget('selectAll'))
|
|
20
|
+
table.a11y.focusTable();
|
|
21
|
+
}, children: labels.clearSelection })] }))] }));
|
|
22
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TableController } from '../types.js';
|
|
2
|
+
export interface ColumnVisibilityDialogProps<TRow> {
|
|
3
|
+
table: TableController<TRow>;
|
|
4
|
+
className?: string;
|
|
5
|
+
}
|
|
6
|
+
/** "Columnas" button and dialog to show or hide columns. Focus returns to the button. */
|
|
7
|
+
export declare function ColumnVisibilityDialog<TRow>({ table, className, }: ColumnVisibilityDialogProps<TRow>): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Button } from '../../components/Button.js';
|
|
4
|
+
import { Checkbox } from '../../components/Choice.js';
|
|
5
|
+
import { Dialog } from '../../components/Dialog.js';
|
|
6
|
+
import { Icon } from '../../components/Icon.js';
|
|
7
|
+
import { cx } from '../../utils/cx.js';
|
|
8
|
+
/** "Columnas" button and dialog to show or hide columns. Focus returns to the button. */
|
|
9
|
+
export function ColumnVisibilityDialog({ table, className, }) {
|
|
10
|
+
const [open, setOpen] = useState(false);
|
|
11
|
+
const { labels, columnVisibility: visibility } = table;
|
|
12
|
+
if (visibility.hideableColumns.length === 0)
|
|
13
|
+
return null;
|
|
14
|
+
return (_jsxs("div", { className: cx('faast-dt__columns', className), children: [_jsx(Button, { variant: "secondary", leadingIcon: _jsx(Icon, { name: "columns-3-cog", size: 16 }), "aria-haspopup": "dialog", onClick: () => setOpen(true), children: labels.columns }), _jsx(Dialog, { open: open, onClose: () => setOpen(false), title: labels.columns, description: labels.columnsDescription, size: "sm", closeLabel: labels.close, footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: visibility.reset, children: labels.resetColumns }), _jsx(Button, { variant: "primary", onClick: () => setOpen(false), children: labels.done })] }), children: _jsx("div", { className: "faast-dt__options-list", children: visibility.hideableColumns.map((column) => (_jsx(Checkbox, { label: column.header, checked: !visibility.isHidden(column.id), onChange: () => visibility.toggle(column.id) }, column.id))) }) })] }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface DataTableToolbarProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
/**
|
|
5
|
+
* The search field takes all the free width and the other controls (Filtros, sort,
|
|
6
|
+
* columns) sit at its right, instead of a fixed 240px search. Use it for a toolbar that
|
|
7
|
+
* only holds a search and a filters button (a search card). Default `false`.
|
|
8
|
+
*/
|
|
9
|
+
searchGrow?: boolean;
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Layout of the controls above a table (quick filters, search, filters button, sort, columns).
|
|
14
|
+
* It owns the spacing: items sit in a row with a consistent gap. From 900px everything is one
|
|
15
|
+
* row (quick filter chips take the free width and scroll sideways, then your switch, then a
|
|
16
|
+
* 240px search); below it the chips are one scrolling line and the search is full width under
|
|
17
|
+
* them. Apps do not add margins between the controls.
|
|
18
|
+
*/
|
|
19
|
+
export declare function DataTableToolbar({ children, searchGrow, className, }: DataTableToolbarProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from '../../utils/cx.js';
|
|
3
|
+
/**
|
|
4
|
+
* Layout of the controls above a table (quick filters, search, filters button, sort, columns).
|
|
5
|
+
* It owns the spacing: items sit in a row with a consistent gap. From 900px everything is one
|
|
6
|
+
* row (quick filter chips take the free width and scroll sideways, then your switch, then a
|
|
7
|
+
* 240px search); below it the chips are one scrolling line and the search is full width under
|
|
8
|
+
* them. Apps do not add margins between the controls.
|
|
9
|
+
*/
|
|
10
|
+
export function DataTableToolbar({ children, searchGrow = false, className, }) {
|
|
11
|
+
return (_jsx("div", { className: cx('faast-dt__toolbar', searchGrow && 'faast-dt__toolbar--search-grow', className), children: children }));
|
|
12
|
+
}
|