torch-glare 2.1.4 → 2.1.7
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/DataViews/DataViewsConfigPanel.tsx +1 -1
- package/apps/lib/components/DataViews/DataViewsLayout.tsx +9 -0
- package/apps/lib/components/DataViews/FilterPanel.tsx +4 -3
- package/apps/lib/components/DataViews/InboxView.tsx +15 -1
- package/apps/lib/components/Drawer.tsx +23 -4
- package/dist/bin/index.js +2 -1
- package/dist/bin/index.js.map +1 -1
- package/docs/components/data-views-layout.md +18 -1
- package/docs/components/drawer.md +527 -668
- package/docs/components/inbox-view.md +159 -0
- package/docs/components/kanban-view.md +125 -0
- package/docs/components/table-view.md +131 -0
- package/docs/components/tree-view.md +136 -0
- package/docs/how-to/data-views-from-backend-response.md +191 -0
- package/package.json +3 -2
- package/apps/lib/components/DataViews/ARCHITECTURE.md +0 -439
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: InboxView
|
|
3
|
+
description: Standalone inbox/list view for DataViews — a master list with read/starred/priority states and an optional detail pane. Use inside DataViewsLayout (tab mode) or directly in Composable Mode.
|
|
4
|
+
group: Data Display
|
|
5
|
+
keywords: [data-views, inbox-view, inbox, list, master-detail, read, starred, priority, attachment, composable, dynamic-data]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# InboxView
|
|
9
|
+
|
|
10
|
+
> The inbox renderer behind `DataViewsLayout`'s "Inbox" tab. It renders records as a scannable list with read / starred / priority / attachment affordances, plus an optional detail pane. In tab mode the layout renders it for you; render it directly only in **Composable Mode**.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Part of `torch-glare`. Ships with the `DataViews` folder when you run `npx torch-glare add DataViews` — no separate install. It depends on the shared `Badge`, `Button`, `Avatar`, `Card`, `Divider`, and `TabFormItem` components plus `lucide-react`.
|
|
15
|
+
|
|
16
|
+
## Import
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { InboxView, useDataViewsState } from "torch-glare"
|
|
20
|
+
import type { InboxViewProps, InboxConfig, FieldConfig } from "torch-glare"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## When to use it directly
|
|
24
|
+
|
|
25
|
+
| Situation | Use |
|
|
26
|
+
|---|---|
|
|
27
|
+
| You want the standard tabbed multi-view UI | `DataViewsLayout` with `views={{ inbox: true }}` — it mounts `InboxView` for you. |
|
|
28
|
+
| You want a custom master-detail layout | Render `InboxView` directly with state from `useDataViewsState`, and supply `renderDetail`. |
|
|
29
|
+
|
|
30
|
+
## Field auto-detection
|
|
31
|
+
|
|
32
|
+
InboxView auto-detects these record fields and maps them to UI affordances.
|
|
33
|
+
Override any of them with `inboxConfig`.
|
|
34
|
+
|
|
35
|
+
| Detected field | Affordance |
|
|
36
|
+
|---|---|
|
|
37
|
+
| `isRead` | Read/unread weight |
|
|
38
|
+
| `isStarred` | Star toggle |
|
|
39
|
+
| `hasAttachment` | Paperclip icon |
|
|
40
|
+
| `priority` | Priority flag |
|
|
41
|
+
|
|
42
|
+
## Composable Mode example
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import { InboxView, useDataViewsState } from "torch-glare"
|
|
46
|
+
import type { FieldConfig, InboxConfig } from "torch-glare"
|
|
47
|
+
|
|
48
|
+
const messages = [
|
|
49
|
+
{ id: 1, subject: "Welcome", from: { name: "Ada" }, isRead: false, isStarred: true, sentAt: "2024-06-01" },
|
|
50
|
+
{ id: 2, subject: "Invoice", from: { name: "Billing" }, isRead: true, hasAttachment: true, sentAt: "2024-06-02" },
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
const fields: FieldConfig[] = [
|
|
54
|
+
{ path: "subject", type: "text" },
|
|
55
|
+
{ path: "from.name", label: "From", type: "text" },
|
|
56
|
+
{ path: "sentAt", type: "date-format", dateFormat: "YYYY-MM-DD" },
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
const inboxConfig: InboxConfig = {
|
|
60
|
+
titlePath: "subject",
|
|
61
|
+
previewPath: "from.name",
|
|
62
|
+
dateField: "sentAt",
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function Mailbox() {
|
|
66
|
+
const state = useDataViewsState({ data: messages, fields })
|
|
67
|
+
const [selectedId, setSelectedId] = useState<number | null>(null)
|
|
68
|
+
return (
|
|
69
|
+
<InboxView
|
|
70
|
+
data={state.flatItems}
|
|
71
|
+
fields={state.resolvedFields}
|
|
72
|
+
config={state.config}
|
|
73
|
+
inboxConfig={inboxConfig}
|
|
74
|
+
selectedItemId={selectedId}
|
|
75
|
+
renderDetail={(item) =>
|
|
76
|
+
item ? <MessageDetail message={item} /> : <Empty />
|
|
77
|
+
}
|
|
78
|
+
/>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Link rows to routes (framework-agnostic)
|
|
84
|
+
|
|
85
|
+
`itemHref` turns each row into a link. By default the card renders a plain `<a>`
|
|
86
|
+
(full-page navigation), so it works in any framework. For client-side routing,
|
|
87
|
+
pass your router's link via `linkComponent` — this is what makes navigation
|
|
88
|
+
behave consistently across environments. Without it you get a normal `<a>`.
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
// Next.js
|
|
92
|
+
import Link from "next/link"
|
|
93
|
+
|
|
94
|
+
<InboxView
|
|
95
|
+
data={state.flatItems}
|
|
96
|
+
fields={state.resolvedFields}
|
|
97
|
+
config={state.config}
|
|
98
|
+
itemHref={(item, id) => `/messages/${id}`}
|
|
99
|
+
linkComponent={Link} // React Router users pass their <Link> the same way
|
|
100
|
+
/>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
> Via `DataViewsLayout` (tab mode) the same prop is named `inboxLinkComponent`.
|
|
104
|
+
|
|
105
|
+
## API Reference
|
|
106
|
+
|
|
107
|
+
### `InboxViewProps`
|
|
108
|
+
|
|
109
|
+
| Prop | Type | Default | Description |
|
|
110
|
+
|---|---|---|---|
|
|
111
|
+
| `data` | `DynamicRecord[]` | — (required) | Records to render as list items. Pass `state.flatItems`. |
|
|
112
|
+
| `fields` | `FieldConfig[]` | — (required) | Field map controlling list-item content. Pass `state.resolvedFields`. |
|
|
113
|
+
| `config` | `ViewConfig` | — (required) | View config from `useDataViewsState`. |
|
|
114
|
+
| `inboxConfig` | `InboxConfig` | auto-detected | Overrides for which record paths map to title/preview/avatar/date/read/starred/attachment/priority. |
|
|
115
|
+
| `columns` | `DynamicColumnConfig[]` | `undefined` | Explicit column overrides. Usually derived from `fields`. |
|
|
116
|
+
| `onDataUpdate` | `(data: DynamicRecord[]) => void` | `undefined` | Called when item data changes (e.g. toggling read/starred). |
|
|
117
|
+
| `filters` | `DynamicFilterConfig[]` | `undefined` | Explicit filter definitions. Usually inferred from `filterable` fields. |
|
|
118
|
+
| `filterState` | `FilterState` | uncontrolled | Controlled filter state. Pair with `onFilterChange`. |
|
|
119
|
+
| `onFilterChange` | `(filters: FilterState) => void` | `undefined` | Fires when a filter changes. |
|
|
120
|
+
| `showFilters` | `boolean` | `true` | Show the integrated filter panel. |
|
|
121
|
+
| `itemHref` | `(item: DynamicRecord, id: any) => string` | `undefined` | When set, each row becomes a link to the returned href. |
|
|
122
|
+
| `linkComponent` | `ElementType` | `"a"` | Component used to render each item's link when `itemHref` is set. Pass your router's link (Next.js `Link`, React Router `Link`) for client-side navigation. Defaults to a plain `<a>` (full-page nav). |
|
|
123
|
+
| `selectedItemId` | `any` | `undefined` | Id of the currently selected row (drives the detail pane + highlight). |
|
|
124
|
+
| `renderDetail` | `(item: DynamicRecord \| null) => ReactNode` | `undefined` | Renders the right-hand detail pane for the selected item. |
|
|
125
|
+
|
|
126
|
+
### `InboxConfig`
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
type InboxConfig = {
|
|
130
|
+
starredField?: string
|
|
131
|
+
readField?: string
|
|
132
|
+
attachmentField?: string
|
|
133
|
+
priorityField?: string
|
|
134
|
+
titlePath?: string
|
|
135
|
+
previewPath?: string
|
|
136
|
+
avatarPath?: string
|
|
137
|
+
dateField?: string
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
See [`DataViewsLayout`](./data-views-layout.md#fieldconfig) for `FieldConfig`,
|
|
142
|
+
`FilterState`, and related shapes.
|
|
143
|
+
|
|
144
|
+
## Accessibility
|
|
145
|
+
|
|
146
|
+
- The all/starred/priority switcher uses [`TabFormItem`](./tab-form-item.md) (full keyboard support).
|
|
147
|
+
- Star/archive/delete actions are real `<button>`s with accessible labels.
|
|
148
|
+
- Avatars fall back to initials via [`Avatar`](./avatar.md).
|
|
149
|
+
|
|
150
|
+
## Theming
|
|
151
|
+
|
|
152
|
+
Uses only `*-presentation-*` design tokens. Control the scheme via the parent
|
|
153
|
+
`DataViewsLayout`'s `theme`.
|
|
154
|
+
|
|
155
|
+
## Related
|
|
156
|
+
|
|
157
|
+
- [`DataViewsLayout`](./data-views-layout.md) — the tabbed container that renders this for you
|
|
158
|
+
- [`TableView`](./table-view.md) · [`KanbanView`](./kanban-view.md) · [`TreeView`](./tree-view.md) — sibling views
|
|
159
|
+
- [How-to: Render a backend response with DataViews](../how-to/data-views-from-backend-response.md)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: KanbanView
|
|
3
|
+
description: Standalone kanban board view for DataViews — groups records into columns by a field and renders each as a card. Use inside DataViewsLayout (tab mode) or directly in Composable Mode.
|
|
4
|
+
group: Data Display
|
|
5
|
+
keywords: [data-views, kanban-view, kanban, board, columns, group-by, cards, composable, dynamic-data, fields]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# KanbanView
|
|
9
|
+
|
|
10
|
+
> The board renderer behind `DataViewsLayout`'s "Board" tab. It groups records into columns by `groupByField` and renders each record as a card. In tab mode the layout renders it for you; render it directly only in **Composable Mode**.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Part of `torch-glare`. Ships with the `DataViews` folder when you run `npx torch-glare add DataViews` — no separate install. It depends on the shared `Button` component, the `DataViewCard` layout, and `lucide-react`.
|
|
15
|
+
|
|
16
|
+
## Import
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { KanbanView, useDataViewsState } from "torch-glare"
|
|
20
|
+
import type { KanbanViewProps, FieldConfig } from "torch-glare"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## When to use it directly
|
|
24
|
+
|
|
25
|
+
| Situation | Use |
|
|
26
|
+
|---|---|
|
|
27
|
+
| You want the standard tabbed multi-view UI | `DataViewsLayout` with `views={{ kanban: true }}` — it mounts `KanbanView` for you. |
|
|
28
|
+
| You want a custom layout (e.g. kanban beside a table) | Render `KanbanView` directly with state from `useDataViewsState`. |
|
|
29
|
+
|
|
30
|
+
## Composable Mode example
|
|
31
|
+
|
|
32
|
+
`KanbanView` groups by the `groupByField` path — every distinct value becomes a
|
|
33
|
+
column. Column colors are assigned deterministically, or per-value via the
|
|
34
|
+
field's `kanbanVariants`.
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { KanbanView, useDataViewsState } from "torch-glare"
|
|
38
|
+
import type { FieldConfig } from "torch-glare"
|
|
39
|
+
|
|
40
|
+
const tasks = [
|
|
41
|
+
{ id: 1, title: "Spec API", status: "Todo", assignee: "Ada" },
|
|
42
|
+
{ id: 2, title: "Build UI", status: "In Progress", assignee: "Linus" },
|
|
43
|
+
{ id: 3, title: "Ship", status: "Done", assignee: "Grace" },
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
const fields: FieldConfig[] = [
|
|
47
|
+
{ path: "title", type: "text" },
|
|
48
|
+
{
|
|
49
|
+
path: "status",
|
|
50
|
+
type: "enum-badge",
|
|
51
|
+
kanbanVariants: {
|
|
52
|
+
Todo: { label: "To Do", color: "gray" },
|
|
53
|
+
"In Progress": { label: "In Progress", color: "blue" },
|
|
54
|
+
Done: { label: "Done", color: "green" },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{ path: "assignee", type: "text" },
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
function TaskBoard() {
|
|
61
|
+
const state = useDataViewsState({ data: tasks, fields })
|
|
62
|
+
return (
|
|
63
|
+
<KanbanView
|
|
64
|
+
data={state.flatItems}
|
|
65
|
+
fields={state.resolvedFields}
|
|
66
|
+
config={state.config}
|
|
67
|
+
groupByField="status"
|
|
68
|
+
titleField="title"
|
|
69
|
+
/>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Column header actions
|
|
75
|
+
|
|
76
|
+
Pass `onColumnAction` to show an overflow (⋯) button on each column header. When
|
|
77
|
+
omitted the button is hidden.
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
<KanbanView
|
|
81
|
+
data={state.flatItems}
|
|
82
|
+
fields={state.resolvedFields}
|
|
83
|
+
config={state.config}
|
|
84
|
+
groupByField="status"
|
|
85
|
+
onColumnAction={(columnId) => openColumnMenu(columnId)}
|
|
86
|
+
/>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## API Reference
|
|
90
|
+
|
|
91
|
+
### `KanbanViewProps`
|
|
92
|
+
|
|
93
|
+
| Prop | Type | Default | Description |
|
|
94
|
+
|---|---|---|---|
|
|
95
|
+
| `data` | `DynamicRecord[]` | — (required) | Records to group into columns. Pass `state.flatItems` in composable mode. |
|
|
96
|
+
| `fields` | `FieldConfig[]` | — (required) | Field map controlling card content. Pass `state.resolvedFields`. |
|
|
97
|
+
| `config` | `ViewConfig` | — (required) | View config from `useDataViewsState`. |
|
|
98
|
+
| `groupByField` | `string` | `"status"` | Dot-path to the field whose distinct values become columns. |
|
|
99
|
+
| `titleField` | `string` | first visible non-group field | Dot-path of the field rendered as the card title. |
|
|
100
|
+
| `columns` | `DynamicColumnConfig[]` | `undefined` | Explicit column overrides. Usually derived from `fields`. |
|
|
101
|
+
| `onDataUpdate` | `(data: DynamicRecord[]) => void` | `undefined` | Called when a card moves between columns (updates the group-by value). |
|
|
102
|
+
| `onColumnAction` | `(columnId: string) => void` | `undefined` | Click handler for the column header overflow button. When omitted, the button is hidden. |
|
|
103
|
+
|
|
104
|
+
Per-column colors come from each field's `kanbanVariants` map
|
|
105
|
+
(`{ [value]: { label?, color? } }`). Available `color` keys: `gray`, `purple`,
|
|
106
|
+
`orange`, `blue`, `green`, `red`. See
|
|
107
|
+
[`DataViewsLayout`](./data-views-layout.md#fieldconfig) for the full
|
|
108
|
+
`FieldConfig` shape.
|
|
109
|
+
|
|
110
|
+
## Accessibility
|
|
111
|
+
|
|
112
|
+
- Cards are keyboard-focusable; the column overflow button is a real `<button>`.
|
|
113
|
+
- Card titles use semantic heading markup within each [`DataViewCard`](./card.md).
|
|
114
|
+
|
|
115
|
+
## Theming
|
|
116
|
+
|
|
117
|
+
Uses `*-presentation-*` tokens plus a small set of deeply-saturated column-header
|
|
118
|
+
fills matched to `glare-torch-mode` raw tokens. Control the scheme via the
|
|
119
|
+
parent `DataViewsLayout`'s `theme`.
|
|
120
|
+
|
|
121
|
+
## Related
|
|
122
|
+
|
|
123
|
+
- [`DataViewsLayout`](./data-views-layout.md) — the tabbed container that renders this for you
|
|
124
|
+
- [`TableView`](./table-view.md) · [`InboxView`](./inbox-view.md) · [`TreeView`](./tree-view.md) — sibling views
|
|
125
|
+
- [How-to: Render a backend response with DataViews](../how-to/data-views-from-backend-response.md)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TableView
|
|
3
|
+
description: Standalone table view for DataViews — sortable columns, row selection, and an integrated filter panel. Use inside DataViewsLayout (tab mode) or directly in Composable Mode.
|
|
4
|
+
group: Data Display
|
|
5
|
+
keywords: [data-views, table-view, table, sortable, columns, selection, filter, composable, dynamic-data, fields]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# TableView
|
|
9
|
+
|
|
10
|
+
> The table renderer behind `DataViewsLayout`'s "List" tab. In tab mode the layout renders it for you. Render it directly only in **Composable Mode** (custom layouts), wiring it with `useDataViewsState`.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Part of `torch-glare`. Ships with the `DataViews` folder when you run `npx torch-glare add DataViews` — no separate install. It depends on the shared `Card`, `Checkbox`, and `Table` components plus the colocated `FilterPanel`.
|
|
15
|
+
|
|
16
|
+
## Import
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { TableView, useDataViewsState } from "torch-glare"
|
|
20
|
+
import type { TableViewProps, FieldConfig } from "torch-glare"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## When to use it directly
|
|
24
|
+
|
|
25
|
+
| Situation | Use |
|
|
26
|
+
|---|---|
|
|
27
|
+
| You want the standard tabbed multi-view UI | `DataViewsLayout` — it mounts `TableView` for you. Don't render this yourself. |
|
|
28
|
+
| You want a custom layout (e.g. table beside a kanban) | Render `TableView` directly with state from `useDataViewsState`. |
|
|
29
|
+
| You only ever need a table and nothing else | Render `TableView` directly, or just use the simpler [`Table`](./table.md) / [`DataTable`](./data-table.md). |
|
|
30
|
+
|
|
31
|
+
## Composable Mode example
|
|
32
|
+
|
|
33
|
+
`TableView` is controlled — it does not own field detection or config. Pull those from `useDataViewsState` (which auto-detects fields and columns from your data) and pass them down.
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { TableView, useDataViewsState } from "torch-glare"
|
|
37
|
+
import type { FieldConfig } from "torch-glare"
|
|
38
|
+
|
|
39
|
+
const employees = [
|
|
40
|
+
{ id: 1, name: "Ada Lovelace", role: "Engineer", salary: 120000, joinDate: "2024-04-12" },
|
|
41
|
+
{ id: 2, name: "Linus Torvalds", role: "Engineer", salary: 145000, joinDate: "2023-09-01" },
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
const fields: FieldConfig[] = [
|
|
45
|
+
{ path: "name", label: "Name", type: "text" },
|
|
46
|
+
{ path: "role", type: "text", filterable: true },
|
|
47
|
+
{ path: "salary", type: "currency", currency: "USD" },
|
|
48
|
+
{ path: "joinDate", type: "date-format", dateFormat: "YYYY-MM-DD" },
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
function EmployeesTable() {
|
|
52
|
+
const state = useDataViewsState({ data: employees, fields })
|
|
53
|
+
return (
|
|
54
|
+
<TableView
|
|
55
|
+
data={state.flatItems}
|
|
56
|
+
fields={state.resolvedFields}
|
|
57
|
+
config={state.config}
|
|
58
|
+
onSortChange={(sortBy, sortOrder) =>
|
|
59
|
+
state.setConfig({ ...state.config, sortBy, sortOrder })
|
|
60
|
+
}
|
|
61
|
+
filterState={state.filterState}
|
|
62
|
+
onFilterChange={state.setFilterState}
|
|
63
|
+
/>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Hide the inline filter panel
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
<TableView
|
|
72
|
+
data={state.flatItems}
|
|
73
|
+
fields={state.resolvedFields}
|
|
74
|
+
config={state.config}
|
|
75
|
+
showFilters={false}
|
|
76
|
+
/>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Controlled sorting
|
|
80
|
+
|
|
81
|
+
`TableView` does not sort internally — it calls `onSortChange` and reads the
|
|
82
|
+
active sort from `config.sortBy` / `config.sortOrder`. Wire it to your config
|
|
83
|
+
state (or your backend) to make headers interactive.
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
<TableView
|
|
87
|
+
data={rows}
|
|
88
|
+
fields={fields}
|
|
89
|
+
config={{ defaultView: "table", sortBy: "name", sortOrder: "asc" }}
|
|
90
|
+
onSortChange={(sortBy, sortOrder) => refetch({ sortBy, sortOrder })}
|
|
91
|
+
/>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## API Reference
|
|
95
|
+
|
|
96
|
+
### `TableViewProps`
|
|
97
|
+
|
|
98
|
+
| Prop | Type | Default | Description |
|
|
99
|
+
|---|---|---|---|
|
|
100
|
+
| `data` | `DynamicRecord[]` | — (required) | Flat array of rows to render. In composable mode pass `state.flatItems`. |
|
|
101
|
+
| `fields` | `FieldConfig[]` | — (required) | Field map controlling which columns render and how cells format. Pass `state.resolvedFields` for auto-detected fields. |
|
|
102
|
+
| `config` | `ViewConfig` | — (required) | View config. `sortBy` / `sortOrder` drive the active sort indicator. |
|
|
103
|
+
| `columns` | `DynamicColumnConfig[]` | `undefined` | Explicit column overrides (visibility/order). Usually derived from `fields`. |
|
|
104
|
+
| `onDataUpdate` | `(data: DynamicRecord[]) => void` | `undefined` | Called when row data changes (e.g. inline selection). |
|
|
105
|
+
| `onSortChange` | `(sortBy: string, sortOrder: "asc" \| "desc") => void` | `undefined` | Fires on header click. When omitted, headers are not sortable. |
|
|
106
|
+
| `filters` | `DynamicFilterConfig[]` | `undefined` | Explicit filter definitions. Usually inferred from `filterable` fields. |
|
|
107
|
+
| `filterState` | `FilterState` | uncontrolled | Controlled filter state. Pair with `onFilterChange`. |
|
|
108
|
+
| `onFilterChange` | `(filters: FilterState) => void` | `undefined` | Fires when a filter changes. When provided, the view is controlled. |
|
|
109
|
+
| `showFilters` | `boolean` | `true` | Show the integrated filter panel. |
|
|
110
|
+
|
|
111
|
+
`DynamicColumnConfig`, `DynamicFilterConfig`, `FilterState`, and `FieldConfig`
|
|
112
|
+
share the same shapes documented in
|
|
113
|
+
[`DataViewsLayout`](./data-views-layout.md#api-reference).
|
|
114
|
+
|
|
115
|
+
## Accessibility
|
|
116
|
+
|
|
117
|
+
- Built on the accessible [`Table`](./table.md) primitive (semantic `<table>` markup, sortable headers).
|
|
118
|
+
- Row selection uses `TableCheckbox` with proper labelling.
|
|
119
|
+
- Filter checkboxes carry labels and `htmlFor` linkage.
|
|
120
|
+
|
|
121
|
+
## Theming
|
|
122
|
+
|
|
123
|
+
Uses only `*-presentation-*` design tokens. Wrap with `ThemeProvider` or pass a
|
|
124
|
+
`theme` to the parent `DataViewsLayout` to control the color scheme.
|
|
125
|
+
|
|
126
|
+
## Related
|
|
127
|
+
|
|
128
|
+
- [`DataViewsLayout`](./data-views-layout.md) — the tabbed multi-view container that renders this for you
|
|
129
|
+
- [`KanbanView`](./kanban-view.md) · [`InboxView`](./inbox-view.md) · [`TreeView`](./tree-view.md) — the sibling views
|
|
130
|
+
- [`Table`](./table.md) / [`DataTable`](./data-table.md) — lower-level table components
|
|
131
|
+
- [How-to: Render a backend response with DataViews](../how-to/data-views-from-backend-response.md)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TreeView
|
|
3
|
+
description: Standalone hierarchical tree view for DataViews — a sidebar tree of nodes with a right pane (table or card) for the selected node. Use inside DataViewsLayout (tab mode) or directly in Composable Mode.
|
|
4
|
+
group: Data Display
|
|
5
|
+
keywords: [data-views, tree-view, tree, hierarchy, nested, sidebar, parent-child, children, composable, dynamic-data]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# TreeView
|
|
9
|
+
|
|
10
|
+
> The tree renderer behind `DataViewsLayout`'s "Tree" tab. It builds a hierarchy from your records (via a `children[]` array or a `parentId` reference) and shows a sidebar tree with a right pane for the selected node. In tab mode the layout renders it for you — and auto-hides the Tree tab when no hierarchy is detected. Render it directly only in **Composable Mode**.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Part of `torch-glare`. Ships with the `DataViews` folder when you run `npx torch-glare add DataViews` — no separate install. It reuses the sibling `TableView`, the `Card` component, a colocated tree sidebar/drawer, and `lucide-react`.
|
|
15
|
+
|
|
16
|
+
## Import
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { TreeView, useDataViewsState } from "torch-glare"
|
|
20
|
+
import type { TreeViewProps, TreeConfig, FieldConfig } from "torch-glare"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## When to use it directly
|
|
24
|
+
|
|
25
|
+
| Situation | Use |
|
|
26
|
+
|---|---|
|
|
27
|
+
| You want the standard tabbed multi-view UI | `DataViewsLayout` — the Tree tab appears automatically when hierarchy is detected. |
|
|
28
|
+
| You want a custom layout with an always-on tree | Render `TreeView` directly with state from `useDataViewsState`. |
|
|
29
|
+
| You want a file/folder tree without the data-grid pane | Use [`TreeFolder`](./tree-drop-down.md) or [`TreeSubLayout`](./tree-sub-layout.md) instead. |
|
|
30
|
+
|
|
31
|
+
## Hierarchy detection
|
|
32
|
+
|
|
33
|
+
`TreeView` auto-detects shape from your data. Override with `treeConfig`:
|
|
34
|
+
|
|
35
|
+
- **Nested** — each record carries a `children: []` array.
|
|
36
|
+
- **Flat / adjacency list** — each record carries a `parentId` (or similar) pointing at its parent's id.
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
// nested
|
|
40
|
+
const departments = [
|
|
41
|
+
{ id: 1, name: "Engineering", children: [
|
|
42
|
+
{ id: 2, name: "Platform" },
|
|
43
|
+
{ id: 3, name: "Product" },
|
|
44
|
+
]},
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
// flat
|
|
48
|
+
const rows = [
|
|
49
|
+
{ id: 1, name: "Engineering", parentId: null },
|
|
50
|
+
{ id: 2, name: "Platform", parentId: 1 },
|
|
51
|
+
]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Composable Mode example
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { TreeView, useDataViewsState } from "torch-glare"
|
|
58
|
+
import type { FieldConfig, TreeConfig } from "torch-glare"
|
|
59
|
+
|
|
60
|
+
const fields: FieldConfig[] = [
|
|
61
|
+
{ path: "name", type: "text" },
|
|
62
|
+
{ path: "headcount", type: "number" },
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
const treeConfig: TreeConfig = {
|
|
66
|
+
childrenField: "children",
|
|
67
|
+
nodeLabel: "name",
|
|
68
|
+
defaultExpanded: "roots", // "all" | "roots" | "none"
|
|
69
|
+
defaultRightPane: "table", // "table" | "card"
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function OrgTree() {
|
|
73
|
+
const state = useDataViewsState({ data: departments, fields, treeConfig })
|
|
74
|
+
return (
|
|
75
|
+
<TreeView
|
|
76
|
+
data={state.items}
|
|
77
|
+
fields={state.resolvedFields}
|
|
78
|
+
config={state.config}
|
|
79
|
+
treeConfig={treeConfig}
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## API Reference
|
|
86
|
+
|
|
87
|
+
### `TreeViewProps`
|
|
88
|
+
|
|
89
|
+
| Prop | Type | Default | Description |
|
|
90
|
+
|---|---|---|---|
|
|
91
|
+
| `data` | `DynamicRecord[]` | — (required) | Records to build the hierarchy from. Pass `state.items` (nested) in composable mode. |
|
|
92
|
+
| `fields` | `FieldConfig[]` | — (required) | Field map for the right-pane table/card. Pass `state.resolvedFields`. |
|
|
93
|
+
| `config` | `ViewConfig` | — (required) | View config from `useDataViewsState`. |
|
|
94
|
+
| `treeConfig` | `TreeConfig` | auto-detected | Hierarchy + expansion + right-pane config (see below). |
|
|
95
|
+
| `columns` | `DynamicColumnConfig[]` | `undefined` | Explicit column overrides for the right-pane table. |
|
|
96
|
+
| `onDataUpdate` | `(data: DynamicRecord[]) => void` | `undefined` | Called when nodes move (drag-and-drop reparent), if `dndEnabled`. |
|
|
97
|
+
| `filters` | `DynamicFilterConfig[]` | `undefined` | Explicit filter definitions. Usually inferred from `filterable` fields. |
|
|
98
|
+
| `filterState` | `FilterState` | uncontrolled | Controlled filter state. Pair with `onFilterChange`. |
|
|
99
|
+
| `onFilterChange` | `(filters: FilterState) => void` | `undefined` | Fires when a filter changes. |
|
|
100
|
+
| `showFilters` | `boolean` | `true` | Show the integrated filter panel. |
|
|
101
|
+
|
|
102
|
+
### `TreeConfig`
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
type TreeConfig = {
|
|
106
|
+
childrenField?: string // nested mode: array property holding children
|
|
107
|
+
parentField?: string // flat mode: property pointing at the parent id
|
|
108
|
+
idField?: string // id property (default "id")
|
|
109
|
+
orderField?: string // optional ordering within siblings
|
|
110
|
+
nodeLabel?: string // which field labels each tree node
|
|
111
|
+
defaultExpanded?: "all" | "roots" | "none"
|
|
112
|
+
defaultRightPane?: "table" | "card" // "details" accepted as a deprecated alias of "card"
|
|
113
|
+
dndEnabled?: boolean // enable drag-and-drop reparenting
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
See [`DataViewsLayout`](./data-views-layout.md#fieldconfig) for `FieldConfig`,
|
|
118
|
+
`FilterState`, and related shapes.
|
|
119
|
+
|
|
120
|
+
## Accessibility
|
|
121
|
+
|
|
122
|
+
- Tree rows expose `role="treeitem"` with `aria-expanded` and `aria-selected`.
|
|
123
|
+
- On mobile the sidebar collapses into a drawer with a labelled trigger.
|
|
124
|
+
- The right-pane table inherits [`TableView`](./table-view.md)'s accessibility.
|
|
125
|
+
|
|
126
|
+
## Theming
|
|
127
|
+
|
|
128
|
+
Uses only `*-presentation-*` design tokens. Control the scheme via the parent
|
|
129
|
+
`DataViewsLayout`'s `theme`.
|
|
130
|
+
|
|
131
|
+
## Related
|
|
132
|
+
|
|
133
|
+
- [`DataViewsLayout`](./data-views-layout.md) — the tabbed container that renders this for you
|
|
134
|
+
- [`TableView`](./table-view.md) · [`KanbanView`](./kanban-view.md) · [`InboxView`](./inbox-view.md) — sibling views
|
|
135
|
+
- [`TreeFolder`](./tree-drop-down.md) / [`TreeSubLayout`](./tree-sub-layout.md) — non-grid tree navigation
|
|
136
|
+
- [How-to: Render a backend response with DataViews](../how-to/data-views-from-backend-response.md)
|