@dxos/react-ui-table 0.4.8-main.f998f66 → 0.4.8-next.fff1521
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/dist/lib/browser/index.mjs +70 -54
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/Cell/Cell.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +2 -0
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/helpers.d.ts.map +1 -1
- package/dist/types/src/theme.d.ts +1 -1
- package/dist/types/src/theme.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/components/Cell/Cell.tsx +4 -1
- package/src/components/Table/Table.stories.tsx +51 -62
- package/src/components/Table/Table.tsx +35 -36
- package/src/helpers.tsx +50 -42
- package/src/theme.ts +3 -1
package/src/helpers.tsx
CHANGED
|
@@ -95,8 +95,11 @@ const ComboboxBuilderCell = <TData extends RowData>(cellContext: CellContext<TDa
|
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
const StringBuilderCell = <TData extends RowData>(cellContext: CellContext<TData, string>) => {
|
|
98
|
-
const
|
|
99
|
-
const {
|
|
98
|
+
const ref = useRef<HTMLInputElement>(null);
|
|
99
|
+
const { findPrevFocusable } = useFocusFinders();
|
|
100
|
+
|
|
101
|
+
const { onUpdate, cell } = cellContext.column.columnDef.meta as ColumnMeta<TData, string>;
|
|
102
|
+
|
|
100
103
|
// https://tanstack.com/table/v8/docs/examples/react/editable-data
|
|
101
104
|
const initialValue = cellContext.getValue();
|
|
102
105
|
const [value, setValue] = useState(() => {
|
|
@@ -109,16 +112,14 @@ const StringBuilderCell = <TData extends RowData>(cellContext: CellContext<TData
|
|
|
109
112
|
});
|
|
110
113
|
|
|
111
114
|
const handleSave = () => {
|
|
112
|
-
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
+
ref.current && document.activeElement === ref.current && findPrevFocusable(ref.current)?.focus();
|
|
115
116
|
|
|
116
|
-
|
|
117
|
+
if (value !== initialValue) {
|
|
118
|
+
onUpdate?.(cellContext.row.original, cellContext.column.id, value);
|
|
119
|
+
}
|
|
117
120
|
};
|
|
118
121
|
|
|
119
|
-
const handleCancel = () =>
|
|
120
|
-
setValue(initialValue);
|
|
121
|
-
};
|
|
122
|
+
const handleCancel = () => setValue(initialValue);
|
|
122
123
|
|
|
123
124
|
// Check if first input column of last row.
|
|
124
125
|
const rows = cellContext.table.getRowModel().flatRows;
|
|
@@ -129,12 +130,12 @@ const StringBuilderCell = <TData extends RowData>(cellContext: CellContext<TData
|
|
|
129
130
|
return (
|
|
130
131
|
<Input.Root>
|
|
131
132
|
<Input.TextInput
|
|
132
|
-
ref={
|
|
133
|
+
ref={ref}
|
|
133
134
|
variant='subdued'
|
|
134
135
|
placeholder={placeholder ? 'Add row...' : undefined}
|
|
135
|
-
classNames={['is-full', textPadding]}
|
|
136
|
+
classNames={['is-full', textPadding, cell?.classNames]}
|
|
136
137
|
value={value ?? ''}
|
|
137
|
-
onBlur={
|
|
138
|
+
onBlur={handleSave}
|
|
138
139
|
onChange={(event) => setValue(event.target.value)}
|
|
139
140
|
onKeyDown={(event) => (event.key === 'Enter' && handleSave()) || (event.key === 'Escape' && handleCancel())}
|
|
140
141
|
/>
|
|
@@ -164,17 +165,20 @@ const NumberBuilderCell = <TData extends RowData>(cellContext: CellContext<TData
|
|
|
164
165
|
(!document.activeElement || document.activeElement !== ref.current) && setText(displayNumber(value, digits));
|
|
165
166
|
}, [digits, value]);
|
|
166
167
|
|
|
167
|
-
const handleEdit = () =>
|
|
168
|
-
if (onUpdate) {
|
|
169
|
-
setText(value !== undefined ? String(value) : '');
|
|
170
|
-
}
|
|
171
|
-
};
|
|
168
|
+
const handleEdit = () => setText(value !== undefined ? String(value) : '');
|
|
172
169
|
|
|
173
170
|
// TODO(burdon): Property is encoded as float (e.g., 6.1 => 6.099)
|
|
174
171
|
const handleSave = () => {
|
|
175
172
|
const nextValue = parseNumber(text);
|
|
176
|
-
|
|
177
|
-
|
|
173
|
+
|
|
174
|
+
if (!isNaN(nextValue)) {
|
|
175
|
+
onUpdate?.(cellContext.row.original, cellContext.column.id, nextValue);
|
|
176
|
+
setText(displayNumber(nextValue, digits));
|
|
177
|
+
} else {
|
|
178
|
+
// Reset the text to display the original value without updating the model.
|
|
179
|
+
setText(displayNumber(value, digits));
|
|
180
|
+
}
|
|
181
|
+
|
|
178
182
|
// Shift focus only if input is focused on save (e.g. on `Enter`).
|
|
179
183
|
ref.current && document.activeElement === ref.current && findPrevFocusable(ref.current)?.focus();
|
|
180
184
|
};
|
|
@@ -210,20 +214,23 @@ const RowSelectorBuilderCell = <TData extends RowData>(cellContext: CellContext<
|
|
|
210
214
|
const checked = row.getCanSelect()
|
|
211
215
|
? row.getIsSelected()
|
|
212
216
|
: row.getCanSelectSubRows() && (row.getIsSomeSelected() ? 'indeterminate' : row.getIsAllSubRowsSelected());
|
|
217
|
+
|
|
213
218
|
return (
|
|
214
|
-
<
|
|
215
|
-
<Input.
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
row.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
219
|
+
<div className='flex justify-center w-full h-full' role='presentation'>
|
|
220
|
+
<Input.Root>
|
|
221
|
+
<Input.Checkbox
|
|
222
|
+
size={4}
|
|
223
|
+
classNames={[cell?.classNames]}
|
|
224
|
+
checked={checked}
|
|
225
|
+
onCheckedChange={(event) => {
|
|
226
|
+
if (row.getCanSelect()) {
|
|
227
|
+
row.getToggleSelectedHandler()(event);
|
|
228
|
+
}
|
|
229
|
+
}}
|
|
230
|
+
disabled={!(row.getCanSelect() || row.getCanSelectSubRows())}
|
|
231
|
+
/>
|
|
232
|
+
</Input.Root>
|
|
233
|
+
</div>
|
|
227
234
|
);
|
|
228
235
|
};
|
|
229
236
|
|
|
@@ -422,21 +429,22 @@ export class ColumnBuilder<TData extends RowData> {
|
|
|
422
429
|
return {
|
|
423
430
|
id,
|
|
424
431
|
size: 32,
|
|
425
|
-
|
|
426
|
-
maxSize: 32,
|
|
432
|
+
enableResizing: false,
|
|
427
433
|
meta: { onUpdate, cell: { classNames } },
|
|
428
434
|
header: ({ table }) => {
|
|
429
435
|
const { rowsSelectable } = useTableContext('HELPER_SELECT_ROW_HEADER_CELL');
|
|
430
436
|
const checked = table.getIsSomeRowsSelected() ? 'indeterminate' : table.getIsAllRowsSelected();
|
|
431
437
|
return rowsSelectable === 'multi' ? (
|
|
432
|
-
<
|
|
433
|
-
<Input.
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
438
|
+
<div className='flex justify-center w-full h-full' role='presentation'>
|
|
439
|
+
<Input.Root>
|
|
440
|
+
<Input.Checkbox
|
|
441
|
+
size={4}
|
|
442
|
+
classNames={['mli-auto', classNames]}
|
|
443
|
+
checked={checked}
|
|
444
|
+
onCheckedChange={() => table.toggleAllRowsSelected()}
|
|
445
|
+
/>
|
|
446
|
+
</Input.Root>
|
|
447
|
+
</div>
|
|
440
448
|
) : null;
|
|
441
449
|
},
|
|
442
450
|
cell: RowSelectorBuilderCell,
|
package/src/theme.ts
CHANGED
|
@@ -23,7 +23,8 @@ export const flushPadding = 'pli-0 plb-0';
|
|
|
23
23
|
export const textPadding = 'pli-2 plb-0.5';
|
|
24
24
|
export const headPadding = 'pli-2 plb-1.5';
|
|
25
25
|
|
|
26
|
-
export const gridCellFocusRing =
|
|
26
|
+
export const gridCellFocusRing =
|
|
27
|
+
'focus-within:z-[11] focus-within:outline outline-2 outline-primary-500 dark:outline-primary-400';
|
|
27
28
|
|
|
28
29
|
//
|
|
29
30
|
// table
|
|
@@ -89,6 +90,7 @@ export const tbodyTr: ComponentFunction<TbodyTrStyleProps> = ({ canBeCurrent },
|
|
|
89
90
|
|
|
90
91
|
export const tdRoot: ComponentFunction<TbodyStyleProps> = ({ border, isGrid }, ...etc) =>
|
|
91
92
|
mx('relative', flushPadding, border && 'border', border && groupBorder, isGrid && gridCellFocusRing, ...etc);
|
|
93
|
+
|
|
92
94
|
export const tdContent: ComponentFunction<CellContext<any, any>> = (_props, ...etc) => mx(...etc);
|
|
93
95
|
|
|
94
96
|
//
|