torch-glare 2.2.1 → 2.4.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/apps/lib/components/Badge.tsx +6 -0
- package/apps/lib/components/ContextMenu.tsx +14 -11
- package/apps/lib/components/DataViews/DataViewRadio.tsx +9 -2
- package/apps/lib/components/DataViews/DataViewsConfigPanel.tsx +8 -8
- package/apps/lib/components/DataViews/DataViewsHeader.tsx +13 -32
- package/apps/lib/components/DataViews/FilterPanel.tsx +26 -9
- package/apps/lib/components/DataViews/filters/DatePickerRangeFilter.tsx +80 -0
- package/apps/lib/components/DataViews/types.ts +8 -0
- package/apps/lib/components/DatePicker.tsx +6 -1
- package/apps/lib/components/DropdownMenu.tsx +14 -11
- package/apps/lib/components/HeaderBar.tsx +127 -0
- package/apps/lib/components/SearchableSelect.tsx +42 -42
- package/apps/lib/components/SearchableTable.tsx +167 -177
- package/apps/lib/components/TabSwitch.tsx +181 -0
- package/docs/components/context-menu.md +30 -0
- package/docs/components/data-views-config-panel.md +3 -3
- package/docs/components/data-views-layout.md +9 -2
- package/docs/components/dropdown-menu.md +28 -0
- package/docs/components/header-bar.md +181 -0
- package/docs/components/searchable-table.md +44 -30
- package/docs/components/section-block.md +118 -0
- package/docs/components/tab-switch.md +163 -0
- package/docs/how-to/data-views-from-backend-response.md +1 -0
- package/package.json +1 -1
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: SearchableTable
|
|
3
|
-
description: A
|
|
3
|
+
description: A field that opens a modal dialog to pick a row from a real Table, with single-select, client- or server-side search, and infinite-scroll pagination
|
|
4
4
|
group: Inputs
|
|
5
|
-
keywords: [searchable-table,
|
|
5
|
+
keywords: [searchable-table, dialog, table, search, async, infinite-scroll, pagination, select, picker]
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# SearchableTable
|
|
9
9
|
|
|
10
|
-
> A
|
|
10
|
+
> A field that opens a modal `Dialog` to pick a row from a real, multi-column `Table`. The trigger shows a placeholder until something is selected, then the selected row's label. Click it to open the dialog (a search input + the data table); type to filter rows (client-side) or refetch them from a backend (server-side), click a row to single-select it and close the dialog, and scroll to the bottom to lazy-load more pages. Generic over your row type `T`.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
|
-
`SearchableTable` is part of the TORCH Glare component library. It composes the [
|
|
14
|
+
`SearchableTable` is part of the TORCH Glare component library. It composes the [Dialog](./dialog.md) (built on Radix Dialog) and the [Table](./table.md) component internally, so both must be available — they ship with the library.
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
npm install @torch-ui/components @radix-ui/react-
|
|
17
|
+
npm install @torch-ui/components @radix-ui/react-dialog
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## Import
|
|
@@ -60,13 +60,15 @@ function Example() {
|
|
|
60
60
|
onSelect={setSelected}
|
|
61
61
|
getLabel={(row) => row.name}
|
|
62
62
|
getRowId={(row) => row.id}
|
|
63
|
-
|
|
63
|
+
icon={<i className="ri-user-line" />}
|
|
64
|
+
placeholder="Select a user…"
|
|
65
|
+
title="Select a user"
|
|
64
66
|
/>
|
|
65
67
|
)
|
|
66
68
|
}
|
|
67
69
|
```
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
Clicking the field opens a modal dialog with a search input and the data table. As you type, rows are filtered locally by every column key. Clicking a row selects it (single-select), closes the dialog, and shows `getLabel(row)` on the trigger. Use `placeholder` for the trigger text, `searchPlaceholder` for the in-dialog search input, and `title` for the dialog's search-field label (also the accessible dialog title).
|
|
70
72
|
|
|
71
73
|
### Custom cell rendering
|
|
72
74
|
|
|
@@ -159,26 +161,35 @@ function AsyncExample() {
|
|
|
159
161
|
hasMore={hasMore}
|
|
160
162
|
loading={loading}
|
|
161
163
|
onLoadMore={loadMore}
|
|
162
|
-
|
|
164
|
+
icon={<i className="ri-user-line" />}
|
|
165
|
+
placeholder="Select a user…"
|
|
166
|
+
title="Select a user"
|
|
167
|
+
searchPlaceholder="Search users… (scroll to load more)"
|
|
163
168
|
/>
|
|
164
169
|
)
|
|
165
170
|
}
|
|
166
171
|
```
|
|
167
172
|
|
|
168
|
-
###
|
|
173
|
+
### Dialog labels (trigger, title, search)
|
|
169
174
|
|
|
170
|
-
|
|
175
|
+
Three props control the dialog's text. `placeholder` is the trigger text shown until a row is selected; `title` labels the dialog's search field (and is the accessible dialog title); `searchPlaceholder` is the placeholder of the in-dialog search input.
|
|
171
176
|
|
|
172
177
|
```typescript
|
|
173
178
|
<SearchableTable<User>
|
|
174
179
|
columns={columns}
|
|
175
180
|
rows={users}
|
|
181
|
+
value={selected}
|
|
176
182
|
onSelect={setSelected}
|
|
177
183
|
getRowId={(row) => row.id}
|
|
178
|
-
|
|
184
|
+
icon={<i className="ri-user-line" />}
|
|
185
|
+
placeholder="Select a user…"
|
|
186
|
+
title="Select a user"
|
|
187
|
+
searchPlaceholder="Search by name or role…"
|
|
179
188
|
/>
|
|
180
189
|
```
|
|
181
190
|
|
|
191
|
+
The data table inside the dialog scrolls vertically once it exceeds `~55vh`; the remaining rows stay reachable via scroll, which is also what drives infinite-scroll loading.
|
|
192
|
+
|
|
182
193
|
## API Reference
|
|
183
194
|
|
|
184
195
|
### SearchableTable<T>
|
|
@@ -188,24 +199,25 @@ function AsyncExample() {
|
|
|
188
199
|
| `columns` | `SearchableTableColumn<T>[]` | Required | Column config — header, the row key to read, and an optional cell renderer. |
|
|
189
200
|
| `rows` | `T[]` | Required | The data rows. In server mode these are rendered as-is (already filtered upstream). |
|
|
190
201
|
| `value` | `T \| null` | - | Controlled selected row. The matching row is highlighted in the table. |
|
|
191
|
-
| `onSelect` | `(row: T) => void` | - | Called when a row is clicked. The
|
|
192
|
-
| `getLabel` | `(row: T) => string` | First column's value | Text shown
|
|
202
|
+
| `onSelect` | `(row: T) => void` | - | Called when a row is clicked. The dialog closes and the trigger shows the row's label. |
|
|
203
|
+
| `getLabel` | `(row: T) => string` | First column's value | Text shown on the trigger after selection. |
|
|
193
204
|
| `getRowId` | `(row: T) => string` | `JSON.stringify(row)` | Stable id/key per row, used for keys and selection matching. |
|
|
194
205
|
| `searchKeys` | `(keyof T & string)[]` | Every column `key` | Which fields client-side search matches against. |
|
|
195
|
-
| `placeholder` | `string` | `'
|
|
196
|
-
| `
|
|
197
|
-
| `
|
|
198
|
-
| `
|
|
206
|
+
| `placeholder` | `string` | `'Select…'` | Trigger placeholder shown until a row is selected. |
|
|
207
|
+
| `searchPlaceholder` | `string` | `'Search…'` | Placeholder for the search input inside the dialog. |
|
|
208
|
+
| `title` | `string` | `'Select an item'` | Label shown on the dialog's search field (also used as the accessible dialog title). |
|
|
209
|
+
| `size` | `'XS' \| 'S' \| 'M'` | `'M'` | Trigger size. (`XS` maps the underlying Group to `S` with a tighter input height.) |
|
|
210
|
+
| `variant` | `'PresentationStyle'` | `'PresentationStyle'` | Visual style of the trigger field. |
|
|
211
|
+
| `icon` | `ReactNode` | - | Optional leading icon rendered inside the trigger. |
|
|
199
212
|
| `theme` | `'dark' \| 'light' \| 'default'` | - | Theme variant, applied via `data-theme`. |
|
|
200
|
-
| `dir` | `string` | - | Text direction (e.g. `'rtl'`), applied to the
|
|
201
|
-
| `className` | `string` | - | Additional classes merged onto the
|
|
213
|
+
| `dir` | `string` | - | Text direction (e.g. `'rtl'`), applied to the trigger and dialog. |
|
|
214
|
+
| `className` | `string` | - | Additional classes merged onto the trigger group. |
|
|
202
215
|
| `filterClientSide` | `boolean` | `true` | When `true`, filter `rows` locally by `searchKeys`. Set `false` for server-side search. |
|
|
203
216
|
| `onSearchChange` | `(query: string) => void` | - | Debounced query callback — refetch your data here in server mode. |
|
|
204
217
|
| `searchDebounceMs` | `number` | `300` | Debounce delay (ms) for `onSearchChange`. |
|
|
205
218
|
| `hasMore` | `boolean` | `false` | Whether more pages are available; gates the infinite-scroll loader. |
|
|
206
219
|
| `loading` | `boolean` | `false` | Whether a fetch is in flight; renders a loading row and blocks `onLoadMore`. |
|
|
207
220
|
| `onLoadMore` | `() => void` | - | Called when the list nears the bottom and `hasMore && !loading`. |
|
|
208
|
-
| `maxVisibleRows` | `number` | `6` | Max rows visible before the list scrolls vertically. |
|
|
209
221
|
|
|
210
222
|
### SearchableTableColumn<T>
|
|
211
223
|
|
|
@@ -242,7 +254,9 @@ interface SearchableTableProps<T> {
|
|
|
242
254
|
getLabel?: (row: T) => string
|
|
243
255
|
getRowId?: (row: T) => string
|
|
244
256
|
searchKeys?: (keyof T & string)[]
|
|
245
|
-
placeholder?: string
|
|
257
|
+
placeholder?: string // trigger text until selection (default 'Select…')
|
|
258
|
+
searchPlaceholder?: string // in-dialog search input (default 'Search…')
|
|
259
|
+
title?: string // dialog search-field label / a11y title (default 'Select an item')
|
|
246
260
|
size?: 'XS' | 'S' | 'M'
|
|
247
261
|
variant?: 'PresentationStyle'
|
|
248
262
|
icon?: React.ReactNode
|
|
@@ -256,7 +270,6 @@ interface SearchableTableProps<T> {
|
|
|
256
270
|
hasMore?: boolean
|
|
257
271
|
loading?: boolean
|
|
258
272
|
onLoadMore?: () => void
|
|
259
|
-
maxVisibleRows?: number
|
|
260
273
|
}
|
|
261
274
|
|
|
262
275
|
// Generic function component, constrained so rows are object-shaped:
|
|
@@ -395,25 +408,26 @@ function toUser(api: ApiUser): User {
|
|
|
395
408
|
|
|
396
409
|
## Accessibility
|
|
397
410
|
|
|
398
|
-
- The trigger is a
|
|
399
|
-
-
|
|
400
|
-
-
|
|
401
|
-
-
|
|
402
|
-
- Provide a descriptive `placeholder` and a
|
|
411
|
+
- The trigger is a focusable group with `role="button"` and `tabIndex={0}`; activating it opens a modal dialog (Radix Dialog), which traps focus and closes on `Esc` or outside click.
|
|
412
|
+
- On open, focus moves to the in-dialog search input (`onOpenAutoFocus` is intercepted to focus the search field rather than the first row), so users can type to filter immediately.
|
|
413
|
+
- The dialog always renders a `DialogTitle` (visually hidden, sourced from `title`) so the modal has an accessible name even though the heading is not shown.
|
|
414
|
+
- Clicking a row selects it and closes the dialog; the selected row is marked with the Table's `state="selected"`.
|
|
415
|
+
- Provide a descriptive `placeholder`, a meaningful `title`, and a `getLabel` so screen-reader users hear a clear value after selection. Prefer human-readable headers in `columns`.
|
|
403
416
|
|
|
404
417
|
## Best Practices
|
|
405
418
|
|
|
406
419
|
1. **Always supply `getRowId`.** The default key is `JSON.stringify(row)`, which is slow and brittle for large or nested rows. A stable id keeps keys and selection matching cheap.
|
|
407
|
-
2. **Set `getLabel` for the selected display.** Otherwise the
|
|
420
|
+
2. **Set `getLabel` for the selected display.** Otherwise the trigger shows the first column's raw value, which may not be the most descriptive field.
|
|
408
421
|
3. **Pick the right search mode.** Keep `filterClientSide` (default) for small, in-memory datasets. Switch to `filterClientSide={false}` + `onSearchChange` for backend-driven search so you never filter a partial page.
|
|
409
422
|
4. **Gate pagination correctly.** `onLoadMore` only fires while `hasMore && !loading` — keep `loading` accurate so a single scroll doesn't trigger duplicate fetches, and flip `hasMore` to `false` on the last page.
|
|
410
|
-
5. **The table scrolls in both directions.** Columns keep their natural width, so wide tables scroll horizontally inside the
|
|
423
|
+
5. **The table scrolls in both directions.** Columns keep their natural width, so wide tables scroll horizontally inside the dialog, while the table caps its vertical height (~`55vh`) and the rest scrolls vertically (which is what drives infinite scroll). Keep column count and content reasonable so horizontal scroll stays usable.
|
|
411
424
|
6. **Tune `searchDebounceMs` to your backend.** The 300ms default suits most APIs; raise it for slow or rate-limited endpoints.
|
|
412
425
|
7. **Match `searchKeys` to visible columns.** In client mode, search defaults to every column key — narrow `searchKeys` if some columns hold non-searchable data (ids, formatted dates).
|
|
413
426
|
|
|
414
427
|
## Related Components
|
|
415
428
|
|
|
416
429
|
- [SearchableSelect](./searchable-select.md) - Single-column searchable combobox
|
|
417
|
-
- [Table](./table.md) - The table primitive rendered inside the
|
|
430
|
+
- [Table](./table.md) - The table primitive rendered inside the dialog
|
|
431
|
+
- [Dialog](./dialog.md) - The modal surface the picker opens in
|
|
418
432
|
- [DataTable](./data-table.md) - Full-featured data grid for page-level tables
|
|
419
433
|
- [Select](./select.md) - Standard form select field
|
|
@@ -236,6 +236,124 @@ function RowDivider() {
|
|
|
236
236
|
}
|
|
237
237
|
```
|
|
238
238
|
|
|
239
|
+
### Bilingual Form with Language Switch (EN / AR)
|
|
240
|
+
|
|
241
|
+
A real-world pattern: a `SectionBlock` form with an EN/AR language switcher in the header. The colored title badge and the `TabSwitch` stay LTR; only the field rows flip to RTL when Arabic is selected, and all labels/placeholders are translated.
|
|
242
|
+
|
|
243
|
+
Key points:
|
|
244
|
+
|
|
245
|
+
- Put the `TabSwitch` in a `relative` wrapper and position it `absolute top-2 right-2` so it sits at the header's top-right **outside** the colored title badge (the badge wraps the entire `title` node).
|
|
246
|
+
- Apply `dir` to each field **row**, not to the `SectionBlock` root — otherwise the header (badge + switch) flips too.
|
|
247
|
+
- Drive copy through a tiny `t(en, ar)` helper keyed off the selected language.
|
|
248
|
+
|
|
249
|
+
```tsx
|
|
250
|
+
import { type ReactNode, useState } from "react";
|
|
251
|
+
import { SectionBlock } from "@/components/SectionBlock";
|
|
252
|
+
import { InputField } from "@/components/InputField";
|
|
253
|
+
import { ActionButton } from "@/components/ActionButton";
|
|
254
|
+
import { TabSwitch } from "@/components/TabSwitch";
|
|
255
|
+
|
|
256
|
+
export function BilingualFieldsForm() {
|
|
257
|
+
const [language, setLanguage] = useState<"ar" | "en">("en");
|
|
258
|
+
const isAr = language === "ar";
|
|
259
|
+
const t = (en: string, ar: string) => (isAr ? ar : en);
|
|
260
|
+
|
|
261
|
+
return (
|
|
262
|
+
<div className="relative">
|
|
263
|
+
<SectionBlock
|
|
264
|
+
color="Blue"
|
|
265
|
+
title={
|
|
266
|
+
<span className="flex items-center gap-[6px]">
|
|
267
|
+
<i className="ri-edit-box-line" />
|
|
268
|
+
{t("Custom fields", "حقول مخصصة")}
|
|
269
|
+
</span>
|
|
270
|
+
}
|
|
271
|
+
>
|
|
272
|
+
<FieldRow
|
|
273
|
+
dir={isAr ? "rtl" : "ltr"}
|
|
274
|
+
label={t("Name", "الاسم")}
|
|
275
|
+
required
|
|
276
|
+
requiredLabel={t("(Required)", "(مطلوب)")}
|
|
277
|
+
right={
|
|
278
|
+
<div className="flex flex-1 items-center gap-[12px] min-w-0">
|
|
279
|
+
<InputField placeholder={t("First Name*", "الاسم الأول*")} className="flex-1 min-w-0" />
|
|
280
|
+
<InputField placeholder={t("Last Name*", "اسم العائلة*")} className="flex-1 min-w-0" />
|
|
281
|
+
</div>
|
|
282
|
+
}
|
|
283
|
+
/>
|
|
284
|
+
|
|
285
|
+
<RowDivider />
|
|
286
|
+
|
|
287
|
+
<FieldRow
|
|
288
|
+
dir={isAr ? "rtl" : "ltr"}
|
|
289
|
+
label={t("Department", "القسم")}
|
|
290
|
+
right={<InputField placeholder={t("Write Hint Here", "اكتب التلميح هنا")} className="flex-1" />}
|
|
291
|
+
/>
|
|
292
|
+
|
|
293
|
+
<RowDivider />
|
|
294
|
+
|
|
295
|
+
<FieldRow
|
|
296
|
+
dir={isAr ? "rtl" : "ltr"}
|
|
297
|
+
label={t("Alias names", "الأسماء المستعارة")}
|
|
298
|
+
right={
|
|
299
|
+
<InputField
|
|
300
|
+
placeholder={t("Write Hint Here", "اكتب التلميح هنا")}
|
|
301
|
+
className="flex-1"
|
|
302
|
+
childrenSide={
|
|
303
|
+
<ActionButton aria-label={t("Add alias name", "إضافة اسم مستعار")}>
|
|
304
|
+
<i className="ri-add-line" />
|
|
305
|
+
</ActionButton>
|
|
306
|
+
}
|
|
307
|
+
/>
|
|
308
|
+
}
|
|
309
|
+
/>
|
|
310
|
+
</SectionBlock>
|
|
311
|
+
|
|
312
|
+
<TabSwitch
|
|
313
|
+
className="absolute top-2 right-2 z-10"
|
|
314
|
+
size="S"
|
|
315
|
+
value={language}
|
|
316
|
+
onValueChange={setLanguage}
|
|
317
|
+
options={[
|
|
318
|
+
{ value: "en", label: "English" },
|
|
319
|
+
{ value: "ar", label: "العربية" },
|
|
320
|
+
]}
|
|
321
|
+
/>
|
|
322
|
+
</div>
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
interface FieldRowProps {
|
|
327
|
+
label: string;
|
|
328
|
+
required?: boolean;
|
|
329
|
+
requiredLabel?: string;
|
|
330
|
+
right: ReactNode;
|
|
331
|
+
dir?: "ltr" | "rtl";
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function FieldRow({ label, required, requiredLabel = "(Required)", right, dir }: FieldRowProps) {
|
|
335
|
+
return (
|
|
336
|
+
<div dir={dir} className="flex items-center gap-[24px] py-[18px]">
|
|
337
|
+
<div className="flex w-[140px] shrink-0 items-center gap-[6px]">
|
|
338
|
+
<span className="typography-body-medium-regular text-content-presentation-action-light-primary">
|
|
339
|
+
{label}
|
|
340
|
+
</span>
|
|
341
|
+
{required && (
|
|
342
|
+
<span className="typography-body-small-medium text-content-presentation-state-negative">
|
|
343
|
+
{requiredLabel}
|
|
344
|
+
</span>
|
|
345
|
+
)}
|
|
346
|
+
</div>
|
|
347
|
+
<div className="flex flex-1 items-center min-w-0">{right}</div>
|
|
348
|
+
</div>
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function RowDivider() {
|
|
353
|
+
return <div className="h-px w-full bg-border-presentation-global-primary" />;
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
239
357
|
### Custom Layout (override defaults)
|
|
240
358
|
|
|
241
359
|
Use `containerClassName`, `headerClassName`, and `bodyClassName` to override the built-in spacing and width without losing the title/body structure.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: TabSwitch
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
status: stable
|
|
5
|
+
category: components/navigation
|
|
6
|
+
tags: [tab-switch, segmented-control, view-switcher, toggle, list-cards, pills]
|
|
7
|
+
last-reviewed: 2026-06-15
|
|
8
|
+
bundle-size: 2.0kb
|
|
9
|
+
dependencies:
|
|
10
|
+
- "class-variance-authority": "^0.7.0"
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# TabSwitch
|
|
14
|
+
|
|
15
|
+
> A segmented control for picking one option from a small set — the classic List / Cards style pill switcher. The active option renders as a solid raised white pill; thin dividers sit between adjacent inactive options (never flanking the active pill). Controlled, generic over the option value, supports optional per-option icons, three sizes, and theme-aware track/labels. This is the switcher used in the DataViews header to flip between Table / Kanban / Inbox / Tree.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install torch-glare
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Import
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { TabSwitch } from 'torch-glare/lib/components/TabSwitch'
|
|
27
|
+
import type { TabSwitchOption } from 'torch-glare/lib/components/TabSwitch'
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Examples
|
|
31
|
+
|
|
32
|
+
### Basic Usage (List / Cards)
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { TabSwitch } from 'torch-glare/lib/components/TabSwitch'
|
|
36
|
+
import { useState } from 'react'
|
|
37
|
+
|
|
38
|
+
function Example() {
|
|
39
|
+
const [view, setView] = useState('list')
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<TabSwitch
|
|
43
|
+
value={view}
|
|
44
|
+
onValueChange={setView}
|
|
45
|
+
options={[
|
|
46
|
+
{ value: 'list', label: 'List', icon: <i className="ri-layout-grid-line" /> },
|
|
47
|
+
{ value: 'cards', label: 'Cards', icon: <i className="ri-grid-fill" /> },
|
|
48
|
+
]}
|
|
49
|
+
/>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Sizes
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
<TabSwitch size="S" value={view} onValueChange={setView} options={options} />
|
|
58
|
+
<TabSwitch size="M" value={view} onValueChange={setView} options={options} /> {/* default */}
|
|
59
|
+
<TabSwitch size="L" value={view} onValueChange={setView} options={options} />
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Icons Only
|
|
63
|
+
|
|
64
|
+
Omit `label` to render an icon-only switcher.
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
<TabSwitch
|
|
68
|
+
value={view}
|
|
69
|
+
onValueChange={setView}
|
|
70
|
+
options={[
|
|
71
|
+
{ value: 'list', icon: <i className="ri-layout-grid-line" /> },
|
|
72
|
+
{ value: 'cards', icon: <i className="ri-grid-fill" /> },
|
|
73
|
+
{ value: 'board', icon: <i className="ri-layout-column-line" /> },
|
|
74
|
+
]}
|
|
75
|
+
/>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### On a dark surface
|
|
79
|
+
|
|
80
|
+
The active pill is always a solid white pill with dark text, so it stays visible on dark bars. The track and inactive labels follow the theme — pass `theme="dark"` (or render inside a `data-theme="dark"` scope) so they resolve dark-theme tokens. This is how the DataViews header uses it.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
<div data-theme="dark" className="bg-black p-2">
|
|
84
|
+
<TabSwitch theme="dark" value={view} onValueChange={setView} options={options} />
|
|
85
|
+
</div>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Disabled
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
{/* whole control */}
|
|
92
|
+
<TabSwitch disabled value={view} onValueChange={setView} options={options} />
|
|
93
|
+
|
|
94
|
+
{/* a single option */}
|
|
95
|
+
<TabSwitch
|
|
96
|
+
value={view}
|
|
97
|
+
onValueChange={setView}
|
|
98
|
+
options={[
|
|
99
|
+
{ value: 'list', label: 'List' },
|
|
100
|
+
{ value: 'cards', label: 'Cards', disabled: true },
|
|
101
|
+
]}
|
|
102
|
+
/>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## API Reference
|
|
106
|
+
|
|
107
|
+
### TabSwitch
|
|
108
|
+
|
|
109
|
+
| Prop | Type | Default | Description |
|
|
110
|
+
|------|------|---------|-------------|
|
|
111
|
+
| `options` | `TabSwitchOption[]` | — (required) | The selectable options rendered as segments. |
|
|
112
|
+
| `value` | `string` | — | The currently selected option value (controlled). |
|
|
113
|
+
| `onValueChange` | `(value: string) => void` | — | Called with the option value when a segment is selected. |
|
|
114
|
+
| `size` | `'S' \| 'M' \| 'L'` | `'M'` | Size of the control. |
|
|
115
|
+
| `disabled` | `boolean` | `false` | Disables the whole control. |
|
|
116
|
+
| `theme` | `'dark' \| 'light' \| 'default'` | — | Applies a fixed theme to the track and inactive labels (the active pill stays white). |
|
|
117
|
+
| `className` | `string` | — | Additional classes merged onto the track. |
|
|
118
|
+
|
|
119
|
+
`TabSwitch` is generic over the option value: `TabSwitch<T extends string>` infers `T` from `options`, so `value` and `onValueChange` are typed to your union (e.g. `'list' | 'cards'`).
|
|
120
|
+
|
|
121
|
+
### TabSwitchOption
|
|
122
|
+
|
|
123
|
+
| Prop | Type | Default | Description |
|
|
124
|
+
|------|------|---------|-------------|
|
|
125
|
+
| `value` | `string` | — | Unique value for the option. |
|
|
126
|
+
| `label` | `ReactNode` | `undefined` | Text or node shown for the option. Omit for an icon-only segment. |
|
|
127
|
+
| `icon` | `ReactNode` | `undefined` | Optional leading icon rendered before the label. |
|
|
128
|
+
| `disabled` | `boolean` | `false` | Disables this individual option. |
|
|
129
|
+
|
|
130
|
+
## Accessibility
|
|
131
|
+
|
|
132
|
+
- The track is a `role="tablist"`; each option is a `role="tab"` with `aria-selected` reflecting the active state.
|
|
133
|
+
- Options are real `<button>` elements, so they are keyboard-focusable and activate on Enter/Space.
|
|
134
|
+
|
|
135
|
+
## Notes
|
|
136
|
+
|
|
137
|
+
- The active pill is intentionally a solid white pill with dark text in every theme (not derived from the per-theme selected-tab tokens), so it reads correctly on the always-dark DataViews header as well as on light surfaces.
|
|
138
|
+
- TabSwitch is a controlled component — always pass both `value` and `onValueChange`.
|
|
139
|
+
|
|
140
|
+
## TypeScript
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
interface TabSwitchOption<T extends string = string> {
|
|
144
|
+
value: T
|
|
145
|
+
label?: React.ReactNode
|
|
146
|
+
icon?: React.ReactNode
|
|
147
|
+
disabled?: boolean
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
interface TabSwitchProps<T extends string = string>
|
|
151
|
+
extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
|
|
152
|
+
options: TabSwitchOption<T>[]
|
|
153
|
+
value: T
|
|
154
|
+
onValueChange: (value: T) => void
|
|
155
|
+
size?: 'S' | 'M' | 'L'
|
|
156
|
+
theme?: 'dark' | 'light' | 'default'
|
|
157
|
+
disabled?: boolean
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
declare function TabSwitch<T extends string = string>(
|
|
161
|
+
props: TabSwitchProps<T> & { ref?: React.ForwardedRef<HTMLDivElement> }
|
|
162
|
+
): React.ReactElement
|
|
163
|
+
```
|
|
@@ -183,6 +183,7 @@ See each view's reference: [TableView](../components/table-view.md) ·
|
|
|
183
183
|
|
|
184
184
|
- **Empty `data`** → all views render their empty state; pass `isLoading` upstream if you fetch async.
|
|
185
185
|
- **Tree tab missing?** No hierarchy was detected. Supply `treeConfig` explicitly or check your `childrenField` / `parentField`.
|
|
186
|
+
- **Unwanted filters?** The panel auto-detects filterable text fields with few unique values (e.g. `id`, `name`). Set `filterable: false` on a field to exclude it. For a field with many options, set `filterVariant: "searchable-select"` to render a searchable dropdown instead of a long checkbox list.
|
|
186
187
|
- **Saved Views don't persist** in tab mode — that's a known limitation documented in [`DataViewsConfigPanel`](../components/data-views-config-panel.md). Use composable mode for real persistence.
|
|
187
188
|
|
|
188
189
|
## Related
|