@rovula/ui 0.1.28 → 0.1.29
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/cjs/bundle.css +501 -67
- package/dist/cjs/bundle.js +589 -589
- package/dist/cjs/bundle.js.map +1 -1
- package/dist/cjs/types/components/DataTable/DataTable.d.ts +195 -4
- package/dist/cjs/types/components/DataTable/DataTable.editing.d.ts +20 -0
- package/dist/cjs/types/components/DataTable/DataTable.editing.types.d.ts +145 -0
- package/dist/cjs/types/components/DataTable/DataTable.stories.d.ts +268 -6
- package/dist/cjs/types/components/Dropdown/Dropdown.d.ts +22 -0
- package/dist/cjs/types/components/Dropdown/Dropdown.stories.d.ts +4 -0
- package/dist/cjs/types/components/ScrollArea/ScrollArea.d.ts +3 -3
- package/dist/cjs/types/components/ScrollArea/ScrollArea.stories.d.ts +4 -0
- package/dist/cjs/types/components/Table/Table.d.ts +33 -3
- package/dist/cjs/types/components/Table/Table.stories.d.ts +86 -4
- package/dist/cjs/types/components/TextInput/TextInput.stories.d.ts +8 -0
- package/dist/cjs/types/components/TextInput/TextInput.styles.d.ts +1 -0
- package/dist/components/DataTable/DataTable.editing.js +385 -0
- package/dist/components/DataTable/DataTable.editing.types.js +1 -0
- package/dist/components/DataTable/DataTable.js +983 -50
- package/dist/components/DataTable/DataTable.stories.js +1077 -25
- package/dist/components/Dropdown/Dropdown.js +8 -6
- package/dist/components/ScrollArea/ScrollArea.js +2 -2
- package/dist/components/ScrollArea/ScrollArea.stories.js +68 -2
- package/dist/components/Table/Table.js +103 -13
- package/dist/components/Table/Table.stories.js +226 -9
- package/dist/components/TextInput/TextInput.js +6 -4
- package/dist/components/TextInput/TextInput.stories.js +8 -0
- package/dist/components/TextInput/TextInput.styles.js +7 -1
- package/dist/esm/bundle.css +501 -67
- package/dist/esm/bundle.js +1545 -1545
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/types/components/DataTable/DataTable.d.ts +195 -4
- package/dist/esm/types/components/DataTable/DataTable.editing.d.ts +20 -0
- package/dist/esm/types/components/DataTable/DataTable.editing.types.d.ts +145 -0
- package/dist/esm/types/components/DataTable/DataTable.stories.d.ts +268 -6
- package/dist/esm/types/components/Dropdown/Dropdown.d.ts +22 -0
- package/dist/esm/types/components/Dropdown/Dropdown.stories.d.ts +4 -0
- package/dist/esm/types/components/ScrollArea/ScrollArea.d.ts +3 -3
- package/dist/esm/types/components/ScrollArea/ScrollArea.stories.d.ts +4 -0
- package/dist/esm/types/components/Table/Table.d.ts +33 -3
- package/dist/esm/types/components/Table/Table.stories.d.ts +86 -4
- package/dist/esm/types/components/TextInput/TextInput.stories.d.ts +8 -0
- package/dist/esm/types/components/TextInput/TextInput.styles.d.ts +1 -0
- package/dist/index.d.ts +493 -122
- package/dist/src/theme/global.css +747 -96
- package/package.json +14 -2
- package/src/components/DataTable/DataTable.editing.tsx +861 -0
- package/src/components/DataTable/DataTable.editing.types.ts +192 -0
- package/src/components/DataTable/DataTable.stories.tsx +2169 -31
- package/src/components/DataTable/DataTable.test.tsx +696 -0
- package/src/components/DataTable/DataTable.tsx +2260 -94
- package/src/components/Dropdown/Dropdown.tsx +22 -6
- package/src/components/ScrollArea/ScrollArea.stories.tsx +146 -3
- package/src/components/ScrollArea/ScrollArea.tsx +6 -6
- package/src/components/Table/Table.stories.tsx +789 -44
- package/src/components/Table/Table.tsx +294 -28
- package/src/components/TextInput/TextInput.stories.tsx +80 -0
- package/src/components/TextInput/TextInput.styles.ts +7 -1
- package/src/components/TextInput/TextInput.tsx +21 -14
- package/src/test/setup.ts +50 -0
- package/src/theme/global.css +81 -42
- package/src/theme/presets/colors.js +12 -0
- package/src/theme/themes/variable.css +27 -28
- package/src/theme/tokens/baseline.css +2 -1
- package/src/theme/tokens/components/scrollbar.css +9 -4
- package/src/theme/tokens/components/table.css +63 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import type { ColumnDef, Row, RowData } from "@tanstack/react-table";
|
|
2
|
+
import type { Options } from "@/components/Dropdown/Dropdown";
|
|
3
|
+
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Editing display / trigger modes
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
export type EditDisplayMode = "cell" | "row";
|
|
9
|
+
export type EditTrigger = "click" | "doubleClick";
|
|
10
|
+
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Column-level editing extensions
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
export type EditableColumnDef<
|
|
16
|
+
TData extends RowData = RowData,
|
|
17
|
+
TValue = unknown,
|
|
18
|
+
> = ColumnDef<TData, TValue> & {
|
|
19
|
+
/**
|
|
20
|
+
* Enable inline editing for this column.
|
|
21
|
+
* - `true` — always editable
|
|
22
|
+
* - `(row) => boolean` — conditionally editable (e.g. dependent fields)
|
|
23
|
+
*/
|
|
24
|
+
enableEditing?: boolean | ((row: Row<TData>) => boolean);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Which built-in editor to render.
|
|
28
|
+
* - `"text"` — `TextInput` (default when `enableEditing` is truthy)
|
|
29
|
+
* - `"select"` — `Dropdown`
|
|
30
|
+
* - `"number"` — `NumberInput`
|
|
31
|
+
* - `"checkbox"` — `Checkbox`
|
|
32
|
+
* - `"custom"` — user-provided renderer via `editCustomCell`
|
|
33
|
+
*/
|
|
34
|
+
editVariant?: "text" | "select" | "number" | "checkbox" | "custom";
|
|
35
|
+
|
|
36
|
+
/** Props forwarded to the `TextInput` editor (variant `"text"`). */
|
|
37
|
+
editTextProps?: {
|
|
38
|
+
placeholder?: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** Props forwarded to the `Dropdown` editor (variant `"select"`). */
|
|
42
|
+
editSelectProps?: {
|
|
43
|
+
options: Options[] | ((row: Row<TData>) => Options[]);
|
|
44
|
+
placeholder?: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Props forwarded to the `NumberInput` editor (variant `"number"`). */
|
|
48
|
+
editNumberProps?: {
|
|
49
|
+
placeholder?: string;
|
|
50
|
+
min?: number;
|
|
51
|
+
max?: number;
|
|
52
|
+
step?: number;
|
|
53
|
+
precision?: number;
|
|
54
|
+
allowDecimal?: boolean;
|
|
55
|
+
allowNegative?: boolean;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** Props forwarded to the `Checkbox` editor (variant `"checkbox"`). */
|
|
59
|
+
editCheckboxProps?: {
|
|
60
|
+
label?: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Render function for a fully custom edit cell (variant `"custom"`).
|
|
65
|
+
*
|
|
66
|
+
* Receives the current row and a `commit` callback. Call `commit(rawValue)`
|
|
67
|
+
* to persist the change — the engine will run `onCommit` / `buildPatch`
|
|
68
|
+
* as usual.
|
|
69
|
+
*
|
|
70
|
+
* ```tsx
|
|
71
|
+
* editCustomCell: (row, { commit, errorMessage }) => (
|
|
72
|
+
* <MyColorPicker
|
|
73
|
+
* value={row.original.color}
|
|
74
|
+
* onChange={(c) => commit(c)}
|
|
75
|
+
* error={errorMessage}
|
|
76
|
+
* />
|
|
77
|
+
* )
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
editCustomCell?: (
|
|
81
|
+
row: Row<TData>,
|
|
82
|
+
ctx: {
|
|
83
|
+
/** Persist the edited value — runs `onCommit` / `buildPatch` as usual. */
|
|
84
|
+
commit: (rawValue: string) => void;
|
|
85
|
+
/** Exit edit mode without committing (same as pressing Escape). */
|
|
86
|
+
blur: () => void;
|
|
87
|
+
columnId: string;
|
|
88
|
+
autoFocus: boolean;
|
|
89
|
+
errorMessage?: string;
|
|
90
|
+
onKeyDown?: (e: React.KeyboardEvent<HTMLElement>) => void;
|
|
91
|
+
},
|
|
92
|
+
) => React.ReactNode;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Return an error message for the current cell value to display inline
|
|
96
|
+
* validation feedback. Return `undefined` or empty string when valid.
|
|
97
|
+
*/
|
|
98
|
+
editError?: (row: Row<TData>) => string | undefined;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Build a custom `Partial<TData>` patch from the raw committed value.
|
|
102
|
+
* When omitted the engine defaults to `{ [columnId]: rawValue }`.
|
|
103
|
+
*
|
|
104
|
+
* Use this for dependent-field resets, value transforms, etc.
|
|
105
|
+
*
|
|
106
|
+
* ```ts
|
|
107
|
+
* onCommit: (_row, value) => ({
|
|
108
|
+
* dataCategory: value,
|
|
109
|
+
* dataType: "", format: "", source: "",
|
|
110
|
+
* })
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
onCommit?: (row: Row<TData>, value: string) => Partial<TData>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* When `true`, a cell whose `enableEditing` returns `false` renders a
|
|
117
|
+
* **disabled** TextInput / Dropdown (matching `editVariant`) instead of
|
|
118
|
+
* falling back to `displayCell` or plain text.
|
|
119
|
+
*/
|
|
120
|
+
editShowDisabledField?: boolean;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Custom preview renderer shown when the cell is **not** in edit mode.
|
|
124
|
+
* Defaults to the plain string value of `row.original[key]`.
|
|
125
|
+
*/
|
|
126
|
+
displayCell?: (row: Row<TData>) => React.ReactNode;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
// Table-level editing props (merged into DataTableProps)
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
|
|
133
|
+
export interface DataTableEditingProps<TData extends RowData = RowData> {
|
|
134
|
+
/** Master switch — set `true` to enable editing features. */
|
|
135
|
+
enableEditing?: boolean;
|
|
136
|
+
|
|
137
|
+
/** How editing is activated visually. @default "cell" */
|
|
138
|
+
editDisplayMode?: EditDisplayMode;
|
|
139
|
+
|
|
140
|
+
/** Gesture that enters edit mode. @default "click" */
|
|
141
|
+
editTrigger?: EditTrigger;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Called every time a cell commits a new value. The `patch` object is
|
|
145
|
+
* built from the column's `commitResets` / `mapCommitValue` or defaults
|
|
146
|
+
* to `{ [columnId]: rawValue }`.
|
|
147
|
+
*/
|
|
148
|
+
onCellCommit?: (
|
|
149
|
+
rowId: string,
|
|
150
|
+
columnId: string,
|
|
151
|
+
patch: Partial<TData>,
|
|
152
|
+
) => void;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Rows that return `true` render their editable columns in edit mode
|
|
156
|
+
* **permanently** (e.g. an "add" footer row).
|
|
157
|
+
*/
|
|
158
|
+
alwaysEditing?: (row: Row<TData>) => boolean;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* When `true` (the default when `enableEditing` is set), Tab / Shift+Tab
|
|
162
|
+
* inside an editing cell moves focus to the next / previous editable
|
|
163
|
+
* column in the same row.
|
|
164
|
+
*/
|
|
165
|
+
enableCellTabTraversal?: boolean;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Explicit ordered list of column ids for Tab traversal. When omitted
|
|
169
|
+
* the engine auto-detects editable columns in definition order.
|
|
170
|
+
*/
|
|
171
|
+
editableColumnIds?: string[];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
// Internal editing context (shared between engine and DataTable render)
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
|
|
178
|
+
export interface EditingState {
|
|
179
|
+
editingRowId: string | null;
|
|
180
|
+
editingCell: { rowId: string; columnId: string } | null;
|
|
181
|
+
editDisplayMode: EditDisplayMode;
|
|
182
|
+
editTrigger: EditTrigger;
|
|
183
|
+
requestRowEdit: (rowId: string) => void;
|
|
184
|
+
requestCellEdit: (rowId: string, columnId: string) => void;
|
|
185
|
+
clearEdit: () => void;
|
|
186
|
+
onFieldBlur: (rowId: string, columnId: string) => void;
|
|
187
|
+
moveCellEdit: (
|
|
188
|
+
rowId: string,
|
|
189
|
+
fromColumnId: string,
|
|
190
|
+
delta: -1 | 1,
|
|
191
|
+
) => "moved" | "exited";
|
|
192
|
+
}
|