@tangible/ui 0.2.10 → 0.2.12
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 +35 -22
- package/components/Accordion/Accordion.js +2 -2
- package/components/Combobox/Combobox.js +37 -5
- package/components/Combobox/types.d.ts +6 -0
- package/components/DatePicker/DatePicker.d.ts +3 -0
- package/components/DatePicker/DatePicker.js +8 -2
- package/components/DatePicker/DateRangePicker.d.ts +3 -0
- package/components/DatePicker/DateRangePicker.js +8 -2
- package/components/DatePicker/types.d.ts +36 -0
- package/components/Dropdown/Dropdown.js +2 -1
- package/components/MultiCombobox/MultiCombobox.js +1 -1
- package/components/MultiSelect/MultiSelect.d.ts +1 -1
- package/components/MultiSelect/MultiSelect.js +29 -5
- package/components/MultiSelect/types.d.ts +13 -0
- package/components/Pager/Pager.d.ts +65 -1
- package/components/Pager/Pager.js +83 -10
- package/components/Pager/index.d.ts +1 -1
- package/components/Pager/types.d.ts +39 -0
- package/components/Pager/types.js +6 -0
- package/components/Popover/Popover.js +2 -1
- package/components/SearchSelect/SearchSelect.d.ts +1 -1
- package/components/SearchSelect/SearchSelect.js +3 -5
- package/components/SearchSelect/types.d.ts +0 -2
- package/components/Select/Select.d.ts +1 -1
- package/components/Select/Select.js +29 -5
- package/components/Select/types.d.ts +13 -0
- package/components/Table/DataTable.d.ts +49 -3
- package/components/Table/DataTable.js +83 -4
- package/components/Textarea/Textarea.js +7 -0
- package/components/Tooltip/Tooltip.js +2 -1
- package/components/index.d.ts +2 -2
- package/components/index.js +1 -1
- package/figma-tokens.json +4018 -0
- package/icons/icons.svg +12 -2
- package/icons/lms/index.d.ts +12 -0
- package/icons/lms/index.js +83 -17
- package/icons/manifest.json +80 -0
- package/icons/membersync/index.js +9 -9
- package/icons/player/index.js +4 -4
- package/icons/reaction/index.js +4 -4
- package/icons/registry.d.ts +20 -0
- package/icons/registry.js +10 -0
- package/icons/system/index.d.ts +8 -0
- package/icons/system/index.js +65 -21
- package/package.json +5 -1
- package/skills/building-with-tui/SKILL.md +328 -0
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +160 -269
- package/styles/all.expanded.unlayered.css +160 -269
- package/styles/all.unlayered.css +1 -1
- package/styles/components/color-picker.scss +16 -3
- package/styles/components/combobox.scss +33 -58
- package/styles/components/date-picker.scss +18 -10
- package/styles/components/dropdown.scss +12 -7
- package/styles/components/gradient-picker.scss +4 -4
- package/styles/components/multi-combobox.scss +17 -37
- package/styles/components/multi-select.scss +14 -50
- package/styles/components/pager.scss +155 -17
- package/styles/components/progress.scss +1 -1
- package/styles/components/radio.scss +37 -0
- package/styles/components/search-select.scss +16 -38
- package/styles/components/segmented-control.scss +1 -1
- package/styles/components/select.scss +22 -51
- package/styles/components/sidebar.scss +8 -3
- package/styles/components/slider.scss +1 -1
- package/styles/components/table.scss +3 -1
- package/styles/components/tabs.scss +1 -1
- package/styles/components/text-input.scss +79 -21
- package/styles/core.css +1 -1
- package/styles/core.unlayered.css +1 -1
- package/styles/system/_constants.scss +7 -1
- package/styles/system/_tokens.scss +2 -2
- package/tui-manifest.json +144 -6
- package/utils/compose-refs.d.ts +29 -3
- package/utils/compose-refs.js +51 -12
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { cx } from '../../utils/cx.js';
|
|
4
|
+
import { isDev } from '../../utils/is-dev.js';
|
|
4
5
|
import { useReactTable, getCoreRowModel, getSortedRowModel, getPaginationRowModel, flexRender } from '@tanstack/react-table';
|
|
5
6
|
import { BulkActionsBar } from './BulkActionsBar.js';
|
|
6
7
|
import { Pagination } from './Pagination.js';
|
|
7
8
|
import { defaultDataTableLabels } from './types.js';
|
|
8
|
-
|
|
9
|
+
// ^ Remaining props (role, data-*, handlers) spread onto the <table> element —
|
|
10
|
+
// enables role="grid" for consumer-owned row cursors and data-testid targeting.
|
|
11
|
+
// id/className/aria-label/aria-labelledby/aria-busy stay component-owned
|
|
12
|
+
// (declared after the spread; className styles the scroll container).
|
|
13
|
+
export function DataTable({ data, columns, className, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, defaultSorting = [], loading = false, loadingMessage = 'Loading...', emptyMessage = 'No results', labels: labelsProp, getRowProps, renderPagination, paginationMode = 'smart', paginationMaxNumbers = 7, paginationNavStyle = 'text', pageSizeOptions = [10, 20, 50], initialPageSize, pageIndex: pageIndexProp, onPageIndexChange, autoResetPageIndex,
|
|
9
14
|
// selection
|
|
10
|
-
enableRowSelection = false, getRowId, getRowLabelForSelection, onSelectionChange, renderBulkBar, rowSelection, onRowSelectionChange, }) {
|
|
15
|
+
enableRowSelection = false, getRowId, getRowLabelForSelection, onSelectionChange, renderBulkBar, rowSelection, onRowSelectionChange, ...rest }) {
|
|
11
16
|
const labels = React.useMemo(() => ({ ...defaultDataTableLabels, ...labelsProp }), [labelsProp]);
|
|
12
17
|
const tableId = React.useId();
|
|
13
18
|
const [sorting, setSorting] = React.useState(defaultSorting);
|
|
@@ -23,6 +28,65 @@ enableRowSelection = false, getRowId, getRowLabelForSelection, onSelectionChange
|
|
|
23
28
|
onRowSelectionChange?.(updater);
|
|
24
29
|
}, [isSelectionControlled, onRowSelectionChange]);
|
|
25
30
|
const defaultPageSize = initialPageSize ?? pageSizeOptions[0] ?? 10;
|
|
31
|
+
// Pagination state lives here (not in TanStack's internal store) so pageIndex
|
|
32
|
+
// can be controlled. Controlled/uncontrolled is locked at mount — see the
|
|
33
|
+
// "controlled→uncontrolled mode switch" gotcha; `pageIndex` flipping to
|
|
34
|
+
// undefined mid-flight must not silently hand control back. (Selection above
|
|
35
|
+
// checks per-render instead: `rowSelection` never legitimately becomes
|
|
36
|
+
// undefined the way a cleared value does.)
|
|
37
|
+
const isPageIndexControlled = React.useRef(pageIndexProp !== undefined).current;
|
|
38
|
+
const [internalPagination, setInternalPagination] = React.useState({
|
|
39
|
+
pageIndex: 0,
|
|
40
|
+
pageSize: defaultPageSize,
|
|
41
|
+
});
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (isDev() && isPageIndexControlled !== (pageIndexProp !== undefined)) {
|
|
44
|
+
console.warn('DataTable: pageIndex switched between controlled and uncontrolled after mount. ' +
|
|
45
|
+
'The mode is locked at mount; the switch is ignored.');
|
|
46
|
+
}
|
|
47
|
+
}, [isPageIndexControlled, pageIndexProp]);
|
|
48
|
+
// Clamp the index into range. An out-of-range controlled value (a persisted
|
|
49
|
+
// URL param against a shrunk dataset) would otherwise render a fake
|
|
50
|
+
// "No results" with no pager and no callback — an unrecoverable dead table.
|
|
51
|
+
// No filter row model exists, so the row count is data.length.
|
|
52
|
+
const pageSize = internalPagination.pageSize;
|
|
53
|
+
const maxPageIndex = Math.max(0, Math.ceil(data.length / pageSize) - 1);
|
|
54
|
+
const requestedPageIndex = isPageIndexControlled
|
|
55
|
+
? (pageIndexProp ?? 0)
|
|
56
|
+
: internalPagination.pageIndex;
|
|
57
|
+
const effectivePageIndex = Math.min(requestedPageIndex, maxPageIndex);
|
|
58
|
+
const paginationState = {
|
|
59
|
+
pageIndex: effectivePageIndex,
|
|
60
|
+
pageSize,
|
|
61
|
+
};
|
|
62
|
+
const onPageIndexChangeRef = React.useRef(onPageIndexChange);
|
|
63
|
+
onPageIndexChangeRef.current = onPageIndexChange;
|
|
64
|
+
// Tell a controlled parent its index was clamped so its state can converge.
|
|
65
|
+
React.useEffect(() => {
|
|
66
|
+
if (isPageIndexControlled && effectivePageIndex !== requestedPageIndex) {
|
|
67
|
+
onPageIndexChangeRef.current?.(effectivePageIndex);
|
|
68
|
+
}
|
|
69
|
+
}, [isPageIndexControlled, effectivePageIndex, requestedPageIndex]);
|
|
70
|
+
// Resolve updaters against a ref, not the render closure: two updates in one
|
|
71
|
+
// React batch (nextPage ×2, or setPageSize + setPageIndex) must compose
|
|
72
|
+
// instead of both resolving against the same stale base — TanStack's own
|
|
73
|
+
// functional setState did this for free before the state was hoisted here.
|
|
74
|
+
// In controlled mode the in-tick composition tracks the *requested* index
|
|
75
|
+
// (optimistic); the per-render resync below snaps back to the prop.
|
|
76
|
+
const paginationRef = React.useRef(paginationState);
|
|
77
|
+
paginationRef.current = paginationState;
|
|
78
|
+
const handlePaginationChange = React.useCallback((updater) => {
|
|
79
|
+
const base = paginationRef.current;
|
|
80
|
+
const next = typeof updater === 'function'
|
|
81
|
+
? updater(base)
|
|
82
|
+
: updater;
|
|
83
|
+
paginationRef.current = next;
|
|
84
|
+
// pageSize is always internal; pageIndex only when uncontrolled.
|
|
85
|
+
setInternalPagination((prev) => isPageIndexControlled ? { ...prev, pageSize: next.pageSize } : next);
|
|
86
|
+
if (next.pageIndex !== base.pageIndex) {
|
|
87
|
+
onPageIndexChangeRef.current?.(next.pageIndex);
|
|
88
|
+
}
|
|
89
|
+
}, [isPageIndexControlled]);
|
|
26
90
|
// build columns, inject selection column only when enabled
|
|
27
91
|
const selectionColumn = React.useMemo(() => ({
|
|
28
92
|
id: '__select',
|
|
@@ -89,9 +153,11 @@ enableRowSelection = false, getRowId, getRowLabelForSelection, onSelectionChange
|
|
|
89
153
|
state: {
|
|
90
154
|
sorting,
|
|
91
155
|
rowSelection: rowSelectionState,
|
|
156
|
+
pagination: paginationState,
|
|
92
157
|
},
|
|
93
158
|
onSortingChange: setSorting,
|
|
94
159
|
onRowSelectionChange: handleRowSelectionChange,
|
|
160
|
+
onPaginationChange: handlePaginationChange,
|
|
95
161
|
getCoreRowModel: getCoreRowModel(),
|
|
96
162
|
getSortedRowModel: getSortedRowModel(),
|
|
97
163
|
getPaginationRowModel: getPaginationRowModel(),
|
|
@@ -99,8 +165,14 @@ enableRowSelection = false, getRowId, getRowLabelForSelection, onSelectionChange
|
|
|
99
165
|
? (row, index) => String(getRowId(row, index))
|
|
100
166
|
: undefined, // may be undefined, tanstack handles it
|
|
101
167
|
enableRowSelection,
|
|
168
|
+
autoResetPageIndex: autoResetPageIndex ?? !isPageIndexControlled,
|
|
169
|
+
// initialState is NOT redundant with state.pagination: TanStack's reset
|
|
170
|
+
// helpers (resetPagination/resetPageSize/table.reset) read their defaults
|
|
171
|
+
// back from initialState — without it they'd snap pageSize to a hardcoded
|
|
172
|
+
// 10 that may not even be in pageSizeOptions.
|
|
102
173
|
initialState: {
|
|
103
174
|
pagination: {
|
|
175
|
+
pageIndex: 0,
|
|
104
176
|
pageSize: defaultPageSize,
|
|
105
177
|
},
|
|
106
178
|
},
|
|
@@ -165,7 +237,7 @@ enableRowSelection = false, getRowId, getRowLabelForSelection, onSelectionChange
|
|
|
165
237
|
selectedRowIds,
|
|
166
238
|
clearSelection: () => table.resetRowSelection(),
|
|
167
239
|
selectedCount
|
|
168
|
-
})) : (_jsx(BulkActionsBar, { count: selectedCount, onClear: () => table.resetRowSelection(), "aria-controls": tableId }))), _jsxs("table", { id: tableId, className: "tui-table", "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-busy": loading || undefined, children: [_jsx("thead", { className: "tui-table__head", children: table.getHeaderGroups().map((headerGroup) => (_jsx("tr", { className: "tui-table__row tui-table__row--head", children: headerGroup.headers.map((header) => {
|
|
240
|
+
})) : (_jsx(BulkActionsBar, { count: selectedCount, onClear: () => table.resetRowSelection(), "aria-controls": tableId }))), _jsxs("table", { ...rest, id: tableId, className: "tui-table", "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-busy": loading || undefined, children: [_jsx("thead", { className: "tui-table__head", children: table.getHeaderGroups().map((headerGroup) => (_jsx("tr", { className: "tui-table__row tui-table__row--head", children: headerGroup.headers.map((header) => {
|
|
169
241
|
const canSort = header.column.getCanSort();
|
|
170
242
|
const sortDirection = header.column.getIsSorted();
|
|
171
243
|
const headerDef = header.column.columnDef.header;
|
|
@@ -183,7 +255,14 @@ enableRowSelection = false, getRowId, getRowLabelForSelection, onSelectionChange
|
|
|
183
255
|
: sortDirection === 'desc'
|
|
184
256
|
? '▼'
|
|
185
257
|
: '' })] })) : (headerContent) }, header.id));
|
|
186
|
-
}) }, headerGroup.id))) }), _jsx("tbody", { className: "tui-table__body", children: loading ? (_jsx("tr", { className: "tui-table__row tui-table__row--loading", children: _jsx("td", { className: "tui-table__cell tui-table__cell--body", colSpan: table.getAllLeafColumns().length, children: loadingMessage }) })) : isEmpty ? (_jsx("tr", { className: "tui-table__row tui-table__row--empty", children: _jsx("td", { className: "tui-table__cell tui-table__cell--body", colSpan: table.getAllLeafColumns().length, role: "status", children: emptyMessage }) })) : (rows.map((row) =>
|
|
258
|
+
}) }, headerGroup.id))) }), _jsx("tbody", { className: "tui-table__body", children: loading ? (_jsx("tr", { className: "tui-table__row tui-table__row--loading", children: _jsx("td", { className: "tui-table__cell tui-table__cell--body", colSpan: table.getAllLeafColumns().length, children: loadingMessage }) })) : isEmpty ? (_jsx("tr", { className: "tui-table__row tui-table__row--empty", children: _jsx("td", { className: "tui-table__cell tui-table__cell--body", colSpan: table.getAllLeafColumns().length, role: "status", children: emptyMessage }) })) : (rows.map((row) => {
|
|
259
|
+
const rowProps = getRowProps?.(row);
|
|
260
|
+
return (
|
|
261
|
+
// Consumer props spread first: className merges with the
|
|
262
|
+
// built-in classes, and the selection state markers stay
|
|
263
|
+
// authoritative (declared after the spread).
|
|
264
|
+
_jsx("tr", { ...rowProps, className: cx('tui-table__row', 'tui-table__row--body', row.getIsSelected() && 'is-selected', rowProps?.className), "data-selected": row.getIsSelected() ? 'true' : 'false', children: row.getVisibleCells().map((cell) => (_jsx("td", { className: "tui-table__cell tui-table__cell--body", children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id))) }, row.id));
|
|
265
|
+
})) })] }), renderPagination
|
|
187
266
|
? renderPagination(table)
|
|
188
267
|
: (_jsx(Pagination, { table: table, mode: paginationMode, showPager: showPager, maxNumbers: paginationMaxNumbers, navStyle: paginationNavStyle, pageSizeOptions: pageSizeOptions }))] }));
|
|
189
268
|
}
|
|
@@ -40,6 +40,13 @@ export const Textarea = forwardRef(function Textarea({ size = 'md', resize = 've
|
|
|
40
40
|
adjustHeight();
|
|
41
41
|
}
|
|
42
42
|
}, [autoResize, adjustHeight, value]);
|
|
43
|
+
// Take the handler's type from React's own declaration rather than naming
|
|
44
|
+
// an event type here. `onInput` was `FormEventHandler` through React 18 and
|
|
45
|
+
// @types/react 19.1, and became an `InputEvent` handler in 19.2 — which adds
|
|
46
|
+
// a required `data` property, so a hand-written `FormEvent<…>` parameter no
|
|
47
|
+
// longer satisfies the `onInput?.(e)` forward. Deriving it means the
|
|
48
|
+
// component tracks whichever @types/react is installed, which matters here
|
|
49
|
+
// because the peer range is `react >= 18`.
|
|
43
50
|
const handleInput = useCallback((e) => {
|
|
44
51
|
if (autoResize) {
|
|
45
52
|
adjustHeight();
|
|
@@ -4,6 +4,7 @@ import { isDev } from '../../utils/is-dev.js';
|
|
|
4
4
|
import { useFloating, offset, flip, shift, arrow, autoUpdate, FloatingPortal, FloatingArrow, } from '@floating-ui/react';
|
|
5
5
|
import { cx } from '../../utils/cx.js';
|
|
6
6
|
import { getPortalRootFor } from '../../utils/portal.js';
|
|
7
|
+
import { getElementRef } from '../../utils/compose-refs.js';
|
|
7
8
|
import { TooltipContext, TooltipProviderContext, useTooltipContext, useTooltipProviderContext, } from './TooltipContext.js';
|
|
8
9
|
import { toPlacement } from './types.js';
|
|
9
10
|
// =============================================================================
|
|
@@ -91,7 +92,7 @@ function TooltipTriggerComponent({ asChild = false, 'aria-label': ariaLabel, chi
|
|
|
91
92
|
triggerRef.current = node;
|
|
92
93
|
// Also call child's ref if it exists
|
|
93
94
|
if (asChild && isValidElement(children)) {
|
|
94
|
-
const childRef = children
|
|
95
|
+
const childRef = getElementRef(children);
|
|
95
96
|
if (typeof childRef === 'function') {
|
|
96
97
|
childRef(node);
|
|
97
98
|
}
|
package/components/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export { Modal } from './Modal';
|
|
|
25
25
|
export { MoveHandle } from './MoveHandle';
|
|
26
26
|
export { Notice } from './Notice';
|
|
27
27
|
export { OverlapStack } from './OverlapStack';
|
|
28
|
-
export { Pager } from './Pager';
|
|
28
|
+
export { Pager, defaultPagerLabels } from './Pager';
|
|
29
29
|
export { Popover, PopoverTrigger, PopoverContent, usePopover } from './Popover';
|
|
30
30
|
export { Progress } from './Progress';
|
|
31
31
|
export { RadioGroup, Radio } from './Radio';
|
|
@@ -68,7 +68,7 @@ export type { ModalProps } from './Modal';
|
|
|
68
68
|
export type { MoveHandleLabels, MoveHandleMode, MoveHandleProps, MoveHandleSize } from './MoveHandle';
|
|
69
69
|
export type { NoticeProps } from './Notice';
|
|
70
70
|
export type { OverlapStackProps, OverlapStackOverflowProps } from './OverlapStack';
|
|
71
|
-
export type { PagerProps, PagerMode } from './Pager';
|
|
71
|
+
export type { PagerProps, PagerMode, PagerVariant, PagerLabels } from './Pager';
|
|
72
72
|
export type { PopoverProps, PopoverTriggerProps, PopoverContentProps, } from './Popover';
|
|
73
73
|
export type { ProgressProps } from './Progress';
|
|
74
74
|
export type { RadioGroupProps, RadioProps } from './Radio';
|
package/components/index.js
CHANGED
|
@@ -23,7 +23,7 @@ export { Modal } from './Modal/index.js';
|
|
|
23
23
|
export { MoveHandle } from './MoveHandle/index.js';
|
|
24
24
|
export { Notice } from './Notice/index.js';
|
|
25
25
|
export { OverlapStack } from './OverlapStack/index.js';
|
|
26
|
-
export { Pager } from './Pager/index.js';
|
|
26
|
+
export { Pager, defaultPagerLabels } from './Pager/index.js';
|
|
27
27
|
export { Popover, PopoverTrigger, PopoverContent, usePopover } from './Popover/index.js';
|
|
28
28
|
export { Progress } from './Progress/index.js';
|
|
29
29
|
export { RadioGroup, Radio } from './Radio/index.js';
|