@nanahoshi/mona-ui 0.40.0 → 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/i18n.md +34 -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/kanban.md +293 -0
- package/docs/sortable.md +320 -0
- package/docs/tabs.md +59 -10
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +48 -0
- package/fesm2022/nanahoshi-mona-ui-kanban.mjs +660 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +9 -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 +9 -0
- package/kanban/package.json +4 -0
- package/llms.txt +6 -2
- package/locales/ar-sa/ar-sa.messages.json +9 -0
- package/locales/de-de/de-de.messages.json +9 -0
- package/locales/es-es/es-es.messages.json +9 -0
- package/locales/fr-fr/fr-fr.messages.json +9 -0
- package/locales/id-id/id-id.messages.json +9 -0
- package/locales/it-it/it-it.messages.json +9 -0
- package/locales/ja-jp/ja-jp.messages.json +9 -0
- package/locales/ko-kr/ko-kr.messages.json +9 -0
- package/locales/pl-pl/pl-pl.messages.json +9 -0
- package/locales/pt-br/pt-br.messages.json +9 -0
- package/locales/ru-ru/ru-ru.messages.json +9 -0
- package/locales/tr-tr/tr-tr.messages.json +9 -0
- package/locales/zh-cn/zh-cn.messages.json +9 -0
- package/locales/zh-tw/zh-tw.messages.json +9 -0
- package/package.json +9 -1
- package/sortable/package.json +4 -0
- package/types/nanahoshi-mona-ui-i18n.d.ts +19 -0
- package/types/nanahoshi-mona-ui-kanban.d.ts +270 -0
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +9 -0
- package/types/nanahoshi-mona-ui-sortable.d.ts +245 -0
- package/types/nanahoshi-mona-ui-tabs.d.ts +46 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# `@nanahoshi/mona-ui/sortable`
|
|
2
|
+
|
|
3
|
+
Everything `@nanahoshi/mona-ui/sortable` exports.
|
|
4
|
+
|
|
5
|
+
**Guides:** [Sortable](../sortable.md)
|
|
6
|
+
|
|
7
|
+
## `SortableDirective`
|
|
8
|
+
|
|
9
|
+
Directive.
|
|
10
|
+
|
|
11
|
+
Lets the user reorder a list's items by dragging them, or with Control+Shift and the arrow keys (Command+Shift on
|
|
12
|
+
macOS), and announces each move. Mark each item with `monaSortableItem`, render every item of the array in order,
|
|
13
|
+
and bind the array two-way, `[(monaSortable)]`, or handle `sortableMove`. The list doesn't reorder its elements
|
|
14
|
+
itself. Lists inside one `monaSortableGroup` exchange items.
|
|
15
|
+
|
|
16
|
+
**Selector:** `[monaSortable]`
|
|
17
|
+
**Exported as:** `monaSortable`
|
|
18
|
+
**Type parameters:** `T = unknown`
|
|
19
|
+
|
|
20
|
+
### Inputs
|
|
21
|
+
|
|
22
|
+
| Name | Type | Default | Description |
|
|
23
|
+
| --- | --- | --- | --- |
|
|
24
|
+
| `monaSortable` (required) | `readonly T[]` | — | The list's items, in the order they're shown. Bind it two-way, `[(monaSortable)]`, to take each new order. |
|
|
25
|
+
| `sortableCanEnter` | `((item: T) => boolean) \| null` | `null` | Whether an item from another list of the group may come into this one, such as to keep a list under a limit. The list's own items can always move within it. Without it, every item may come in. |
|
|
26
|
+
| `sortableDisabled` | `boolean` | `false` | Stops items from moving within the list, out of it or into it. |
|
|
27
|
+
| `sortableLabel` | `string` | `""` | The list's name in the announcement of a move into it from another list. Without it, the list's `aria-label` or `aria-labelledby` text. |
|
|
28
|
+
| `sortableLockAxis` | `boolean` | `false` | Keeps a dragged item on the list's axis: across for a horizontal list, up and down for a vertical one. A list whose rows wrap doesn't lock. |
|
|
29
|
+
| `sortableOrientation` | `SortableOrientation` | `"vertical"` | How the items are laid out, which sets the keys that move them: Up and Down in a column, Left and Right in a row, and all four in rows that wrap. |
|
|
30
|
+
|
|
31
|
+
### Outputs
|
|
32
|
+
|
|
33
|
+
| Name | Type | Description |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| `monaSortableChange` | `T[]` | Emitted with the list's new items after an item moves within it, out of it or into it, unless the move was refused. |
|
|
36
|
+
| `sortableMove` | `SortableMoveEvent<T>` | Emitted with a `SortableMoveEvent` when an item moves within this list or into it from another list, before the lists emit their new items. This event is preventable. |
|
|
37
|
+
|
|
38
|
+
### Properties
|
|
39
|
+
|
|
40
|
+
| Name | Type | Description |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| `keyShortcuts` (read-only) | `Signal<string \| null>` | The shortcuts that move an item, in `aria-keyshortcuts` form, or `null` while the list is disabled. Items put it on themselves; an item that's presentational can bind it on the element in it that takes focus. |
|
|
43
|
+
|
|
44
|
+
**Used by:** [`SortableMoveEvent`](sortable.md#sortablemoveevent), [`SortableMoveEventOptions`](sortable.md#sortablemoveeventoptions)
|
|
45
|
+
|
|
46
|
+
## `SortableItemDirective`
|
|
47
|
+
|
|
48
|
+
Directive.
|
|
49
|
+
|
|
50
|
+
An item of a `monaSortable` list, given the array element it shows. Drag it, or focus it, or a control in it, and
|
|
51
|
+
press Control+Shift with an arrow key, Home or End (Command+Shift on macOS) to move it. On a touch screen, press and
|
|
52
|
+
hold it first, so a swipe still scrolls.
|
|
53
|
+
|
|
54
|
+
**Selector:** `[monaSortableItem]`
|
|
55
|
+
**Exported as:** `monaSortableItem`
|
|
56
|
+
**Type parameters:** `T = unknown`
|
|
57
|
+
|
|
58
|
+
### Inputs
|
|
59
|
+
|
|
60
|
+
| Name | Type | Default | Description |
|
|
61
|
+
| --- | --- | --- | --- |
|
|
62
|
+
| `monaSortableItem` (required) | `T` | — | The element of the list's array that this item shows. |
|
|
63
|
+
| `sortableDisabled` | `boolean` | `false` | Stops this item from moving. Other items still move past it. |
|
|
64
|
+
| `sortableLabel` | `string` | `""` | The item's name in announcements of its moves. Without it, the item's `aria-label`, `aria-labelledby` text or own text. |
|
|
65
|
+
|
|
66
|
+
### Properties
|
|
67
|
+
|
|
68
|
+
| Name | Type | Description |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| `keyShortcuts` (read-only) | `Signal<string \| null>` | The shortcuts that move this item, in `aria-keyshortcuts` form, or `null` when it can't move. The item sets them on itself, unless it has `role="presentation"` or `role="none"`: then bind them on the element in it that takes focus. |
|
|
71
|
+
|
|
72
|
+
## `SortableGroupDirective`
|
|
73
|
+
|
|
74
|
+
Directive.
|
|
75
|
+
|
|
76
|
+
Connects the sortable lists inside it, so an item can move from one to another: dragged, or with Control+Shift and
|
|
77
|
+
the arrow keys that cross the lists, such as Left and Right between columns. The lists keep their own items; the
|
|
78
|
+
one an item lands in emits the move.
|
|
79
|
+
|
|
80
|
+
**Selector:** `[monaSortableGroup]`
|
|
81
|
+
**Exported as:** `monaSortableGroup`
|
|
82
|
+
|
|
83
|
+
## `SortableHandleDirective`
|
|
84
|
+
|
|
85
|
+
Directive.
|
|
86
|
+
|
|
87
|
+
Marks the part of a sortable item that starts a drag, such as a grip icon. With a handle, the rest of the item
|
|
88
|
+
doesn't start one, so its text can be selected. The keyboard still moves the item from anywhere in it.
|
|
89
|
+
|
|
90
|
+
**Selector:** `[monaSortableHandle]`
|
|
91
|
+
|
|
92
|
+
## `SortableMoveEvent`
|
|
93
|
+
|
|
94
|
+
Class.
|
|
95
|
+
|
|
96
|
+
A move of an item, by pointer or keyboard, within a sortable list or into another list of its group. The list the
|
|
97
|
+
item lands in emits it. Call `preventDefault()` to refuse the move: the lists then don't emit their new items, and
|
|
98
|
+
the item goes back where it was.
|
|
99
|
+
|
|
100
|
+
**Type parameters:** `T = unknown`
|
|
101
|
+
**Extends:** `PreventableEvent`
|
|
102
|
+
|
|
103
|
+
### Properties
|
|
104
|
+
|
|
105
|
+
| Name | Type | Description |
|
|
106
|
+
| --- | --- | --- |
|
|
107
|
+
| `currentIndex` (read-only) | `number` | The item's index in `currentItems`. |
|
|
108
|
+
| `currentItems` (read-only) | `readonly T[]` | The items of the list the item lands in, after the move. |
|
|
109
|
+
| `currentList` (read-only) | `SortableDirective<T>` | The list the item lands in: the one that emits this event. |
|
|
110
|
+
| `item` (read-only) | `T` | The item that moves. |
|
|
111
|
+
| `previousIndex` (read-only) | `number` | The item's index in its list before the move. |
|
|
112
|
+
| `previousItems` (read-only) | `readonly T[]` | The items of the list the item comes from, after the move. For a move within one list, the same array as `currentItems`. |
|
|
113
|
+
| `previousList` (read-only) | `SortableDirective<T>` | The list the item comes from. The same as `currentList` for a move within one list. |
|
|
114
|
+
|
|
115
|
+
### Inherited from `PreventableEvent`
|
|
116
|
+
|
|
117
|
+
| Name | Type | Description |
|
|
118
|
+
| --- | --- | --- |
|
|
119
|
+
| `originalEvent` (read-only) | `E \| undefined` | The DOM event that caused this one, when there is one. |
|
|
120
|
+
| `type` (read-only) | `string \| undefined` | A name for the kind of event, when the component that emits it sets one. |
|
|
121
|
+
|
|
122
|
+
**Methods**
|
|
123
|
+
|
|
124
|
+
| Signature | Description |
|
|
125
|
+
| --- | --- |
|
|
126
|
+
| `isDefaultPrevented(): boolean` | Whether `preventDefault()` was called. |
|
|
127
|
+
| `preventDefault(): void` | Cancels what the event announces, such as opening or closing a popup, or closing a dialog. |
|
|
128
|
+
|
|
129
|
+
**Used by:** [`SortableDirective`](sortable.md#sortabledirective)
|
|
130
|
+
|
|
131
|
+
## `moveItem`
|
|
132
|
+
|
|
133
|
+
Function.
|
|
134
|
+
|
|
135
|
+
A copy of `items` with the item at `from` moved to `to`, the index it has afterwards. Use it to apply a move that a
|
|
136
|
+
list reports by index, such as a reordered tab. Indexes out of range are clamped; the array isn't changed.
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
function moveItem<T>(items: readonly T[], from: number, to: number): T[];
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## `SORTABLE_DEFAULT_MESSAGES`
|
|
143
|
+
|
|
144
|
+
Constant.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const SORTABLE_DEFAULT_MESSAGES: MonaSortableMessages;
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## `SortableMoveEventOptions`
|
|
151
|
+
|
|
152
|
+
Interface.
|
|
153
|
+
|
|
154
|
+
**Type parameters:** `T`
|
|
155
|
+
|
|
156
|
+
### Properties
|
|
157
|
+
|
|
158
|
+
| Name | Type |
|
|
159
|
+
| --- | --- |
|
|
160
|
+
| `currentIndex` (read-only) | `number` |
|
|
161
|
+
| `currentItems` (read-only) | `readonly T[]` |
|
|
162
|
+
| `currentList` (read-only) | `SortableDirective<T>` |
|
|
163
|
+
| `item` (read-only) | `T` |
|
|
164
|
+
| `previousIndex` (read-only) | `number` |
|
|
165
|
+
| `previousItems` (read-only) | `readonly T[]` |
|
|
166
|
+
| `previousList` (read-only) | `SortableDirective<T>` |
|
|
167
|
+
|
|
168
|
+
## `SortableMoveKey`
|
|
169
|
+
|
|
170
|
+
Type alias.
|
|
171
|
+
|
|
172
|
+
The keys that move an item, held with Control and Shift (Command and Shift on macOS).
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
type SortableMoveKey = "ArrowDown" | "ArrowLeft" | "ArrowRight" | "ArrowUp" | "End" | "Home";
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## `SortableOrientation`
|
|
179
|
+
|
|
180
|
+
Type alias.
|
|
181
|
+
|
|
182
|
+
How a sortable list lays out its items: in a column (`vertical`), in a row (`horizontal`), or in rows that wrap
|
|
183
|
+
(`mixed`), such as a grid of cards.
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
type SortableOrientation = "horizontal" | "mixed" | "vertical";
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Used by:** [`SortableDirective`](sortable.md#sortabledirective)
|
package/docs/api/tabs.md
CHANGED
|
@@ -23,6 +23,7 @@ Component.
|
|
|
23
23
|
| `position` | `"bottom" \| "left" \| "right" \| "top"` | `"top"` | Placement of the tab list relative to the tab content. |
|
|
24
24
|
| `selectedIndex` (two-way) | `number` | `0` | The zero-based index of the selected tab. Writing it selects that tab, unless it's disabled or out of range, in which case the value goes back to the selected tab's index. It also changes when the component moves the selection itself, such as when the selected tab is removed. |
|
|
25
25
|
| `size` | `"large" \| "medium" \| "small"` | `"medium"` | Size preset controlling the tabs' dimensions. |
|
|
26
|
+
| `sortable` | `boolean` | `false` | Lets the user reorder the tabs: by dragging them, or with Control+Shift and the arrow keys along the strip, Home or End (Command+Shift on macOS). The component emits `tabReorder` and doesn't move the tabs itself. |
|
|
26
27
|
|
|
27
28
|
### Outputs
|
|
28
29
|
|
|
@@ -30,6 +31,7 @@ Component.
|
|
|
30
31
|
| --- | --- | --- |
|
|
31
32
|
| `selectedIndexChange` | `number` | Emitted when `selectedIndex` changes. |
|
|
32
33
|
| `tabClose` | `TabCloseEvent` | Emitted with a `TabCloseEvent` when a close is requested. The component doesn't remove the tab: remove it from whatever renders the `mona-tab` elements. |
|
|
34
|
+
| `tabReorder` | `TabReorderEvent` | Emitted with a `TabReorderEvent` when a tab of a `sortable` strip is moved. The component doesn't reorder the tabs: move the tab in whatever renders the `mona-tab` elements. The selected tab stays selected. |
|
|
33
35
|
| `tabSelect` | `TabSelectEvent` | Emitted with a `TabSelectEvent` before a click or key selects a tab. This event is preventable. It doesn't fire for selections made through `selectedIndex` or `selected`, or when the selected tab is removed. |
|
|
34
36
|
|
|
35
37
|
## `TabComponent`
|
|
@@ -94,6 +96,24 @@ Class.
|
|
|
94
96
|
|
|
95
97
|
**Used by:** [`TabsComponent`](tabs.md#tabscomponent)
|
|
96
98
|
|
|
99
|
+
## `TabReorderEvent`
|
|
100
|
+
|
|
101
|
+
Class.
|
|
102
|
+
|
|
103
|
+
A tab dragged, or moved with Control+Shift and an arrow key, Home or End, to a new place in a sortable tab strip.
|
|
104
|
+
The component doesn't reorder the tabs: move the tab in whatever renders the `mona-tab` elements, such as with
|
|
105
|
+
`moveItem` from `@nanahoshi/mona-ui/sortable`.
|
|
106
|
+
|
|
107
|
+
### Properties
|
|
108
|
+
|
|
109
|
+
| Name | Type | Description |
|
|
110
|
+
| --- | --- | --- |
|
|
111
|
+
| `currentIndex` (read-only) | `number` | The index the tab moves to. |
|
|
112
|
+
| `originalEvent` (read-only) | `Event \| undefined` | The DOM event that moved the tab: the key press, or the pointer release that dropped it. |
|
|
113
|
+
| `previousIndex` (read-only) | `number` | The index the tab had. |
|
|
114
|
+
|
|
115
|
+
**Used by:** [`TabsComponent`](tabs.md#tabscomponent)
|
|
116
|
+
|
|
97
117
|
## `TabSelectEvent`
|
|
98
118
|
|
|
99
119
|
Class.
|
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)
|