@nanahoshi/mona-ui 0.39.1 → 0.41.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/docs/api/common.md +1 -1
- package/docs/api/grid.md +214 -17
- package/docs/api/i18n.md +36 -0
- package/docs/api/kanban.md +222 -0
- package/docs/api/locales.md +14 -14
- package/docs/api/sortable.md +189 -0
- package/docs/api/tabs.md +20 -0
- package/docs/grid-selection.md +134 -9
- package/docs/grid-state-export.md +56 -6
- package/docs/grid-tree.md +279 -0
- package/docs/kanban.md +293 -0
- package/docs/sortable.md +320 -0
- package/docs/tabs.md +59 -10
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-colgroup.component-Lv3GunpV.mjs → nanahoshi-mona-ui-grid-grid-colgroup.component-DpszxgFY.mjs} +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-BYH9XbCV.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-CpvzAcX8.mjs} +4 -3
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-BoSXXLKQ.mjs → nanahoshi-mona-ui-grid-grid-list.component-tRmEWiQR.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-Df2gfS0X.mjs → nanahoshi-mona-ui-grid-grid-row.component-eET6dh2Q.mjs} +52 -35
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-xjrcCXXF.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-8h2EMexB.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-grid.styles-aPD3c2A6.mjs → nanahoshi-mona-ui-grid-grid.styles-wAf6jsT9.mjs} +646 -20
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +1663 -22
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +56 -0
- package/fesm2022/nanahoshi-mona-ui-kanban.mjs +660 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +11 -0
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +17 -0
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +17 -0
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +17 -0
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +11 -0
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +17 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +11 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +11 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +21 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +17 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +21 -0
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +11 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +11 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +11 -0
- package/fesm2022/nanahoshi-mona-ui-sortable.mjs +733 -0
- package/fesm2022/nanahoshi-mona-ui-tabs.mjs +112 -5
- package/i18n/catalogs/en-US.messages.json +11 -0
- package/kanban/package.json +4 -0
- package/llms.txt +10 -5
- package/locales/ar-sa/ar-sa.messages.json +11 -0
- package/locales/de-de/de-de.messages.json +11 -0
- package/locales/es-es/es-es.messages.json +11 -0
- package/locales/fr-fr/fr-fr.messages.json +11 -0
- package/locales/id-id/id-id.messages.json +11 -0
- package/locales/it-it/it-it.messages.json +11 -0
- package/locales/ja-jp/ja-jp.messages.json +11 -0
- package/locales/ko-kr/ko-kr.messages.json +11 -0
- package/locales/pl-pl/pl-pl.messages.json +11 -0
- package/locales/pt-br/pt-br.messages.json +11 -0
- package/locales/ru-ru/ru-ru.messages.json +11 -0
- package/locales/tr-tr/tr-tr.messages.json +11 -0
- package/locales/zh-cn/zh-cn.messages.json +11 -0
- package/locales/zh-tw/zh-tw.messages.json +11 -0
- package/package.json +9 -1
- package/sortable/package.json +4 -0
- package/types/nanahoshi-mona-ui-grid.d.ts +305 -3
- package/types/nanahoshi-mona-ui-i18n.d.ts +23 -0
- package/types/nanahoshi-mona-ui-kanban.d.ts +270 -0
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +11 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +11 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +11 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +11 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +11 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +11 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +11 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +11 -0
- package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +11 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +11 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +11 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +11 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +11 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +11 -0
- package/types/nanahoshi-mona-ui-sortable.d.ts +245 -0
- package/types/nanahoshi-mona-ui-tabs.d.ts +46 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# Tree List
|
|
2
|
+
|
|
3
|
+
> Show hierarchical rows in a grid, nested or linked by a parent key, with expandable levels.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/grid`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-grid[monaGridTree]`
|
|
8
|
+
|
|
9
|
+
`monaGridTree` shows the grid's rows as a tree: each row can have child rows, which show below it, indented, while it's expanded. The data can hold each item's children, or be flat, with each item naming its parent. Sorting, filtering, paging, selection, editing and export all keep working, on the rows as a tree.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Tell the grid how to find each row's children in one of two ways:
|
|
14
|
+
|
|
15
|
+
| Your data | Use | Example |
|
|
16
|
+
| :--- | :--- | :--- |
|
|
17
|
+
| Root items that hold their children, at any depth | `children`: the field holding them, or a function returning them | `children="subtasks"` |
|
|
18
|
+
| One flat list, each item naming its parent's `rowKey` value | `parentKey`: the field holding it, or a function returning it, with the grid's `rowKey` | `rowKey="id" parentKey="managerId"` |
|
|
19
|
+
|
|
20
|
+
Rows start collapsed. The expanded rows are a list of row keys you bind with `[(treeExpandedKeys)]`, so they survive paging, sorting and reloading the data. It's apart from the grid's own `expandedKeys`, which opens [detail rows](grid-rows.md).
|
|
21
|
+
|
|
22
|
+
**Use something else when:**
|
|
23
|
+
|
|
24
|
+
- The rows fall into groups by a column's value, such as orders by country. Use [Grouping & Aggregates](grid-grouping.md): the groups come from the data's values, not from its structure.
|
|
25
|
+
- People only browse the hierarchy and pick an item, without columns to compare. Use a [Tree View](tree-view.md).
|
|
26
|
+
- Each row has details of a different shape, such as an order's lines under the order. Use [detail rows](grid-rows.md).
|
|
27
|
+
|
|
28
|
+
## Import & Quick Start
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { GridColumnComponent, GridComponent, GridTreeDirective } from "@nanahoshi/mona-ui/grid";
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
protected readonly expandedIds = signal<unknown[]>([]);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```html
|
|
39
|
+
<mona-grid
|
|
40
|
+
aria-label="Project tasks"
|
|
41
|
+
children="subtasks"
|
|
42
|
+
rowKey="id"
|
|
43
|
+
[data]="tasks()"
|
|
44
|
+
monaGridTree
|
|
45
|
+
[(treeExpandedKeys)]="expandedIds">
|
|
46
|
+
<mona-grid-column expandable field="name" title="Task" />
|
|
47
|
+
<mona-grid-column field="owner" title="Owner" />
|
|
48
|
+
</mona-grid>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Examples
|
|
52
|
+
|
|
53
|
+
### Nested Children
|
|
54
|
+
|
|
55
|
+
`tasks-example.component.ts`
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { Component, signal } from "@angular/core";
|
|
59
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
60
|
+
import {
|
|
61
|
+
GridColumnComponent,
|
|
62
|
+
GridComponent,
|
|
63
|
+
GridSortableDirective,
|
|
64
|
+
GridToolbarTemplateDirective,
|
|
65
|
+
GridTreeDirective
|
|
66
|
+
} from "@nanahoshi/mona-ui/grid";
|
|
67
|
+
|
|
68
|
+
interface Task {
|
|
69
|
+
readonly hours: number;
|
|
70
|
+
readonly id: number;
|
|
71
|
+
readonly name: string;
|
|
72
|
+
readonly owner: string;
|
|
73
|
+
readonly subtasks?: readonly Task[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Component({
|
|
77
|
+
selector: "app-grid-tree-tasks-example",
|
|
78
|
+
imports: [
|
|
79
|
+
ButtonDirective,
|
|
80
|
+
GridColumnComponent,
|
|
81
|
+
GridComponent,
|
|
82
|
+
GridSortableDirective,
|
|
83
|
+
GridToolbarTemplateDirective,
|
|
84
|
+
GridTreeDirective
|
|
85
|
+
],
|
|
86
|
+
templateUrl: "./tasks-example.component.html"
|
|
87
|
+
})
|
|
88
|
+
export class GridTreeTasksExampleComponent {
|
|
89
|
+
protected readonly expandedIds = signal<unknown[]>([1]);
|
|
90
|
+
protected readonly tasks: readonly Task[] = [
|
|
91
|
+
{
|
|
92
|
+
id: 1,
|
|
93
|
+
name: "Website relaunch",
|
|
94
|
+
owner: "Amara Okafor",
|
|
95
|
+
hours: 120,
|
|
96
|
+
subtasks: [
|
|
97
|
+
{
|
|
98
|
+
id: 2,
|
|
99
|
+
name: "Design",
|
|
100
|
+
owner: "Mei Tanaka",
|
|
101
|
+
hours: 40,
|
|
102
|
+
subtasks: [
|
|
103
|
+
{ id: 3, name: "Wireframes", owner: "Mei Tanaka", hours: 16 },
|
|
104
|
+
{ id: 4, name: "Visual design", owner: "Sofia Rossi", hours: 24 }
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: 5,
|
|
109
|
+
name: "Build",
|
|
110
|
+
owner: "Lukas Weber",
|
|
111
|
+
hours: 64,
|
|
112
|
+
subtasks: [
|
|
113
|
+
{ id: 6, name: "Templates", owner: "Lukas Weber", hours: 40 },
|
|
114
|
+
{ id: 7, name: "Content migration", owner: "Noah Clarke", hours: 24 }
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
{ id: 8, name: "Launch review", owner: "Amara Okafor", hours: 16 }
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: 9,
|
|
122
|
+
name: "Mobile app",
|
|
123
|
+
owner: "Diego Ramos",
|
|
124
|
+
hours: 90,
|
|
125
|
+
subtasks: [
|
|
126
|
+
{ id: 10, name: "User research", owner: "Sofia Rossi", hours: 30 },
|
|
127
|
+
{ id: 11, name: "Prototype", owner: "Mei Tanaka", hours: 60 }
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
{ id: 12, name: "Quarterly report", owner: "Noah Clarke", hours: 12 }
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`tasks-example.component.html`
|
|
136
|
+
|
|
137
|
+
```html
|
|
138
|
+
<mona-grid
|
|
139
|
+
#tree="monaGridTree"
|
|
140
|
+
aria-label="Project tasks"
|
|
141
|
+
children="subtasks"
|
|
142
|
+
rowKey="id"
|
|
143
|
+
[data]="tasks"
|
|
144
|
+
[pageSize]="20"
|
|
145
|
+
monaGridSortable
|
|
146
|
+
monaGridTree
|
|
147
|
+
[(treeExpandedKeys)]="expandedIds">
|
|
148
|
+
<ng-template monaGridToolbarTemplate>
|
|
149
|
+
<button monaButton type="button" (click)="tree.expandAll()">Expand all</button>
|
|
150
|
+
<button monaButton type="button" (click)="tree.collapseAll()">Collapse all</button>
|
|
151
|
+
</ng-template>
|
|
152
|
+
<mona-grid-column expandable field="name" title="Task" />
|
|
153
|
+
<mona-grid-column field="owner" title="Owner" />
|
|
154
|
+
<mona-grid-column field="hours" title="Hours" type="number" [width]="100" />
|
|
155
|
+
</mona-grid>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Each task holds its subtasks, and the Task column has the toggles because it's `expandable`; without that on any column, the first visible data column has them. Sort a column, and each task's subtasks sort among themselves, under it. The toolbar's buttons call `expandAll()` and `collapseAll()` through the directive's `exportAs`, `monaGridTree`, and both report the new keys through `treeExpandedKeysChange`.
|
|
159
|
+
|
|
160
|
+
### Flat Data with Parent Keys
|
|
161
|
+
|
|
162
|
+
`org-chart-example.component.ts`
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { Component } from "@angular/core";
|
|
166
|
+
import {
|
|
167
|
+
GridColumnComponent,
|
|
168
|
+
GridComponent,
|
|
169
|
+
GridFilterableDirective,
|
|
170
|
+
GridTreeDirective
|
|
171
|
+
} from "@nanahoshi/mona-ui/grid";
|
|
172
|
+
|
|
173
|
+
interface Employee {
|
|
174
|
+
readonly id: number;
|
|
175
|
+
readonly location: string;
|
|
176
|
+
readonly managerId: number | null;
|
|
177
|
+
readonly name: string;
|
|
178
|
+
readonly title: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
@Component({
|
|
182
|
+
selector: "app-grid-tree-org-chart-example",
|
|
183
|
+
imports: [GridColumnComponent, GridComponent, GridFilterableDirective, GridTreeDirective],
|
|
184
|
+
templateUrl: "./org-chart-example.component.html"
|
|
185
|
+
})
|
|
186
|
+
export class GridTreeOrgChartExampleComponent {
|
|
187
|
+
/** Flat rows: each names its manager's id, and the CEO has none. */
|
|
188
|
+
protected readonly employees: readonly Employee[] = [
|
|
189
|
+
{ id: 1, managerId: null, name: "Amara Okafor", title: "Chief executive", location: "Lagos" },
|
|
190
|
+
{ id: 2, managerId: 1, name: "Lukas Weber", title: "VP engineering", location: "Berlin" },
|
|
191
|
+
{ id: 3, managerId: 1, name: "Diego Ramos", title: "VP product", location: "Lima" },
|
|
192
|
+
{ id: 4, managerId: 2, name: "Mei Tanaka", title: "Engineering manager", location: "Osaka" },
|
|
193
|
+
{ id: 5, managerId: 4, name: "Noah Clarke", title: "Engineer", location: "Toronto" },
|
|
194
|
+
{ id: 6, managerId: 4, name: "Priya Nair", title: "Engineer", location: "Pune" },
|
|
195
|
+
{ id: 7, managerId: 2, name: "Jonas Berg", title: "Site reliability lead", location: "Oslo" },
|
|
196
|
+
{ id: 8, managerId: 3, name: "Sofia Rossi", title: "Researcher", location: "Turin" },
|
|
197
|
+
{ id: 9, managerId: 3, name: "Lucas Martin", title: "Designer", location: "Lyon" }
|
|
198
|
+
];
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
`org-chart-example.component.html`
|
|
203
|
+
|
|
204
|
+
```html
|
|
205
|
+
<mona-grid
|
|
206
|
+
aria-label="Organization"
|
|
207
|
+
parentKey="managerId"
|
|
208
|
+
rowKey="id"
|
|
209
|
+
[data]="employees"
|
|
210
|
+
[monaGridFilterable]="{ enabled: true, type: 'row' }"
|
|
211
|
+
monaGridTree
|
|
212
|
+
[treeExpandedKeys]="[1]">
|
|
213
|
+
<mona-grid-column field="name" title="Name" />
|
|
214
|
+
<mona-grid-column field="title" title="Title" />
|
|
215
|
+
<mona-grid-column field="location" title="Location" />
|
|
216
|
+
</mona-grid>
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Every employee names a manager's `id` in `managerId`, and the chief executive names none. Type a name in the filter row, such as "Priya": the grid keeps the rows above each match, so you see where she sits, and expands them.
|
|
220
|
+
|
|
221
|
+
## Behavior
|
|
222
|
+
|
|
223
|
+
### Building the tree
|
|
224
|
+
|
|
225
|
+
- **With `children`**, the grid's `data` holds the root items, and the grid walks their children at any depth. An item that turns up again inside itself isn't repeated.
|
|
226
|
+
- **With `parentKey`**, an item is a root when its parent key is empty, names no row in the data, or names the item itself. Rows whose parents form a loop become roots, so no row is lost.
|
|
227
|
+
- Changing `data`, `children` or `parentKey` rebuilds the tree, and the expanded rows that still exist stay expanded.
|
|
228
|
+
|
|
229
|
+
### Sorting, filtering and paging
|
|
230
|
+
|
|
231
|
+
- **Sorting** orders each row's children among themselves, so children always stay under their parent.
|
|
232
|
+
- **Filtering** keeps the rows that match and every row above them, and expands those, reporting the new keys through `treeExpandedKeysChange`. A row that only leads to matches shows even if it doesn't match itself.
|
|
233
|
+
- **Paging** counts the rows that show: the roots, and the children of expanded rows.
|
|
234
|
+
- **Grouping** and row reordering are off in a tree, because the tree already decides where each row goes.
|
|
235
|
+
- **Selection** and **editing** work on tree rows as on any other, and select-all takes the rows that show.
|
|
236
|
+
|
|
237
|
+
### Export
|
|
238
|
+
|
|
239
|
+
`exportCsv`, `exportExcel` and `exportPdf` write every row, collapsed or not, in tree order. The workbook groups each row's children into an outline that the spreadsheet can collapse, and indents the tree column's cells by level, as the PDF does. See [State & Export](grid-state-export.md).
|
|
240
|
+
|
|
241
|
+
## Accessibility
|
|
242
|
+
|
|
243
|
+
With a tree, the grid's role is `treegrid`, and each row says where it sits: its level, its position among its siblings and whether it's expanded. The toggle is a pointer convenience, hidden from assistive technology, since the keyboard does the same on the tree column's cell.
|
|
244
|
+
|
|
245
|
+
### Keyboard
|
|
246
|
+
|
|
247
|
+
On the tree column's cell:
|
|
248
|
+
|
|
249
|
+
| Key | Action |
|
|
250
|
+
| --- | --- |
|
|
251
|
+
| `ArrowRight` | Expands a collapsed row. On an expanded row, or one without children, moves to the next cell. |
|
|
252
|
+
| `ArrowLeft` | Collapses an expanded row. Otherwise moves to the previous cell, or, when the tree column is the first, to the parent row's cell. |
|
|
253
|
+
|
|
254
|
+
`ArrowLeft` and `ArrowRight` swap in right-to-left layouts. The rest of the grid's keys are on [Grid Overview](grid.md#keyboard).
|
|
255
|
+
|
|
256
|
+
### ARIA
|
|
257
|
+
|
|
258
|
+
| Attribute | When present | Value |
|
|
259
|
+
| --- | --- | --- |
|
|
260
|
+
| `role` | On the tabular content region | `"treegrid"` |
|
|
261
|
+
| `aria-level` | On every body row | The row's depth, from 1 for a root |
|
|
262
|
+
| `aria-setsize` / `aria-posinset` | On every body row | How many siblings the row has, and its place among them |
|
|
263
|
+
| `aria-expanded` | On a row with children | Whether its children show |
|
|
264
|
+
|
|
265
|
+
## API
|
|
266
|
+
|
|
267
|
+
Everything below is imported from `@nanahoshi/mona-ui/grid`. Each name links to its reference page, with every input, output, property and method.
|
|
268
|
+
|
|
269
|
+
| Name | Kind | Description |
|
|
270
|
+
| --- | --- | --- |
|
|
271
|
+
| [`GridTreeDirective`](api/grid.md#gridtreedirective) | Directive | Shows the grid's rows as a tree: each row can have child rows, shown below it, indented, when it's expanded. |
|
|
272
|
+
|
|
273
|
+
### Types
|
|
274
|
+
|
|
275
|
+
| Type | Kind | Description |
|
|
276
|
+
| --- | --- | --- |
|
|
277
|
+
| [`GridTreeChildren`](api/grid.md#gridtreechildren) | Type alias | The field holding a data item's children, or a function returning them. |
|
|
278
|
+
|
|
279
|
+
**Related types:** [`GridKeySelector`](api/grid.md#gridkeyselector)
|
package/docs/kanban.md
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
# Kanban
|
|
2
|
+
|
|
3
|
+
> A board of columns that cards move between by dragging or with the keyboard, with column limits.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/kanban`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-kanban`
|
|
8
|
+
|
|
9
|
+
`KanbanComponent` lays out cards in columns by their status, such as To do, In progress and Done, and lets users move a card within its column or to another by dragging it, or with Control+Shift and the arrow keys. Each move is announced, and a column can have a limit that keeps cards from other columns out once it's full.
|
|
10
|
+
|
|
11
|
+
The board takes one flat array of cards and emits a new one after each move, with the moved card's status changed. Cards can be plain text or your own template.
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
Give the board its columns and its cards. Each column has a `status`, and each card goes in the column whose status its status field holds, in the order of the array. When the user moves a card, the board emits the array with the card in its new place; bind it two-way and the move renders.
|
|
16
|
+
|
|
17
|
+
**Use Kanban when:**
|
|
18
|
+
|
|
19
|
+
- Work moves through stages, and users move it themselves: tasks, issues, applicants, orders.
|
|
20
|
+
- A stage should hold only so many items at a time.
|
|
21
|
+
|
|
22
|
+
To let users reorder a single list, or a few lists of your own markup, use [Sortable](sortable.md), which this board is built on.
|
|
23
|
+
|
|
24
|
+
## Import & Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { type KanbanColumn, KanbanComponent } from "@nanahoshi/mona-ui/kanban";
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<mona-kanban aria-label="Event planning" [columns]="columns" [(data)]="tasks" />
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
protected readonly columns: readonly KanbanColumn[] = [
|
|
36
|
+
{ status: "todo", title: "To do" },
|
|
37
|
+
{ status: "doing", title: "In progress" },
|
|
38
|
+
{ status: "done", title: "Done" }
|
|
39
|
+
];
|
|
40
|
+
protected readonly tasks = signal<Task[]>([
|
|
41
|
+
{ id: 1, status: "todo", title: "Draft the newsletter" },
|
|
42
|
+
{ id: 2, status: "doing", title: "Design the poster" }
|
|
43
|
+
]);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`statusField` names the field that holds a card's status, `"status"` by default, and `textField` the field shown as its text, `"title"` by default. A card whose status matches no column isn't shown.
|
|
47
|
+
|
|
48
|
+
## Anatomy
|
|
49
|
+
|
|
50
|
+
| Directive | Selector | Template context | Replaces |
|
|
51
|
+
| --- | --- | --- | --- |
|
|
52
|
+
| `KanbanCardTemplateDirective` | `ng-template[monaKanbanCardTemplate]` | `$implicit`: the card; `column`; `index` in the column | The card's text |
|
|
53
|
+
| `KanbanColumnHeaderTemplateDirective` | `ng-template[monaKanbanColumnHeaderTemplate]` | `$implicit`: the column; `cards`; `count` | The column's title and count |
|
|
54
|
+
| `KanbanColumnFooterTemplateDirective` | `ng-template[monaKanbanColumnFooterTemplate]` | `$implicit`: the column; `cards`; `count` | Nothing: it adds a foot below the cards |
|
|
55
|
+
|
|
56
|
+
Bind the board's data to `monaKanbanCardTemplateOf` to type the card in the template; without it, the card is `any`. The header names the column, so a header template should keep its title.
|
|
57
|
+
|
|
58
|
+
## Examples
|
|
59
|
+
|
|
60
|
+
### A board
|
|
61
|
+
|
|
62
|
+
`board-example.component.ts`
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { Component, signal } from "@angular/core";
|
|
66
|
+
import { type KanbanColumn, KanbanComponent } from "@nanahoshi/mona-ui/kanban";
|
|
67
|
+
|
|
68
|
+
interface Task {
|
|
69
|
+
readonly id: number;
|
|
70
|
+
readonly status: "doing" | "done" | "todo";
|
|
71
|
+
readonly title: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@Component({
|
|
75
|
+
selector: "app-kanban-board-example",
|
|
76
|
+
imports: [KanbanComponent],
|
|
77
|
+
templateUrl: "./board-example.component.html"
|
|
78
|
+
})
|
|
79
|
+
export class KanbanBoardExampleComponent {
|
|
80
|
+
protected readonly columns: readonly KanbanColumn[] = [
|
|
81
|
+
{ status: "todo", title: "To do" },
|
|
82
|
+
{ status: "doing", title: "In progress" },
|
|
83
|
+
{ status: "done", title: "Done" }
|
|
84
|
+
];
|
|
85
|
+
protected readonly tasks = signal<Task[]>([
|
|
86
|
+
{ id: 1, status: "todo", title: "Draft the newsletter" },
|
|
87
|
+
{ id: 2, status: "todo", title: "Book the venue" },
|
|
88
|
+
{ id: 3, status: "doing", title: "Design the poster" },
|
|
89
|
+
{ id: 4, status: "done", title: "Pick a date" }
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`board-example.component.html`
|
|
95
|
+
|
|
96
|
+
```html
|
|
97
|
+
<mona-kanban aria-label="Event planning" [columns]="columns" [(data)]="tasks" />
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Card templates, limits and moves
|
|
101
|
+
|
|
102
|
+
The card template shows each issue's priority and assignee, and the footer adds an issue to its column. Building and Testing take two cards each: once one is full, its count is highlighted and cards from other columns can't move into it, by pointer or keyboard. `cardMove` reports each move.
|
|
103
|
+
|
|
104
|
+
`templates-example.component.ts`
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { Component, signal } from "@angular/core";
|
|
108
|
+
import { BadgeDirective } from "@nanahoshi/mona-ui/badge";
|
|
109
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
110
|
+
import {
|
|
111
|
+
type KanbanCardMoveEvent,
|
|
112
|
+
type KanbanColumn,
|
|
113
|
+
KanbanCardTemplateDirective,
|
|
114
|
+
KanbanColumnFooterTemplateDirective,
|
|
115
|
+
KanbanComponent
|
|
116
|
+
} from "@nanahoshi/mona-ui/kanban";
|
|
117
|
+
|
|
118
|
+
interface Issue {
|
|
119
|
+
readonly assignee: string;
|
|
120
|
+
readonly id: number;
|
|
121
|
+
readonly priority: "High" | "Low" | "Medium";
|
|
122
|
+
readonly stage: "backlog" | "building" | "shipped" | "testing";
|
|
123
|
+
readonly title: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@Component({
|
|
127
|
+
selector: "app-kanban-templates-example",
|
|
128
|
+
imports: [
|
|
129
|
+
BadgeDirective,
|
|
130
|
+
ButtonDirective,
|
|
131
|
+
KanbanCardTemplateDirective,
|
|
132
|
+
KanbanColumnFooterTemplateDirective,
|
|
133
|
+
KanbanComponent
|
|
134
|
+
],
|
|
135
|
+
templateUrl: "./templates-example.component.html"
|
|
136
|
+
})
|
|
137
|
+
export class KanbanTemplatesExampleComponent {
|
|
138
|
+
#nextId = 7;
|
|
139
|
+
protected readonly columns: readonly KanbanColumn[] = [
|
|
140
|
+
{ status: "backlog", title: "Backlog" },
|
|
141
|
+
{ limit: 2, status: "building", title: "Building" },
|
|
142
|
+
{ limit: 2, status: "testing", title: "Testing" },
|
|
143
|
+
{ status: "shipped", title: "Shipped" }
|
|
144
|
+
];
|
|
145
|
+
protected readonly issues = signal<Issue[]>([
|
|
146
|
+
{ assignee: "Ana", id: 1, priority: "High", stage: "backlog", title: "Search ignores accents" },
|
|
147
|
+
{ assignee: "Kenji", id: 2, priority: "Low", stage: "backlog", title: "Dark mode logo" },
|
|
148
|
+
{ assignee: "Ana", id: 3, priority: "Medium", stage: "building", title: "Export to CSV" },
|
|
149
|
+
{ assignee: "Sam", id: 4, priority: "High", stage: "building", title: "Session timeout" },
|
|
150
|
+
{ assignee: "Kenji", id: 5, priority: "Medium", stage: "testing", title: "Invite by link" },
|
|
151
|
+
{ assignee: "Sam", id: 6, priority: "Low", stage: "shipped", title: "Keyboard shortcuts page" }
|
|
152
|
+
]);
|
|
153
|
+
protected readonly lastMove = signal("");
|
|
154
|
+
|
|
155
|
+
protected add(column: KanbanColumn): void {
|
|
156
|
+
const id = this.#nextId++;
|
|
157
|
+
const stage = column.status as Issue["stage"];
|
|
158
|
+
this.issues.update(issues => [
|
|
159
|
+
...issues,
|
|
160
|
+
{ assignee: "Ana", id, priority: "Medium", stage, title: `Issue ${id}` }
|
|
161
|
+
]);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
protected onMove(event: KanbanCardMoveEvent<Issue>): void {
|
|
165
|
+
const from = this.titleOf(event.previousStatus);
|
|
166
|
+
const to = this.titleOf(event.status);
|
|
167
|
+
this.lastMove.set(
|
|
168
|
+
from === to
|
|
169
|
+
? `Reordered "${event.card.title}" in ${to}.`
|
|
170
|
+
: `Moved "${event.card.title}" from ${from} to ${to}.`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
protected priorityLook(priority: Issue["priority"]): "error" | "secondary" | "warning" {
|
|
175
|
+
switch (priority) {
|
|
176
|
+
case "High":
|
|
177
|
+
return "error";
|
|
178
|
+
case "Medium":
|
|
179
|
+
return "warning";
|
|
180
|
+
default:
|
|
181
|
+
return "secondary";
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private titleOf(status: unknown): string {
|
|
186
|
+
return this.columns.find(column => column.status === status)?.title ?? "";
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`templates-example.component.html`
|
|
192
|
+
|
|
193
|
+
```html
|
|
194
|
+
<div class="flex flex-col gap-3">
|
|
195
|
+
<mona-kanban
|
|
196
|
+
aria-label="Issues"
|
|
197
|
+
statusField="stage"
|
|
198
|
+
[columns]="columns"
|
|
199
|
+
[(data)]="issues"
|
|
200
|
+
(cardMove)="onMove($event)">
|
|
201
|
+
<ng-template monaKanbanCardTemplate [monaKanbanCardTemplateOf]="issues()" let-issue>
|
|
202
|
+
<div class="flex flex-col gap-2">
|
|
203
|
+
<span class="font-medium">{{ issue.title }}</span>
|
|
204
|
+
<div class="flex items-center justify-between gap-2 text-xs text-muted-foreground">
|
|
205
|
+
<span monaBadge fill="subtle" size="small" [look]="priorityLook(issue.priority)">
|
|
206
|
+
{{ issue.priority }}
|
|
207
|
+
</span>
|
|
208
|
+
<span>{{ issue.assignee }}</span>
|
|
209
|
+
</div>
|
|
210
|
+
</div>
|
|
211
|
+
</ng-template>
|
|
212
|
+
<ng-template monaKanbanColumnFooterTemplate let-column>
|
|
213
|
+
<button monaButton look="link" size="small" type="button" (click)="add(column)">
|
|
214
|
+
Add to {{ column.title }}
|
|
215
|
+
</button>
|
|
216
|
+
</ng-template>
|
|
217
|
+
</mona-kanban>
|
|
218
|
+
<p class="text-sm text-muted-foreground">{{ lastMove() || "Move a card to see what changed." }}</p>
|
|
219
|
+
</div>
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Behavior
|
|
223
|
+
|
|
224
|
+
### Moves and the data
|
|
225
|
+
|
|
226
|
+
A move first emits `cardMove`. It carries the card as it was, the card as it is now (`movedCard`), its previous and new status and index in its column, and the board's new array, `data`. Call `preventDefault()` to refuse the move, such as when the server turns it down. Otherwise the board emits the new array through `dataChange`, which `[(data)]` writes back.
|
|
227
|
+
|
|
228
|
+
A card that moves to another column is copied with its status field set to the column's status, `{ ...card, status }`, so the array you passed isn't changed. A card that stays in its column keeps its object. The new array keeps every other card where it was, and puts the moved card before the card it now sits above in its column.
|
|
229
|
+
|
|
230
|
+
### Limits
|
|
231
|
+
|
|
232
|
+
A column's `limit` is the most cards it takes. Once it holds that many, cards from other columns can't come in, and its count shows as "2 / 2" in the warning colors. Cards already in it can still be reordered. The board doesn't enforce the limit on the data you give it: a column can start over its limit, and stays highlighted until it's under.
|
|
233
|
+
|
|
234
|
+
### Disabling
|
|
235
|
+
|
|
236
|
+
`disabled` stops cards from moving. Focus still moves between them, and what their templates hold still works.
|
|
237
|
+
|
|
238
|
+
### Size and scrolling
|
|
239
|
+
|
|
240
|
+
The board lays its columns out in a row, 18rem wide each, and scrolls sideways when they don't fit. Give it a height, such as with a `class`, and each column scrolls its own cards. A card dragged near the board's edge, or a column's, scrolls it.
|
|
241
|
+
|
|
242
|
+
## Accessibility
|
|
243
|
+
|
|
244
|
+
The board is a `group`, which `aria-label` names. Each column is a `group` too, holding a list of its cards; both are named by the column's title and count, "In progress 2 of 3 cards". The visible count is hidden from screen readers, which read the count in words instead.
|
|
245
|
+
|
|
246
|
+
The board is one Tab stop: the card last focused, or the first card. After a move, the board announces the card's name, from its `textField`, and its new place: "Design the poster moved to Done, position 1 of 2".
|
|
247
|
+
|
|
248
|
+
### Keyboard
|
|
249
|
+
|
|
250
|
+
With focus on a card:
|
|
251
|
+
|
|
252
|
+
| Key | Action |
|
|
253
|
+
| --- | --- |
|
|
254
|
+
| `ArrowUp` / `ArrowDown` | Moves focus to the previous or next card in the column |
|
|
255
|
+
| `ArrowLeft` / `ArrowRight` | Moves focus to the next column with cards, to the card in the same row or the last one |
|
|
256
|
+
| `Home` / `End` | Moves focus to the first or last card in the column |
|
|
257
|
+
| `Control+Shift+ArrowUp` / `Control+Shift+ArrowDown` (`Command+Shift` on macOS) | Moves the card up or down its column |
|
|
258
|
+
| `Control+Shift+ArrowLeft` / `Control+Shift+ArrowRight` | Moves the card to the previous or next column that has room, in the same row |
|
|
259
|
+
| `Control+Shift+Home` / `Control+Shift+End` | Moves the card to the top or bottom of its column |
|
|
260
|
+
|
|
261
|
+
`ArrowLeft` and `ArrowRight` swap in right-to-left layouts. Focus stays on a moved card.
|
|
262
|
+
|
|
263
|
+
### ARIA
|
|
264
|
+
|
|
265
|
+
| Attribute | When present | Value |
|
|
266
|
+
| --- | --- | --- |
|
|
267
|
+
| `role` | On the board and on each column | `"group"` |
|
|
268
|
+
| `aria-labelledby` | On each column and its list | The column's title and count |
|
|
269
|
+
| `aria-keyshortcuts` | On each card, unless the board is disabled | The shortcuts that move it |
|
|
270
|
+
|
|
271
|
+
## API
|
|
272
|
+
|
|
273
|
+
Everything below is imported from `@nanahoshi/mona-ui/kanban`. Each name links to its reference page, with every input, output, property and method.
|
|
274
|
+
|
|
275
|
+
| Name | Kind | Description |
|
|
276
|
+
| --- | --- | --- |
|
|
277
|
+
| [`KanbanComponent`](api/kanban.md#kanbancomponent) | Component | A board of columns that cards move between, by dragging or with Control+Shift and the arrow keys (Command+Shift on macOS). |
|
|
278
|
+
| [`KanbanCardTemplateDirective`](api/kanban.md#kanbancardtemplatedirective) | Directive | Template for each card of a Kanban board. |
|
|
279
|
+
| [`KanbanColumnFooterTemplateDirective`](api/kanban.md#kanbancolumnfootertemplatedirective) | Directive | Template for the foot of each column of a Kanban board, below its cards, such as for an Add card button. |
|
|
280
|
+
| [`KanbanColumnHeaderTemplateDirective`](api/kanban.md#kanbancolumnheadertemplatedirective) | Directive | Template for the header of each column of a Kanban board, in place of its title and count. |
|
|
281
|
+
| [`KanbanCardMoveEvent`](api/kanban.md#kanbancardmoveevent) | Class | A card dragged, or moved with Control+Shift and the arrow keys, to a new place on a Kanban board: within its column or into another. |
|
|
282
|
+
|
|
283
|
+
### Types
|
|
284
|
+
|
|
285
|
+
| Type | Kind | Description |
|
|
286
|
+
| --- | --- | --- |
|
|
287
|
+
| [`KANBAN_DEFAULT_MESSAGES`](api/kanban.md#kanban-default-messages) | Constant | |
|
|
288
|
+
| [`KanbanCardMoveEventOptions`](api/kanban.md#kanbancardmoveeventoptions) | Interface | |
|
|
289
|
+
| [`KanbanCardTemplateContext`](api/kanban.md#kanbancardtemplatecontext) | Interface | The context of a `monaKanbanCardTemplate`: the card, as `let-card`. |
|
|
290
|
+
| [`KanbanColumn`](api/kanban.md#kanbancolumn) | Interface | A column of a Kanban board: the cards whose status field holds its `status`. |
|
|
291
|
+
| [`KanbanColumnTemplateContext`](api/kanban.md#kanbancolumntemplatecontext) | Interface | The context of a `monaKanbanColumnHeaderTemplate` or `monaKanbanColumnFooterTemplate`: the column, as `let-column`. |
|
|
292
|
+
|
|
293
|
+
**Related types:** [`MonaKanbanMessages`](api/i18n.md#monakanbanmessages), [`PreventableEvent`](api/common.md#preventableevent)
|