@nanahoshi/mona-ui 0.40.0 → 0.42.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.
Files changed (80) hide show
  1. package/docs/api/auto-complete.md +2 -0
  2. package/docs/api/combo-box.md +2 -0
  3. package/docs/api/common.md +1 -1
  4. package/docs/api/dropdowns.md +3 -1
  5. package/docs/api/i18n.md +54 -0
  6. package/docs/api/kanban.md +222 -0
  7. package/docs/api/locales.md +14 -14
  8. package/docs/api/sortable.md +189 -0
  9. package/docs/api/sparkline.md +85 -0
  10. package/docs/api/tabs.md +20 -0
  11. package/docs/auto-complete.md +64 -0
  12. package/docs/combo-box.md +65 -0
  13. package/docs/kanban.md +293 -0
  14. package/docs/sortable.md +320 -0
  15. package/docs/sparkline.md +303 -0
  16. package/docs/tabs.md +59 -10
  17. package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +95 -30
  18. package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +58 -5
  19. package/fesm2022/nanahoshi-mona-ui-dropdowns.mjs +64 -29
  20. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +87 -0
  21. package/fesm2022/nanahoshi-mona-ui-kanban.mjs +660 -0
  22. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +14 -0
  23. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +14 -0
  24. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +14 -0
  25. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +14 -0
  26. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +14 -0
  27. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +14 -0
  28. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +14 -0
  29. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +14 -0
  30. package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +44 -0
  31. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +14 -0
  32. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +44 -0
  33. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +14 -0
  34. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +14 -0
  35. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +14 -0
  36. package/fesm2022/nanahoshi-mona-ui-sortable.mjs +733 -0
  37. package/fesm2022/nanahoshi-mona-ui-sparkline.mjs +573 -0
  38. package/fesm2022/nanahoshi-mona-ui-tabs.mjs +112 -5
  39. package/i18n/catalogs/en-US.messages.json +14 -0
  40. package/kanban/package.json +4 -0
  41. package/llms.txt +8 -2
  42. package/locales/ar-sa/ar-sa.messages.json +14 -0
  43. package/locales/de-de/de-de.messages.json +14 -0
  44. package/locales/es-es/es-es.messages.json +14 -0
  45. package/locales/fr-fr/fr-fr.messages.json +14 -0
  46. package/locales/id-id/id-id.messages.json +14 -0
  47. package/locales/it-it/it-it.messages.json +14 -0
  48. package/locales/ja-jp/ja-jp.messages.json +14 -0
  49. package/locales/ko-kr/ko-kr.messages.json +14 -0
  50. package/locales/pl-pl/pl-pl.messages.json +14 -0
  51. package/locales/pt-br/pt-br.messages.json +14 -0
  52. package/locales/ru-ru/ru-ru.messages.json +14 -0
  53. package/locales/tr-tr/tr-tr.messages.json +14 -0
  54. package/locales/zh-cn/zh-cn.messages.json +14 -0
  55. package/locales/zh-tw/zh-tw.messages.json +14 -0
  56. package/package.json +13 -1
  57. package/sortable/package.json +4 -0
  58. package/sparkline/package.json +4 -0
  59. package/types/nanahoshi-mona-ui-auto-complete.d.ts +42 -1
  60. package/types/nanahoshi-mona-ui-combo-box.d.ts +37 -1
  61. package/types/nanahoshi-mona-ui-dropdowns.d.ts +54 -4
  62. package/types/nanahoshi-mona-ui-i18n.d.ts +31 -0
  63. package/types/nanahoshi-mona-ui-kanban.d.ts +270 -0
  64. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +14 -0
  65. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +14 -0
  66. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +14 -0
  67. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +14 -0
  68. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +14 -0
  69. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +14 -0
  70. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +14 -0
  71. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +14 -0
  72. package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +14 -0
  73. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +14 -0
  74. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +14 -0
  75. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +14 -0
  76. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +14 -0
  77. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +14 -0
  78. package/types/nanahoshi-mona-ui-sortable.d.ts +245 -0
  79. package/types/nanahoshi-mona-ui-sparkline.d.ts +228 -0
  80. package/types/nanahoshi-mona-ui-tabs.d.ts +46 -0
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)
@@ -0,0 +1,320 @@
1
+ # Sortable
2
+
3
+ > Lets users reorder any list by dragging or with the keyboard, and move items between connected lists.
4
+
5
+ Entry point: `@nanahoshi/mona-ui/sortable`
6
+
7
+ **Selectors:** `[monaSortable]`, `[monaSortableItem]`, `[monaSortableGroup]`, `[monaSortableHandle]`
8
+
9
+ `SortableDirective` lets users reorder the items of a list you render yourself, such as a list of priorities, a row of chips or a grid of dashboard tiles. They drag an item to its new place, or focus it and press Control+Shift with an arrow key, and each move is announced to screen readers. Lists inside a `monaSortableGroup` exchange items, as the columns of a board do.
10
+
11
+ The directive adds no markup or roles: your list keeps its own. To reorder tabs, use the `sortable` input of [Tabs](tabs.md); for a board of columns, use [Kanban](kanban.md), which is built on this directive.
12
+
13
+ ## Overview
14
+
15
+ Put `monaSortable` on a list element and `monaSortableItem` on each item, and give them your data: the array on the list, and each item's element of it. When the user moves an item, the list emits its new array; it doesn't reorder its elements itself. Bind the array two-way and the new order renders.
16
+
17
+ **Use Sortable when:**
18
+
19
+ - Users choose an order that matters to them: priorities, the columns a table shows, the widgets on a dashboard.
20
+ - Items move between a few lists, such as shown and hidden fields.
21
+
22
+ For a list with selection and a toolbar of move buttons, use [List Box](list-box.md). For a board of columns with counts and limits, use [Kanban](kanban.md).
23
+
24
+ ## Import & Quick Start
25
+
26
+ ```typescript
27
+ import { SortableDirective, SortableItemDirective } from "@nanahoshi/mona-ui/sortable";
28
+ ```
29
+
30
+ ```html
31
+ <ol aria-label="Priorities" [(monaSortable)]="priorities">
32
+ @for (priority of priorities(); track priority) {
33
+ <li tabindex="0" [monaSortableItem]="priority">{{ priority }}</li>
34
+ }
35
+ </ol>
36
+ ```
37
+
38
+ ```typescript
39
+ protected readonly priorities = signal(["Fix the sign-in bug", "Write the release notes", "Plan the offsite"]);
40
+ ```
41
+
42
+ Render every element of the array as an item, in the array's order: the list maps the positions the user sees to the array's indexes. Track items by something stable, such as the item itself or its id, so a moved item keeps its element.
43
+
44
+ ## Anatomy
45
+
46
+ | Directive | Selector | Goes on |
47
+ | --- | --- | --- |
48
+ | `SortableDirective` | `[monaSortable]` | The element that holds the items |
49
+ | `SortableItemDirective` | `[monaSortableItem]` | Each item, given its element of the array |
50
+ | `SortableGroupDirective` | `[monaSortableGroup]` | An element around lists that exchange items |
51
+ | `SortableHandleDirective` | `[monaSortableHandle]` | The part of an item that starts a drag, when only part of it should |
52
+
53
+ ## Examples
54
+
55
+ ### A sortable list
56
+
57
+ `[(monaSortable)]` gives the list its array and takes each new order. `sortableLockAxis` keeps a dragged item on the list's axis, up and down here. The row numbers are hidden from screen readers, so the announcement names the item by its text alone.
58
+
59
+ `list-example.component.ts`
60
+
61
+ ```typescript
62
+ import { Component, signal } from "@angular/core";
63
+ import { SortableDirective, SortableItemDirective } from "@nanahoshi/mona-ui/sortable";
64
+
65
+ @Component({
66
+ selector: "app-sortable-list-example",
67
+ imports: [SortableDirective, SortableItemDirective],
68
+ templateUrl: "./list-example.component.html"
69
+ })
70
+ export class SortableListExampleComponent {
71
+ protected readonly priorities = signal([
72
+ "Fix the sign-in bug",
73
+ "Write the release notes",
74
+ "Review the onboarding design",
75
+ "Plan the team offsite"
76
+ ]);
77
+ }
78
+ ```
79
+
80
+ `list-example.component.html`
81
+
82
+ ```html
83
+ <div class="flex w-80 max-w-full flex-col gap-3">
84
+ <ol aria-label="Priorities" class="flex flex-col gap-1" [(monaSortable)]="priorities" sortableLockAxis>
85
+ @for (priority of priorities(); track priority; let index = $index) {
86
+ <li
87
+ tabindex="0"
88
+ class="flex cursor-grab items-center gap-3 rounded-md border border-border bg-card px-3 py-2 text-sm focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-indicator"
89
+ [monaSortableItem]="priority">
90
+ <span aria-hidden="true" class="w-4 text-end text-muted-foreground tabular-nums">{{ index + 1 }}</span>
91
+ {{ priority }}
92
+ </li>
93
+ }
94
+ </ol>
95
+ <p class="text-sm text-muted-foreground">Up first: {{ priorities()[0] }}</p>
96
+ </div>
97
+ ```
98
+
99
+ ### Moving items between lists
100
+
101
+ Lists inside a `monaSortableGroup` exchange items. Each list emits its own new array, so bind each one two-way. `sortableCanEnter` decides whether an item from another list may come in, here only while fewer than five columns are shown; the list's own items can always be reordered.
102
+
103
+ `connected-example.component.ts`
104
+
105
+ ```typescript
106
+ import { Component, signal } from "@angular/core";
107
+ import { SortableDirective, SortableGroupDirective, SortableItemDirective } from "@nanahoshi/mona-ui/sortable";
108
+
109
+ /** The most columns the table shows. */
110
+ const MAX_SHOWN = 5;
111
+
112
+ @Component({
113
+ selector: "app-sortable-connected-example",
114
+ imports: [SortableDirective, SortableGroupDirective, SortableItemDirective],
115
+ templateUrl: "./connected-example.component.html"
116
+ })
117
+ export class SortableConnectedExampleComponent {
118
+ protected readonly hidden = signal(["Email", "Phone", "Country", "Start date"]);
119
+ protected readonly maxShown = MAX_SHOWN;
120
+ protected readonly shown = signal(["Name", "Role", "Team"]);
121
+
122
+ /** A column can join the shown ones while there's room; the shown ones can always be reordered. */
123
+ protected readonly canShow = (): boolean => this.shown().length < MAX_SHOWN;
124
+ }
125
+ ```
126
+
127
+ `connected-example.component.html`
128
+
129
+ ```html
130
+ <div monaSortableGroup class="grid w-[32rem] max-w-full grid-cols-2 gap-4">
131
+ <section class="flex flex-col gap-2">
132
+ <h3 id="sortable-connected-hidden" class="text-sm font-semibold">Hidden columns</h3>
133
+ <ul
134
+ aria-labelledby="sortable-connected-hidden"
135
+ class="flex min-h-40 flex-col gap-1 rounded-md bg-surface-muted p-2"
136
+ [(monaSortable)]="hidden">
137
+ @for (column of hidden(); track column) {
138
+ <li
139
+ tabindex="0"
140
+ class="cursor-grab rounded-md border border-border bg-card px-3 py-1.5 text-sm focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-indicator"
141
+ [monaSortableItem]="column">
142
+ {{ column }}
143
+ </li>
144
+ }
145
+ </ul>
146
+ </section>
147
+ <section class="flex flex-col gap-2">
148
+ <h3 id="sortable-connected-shown" class="text-sm font-semibold">Shown columns</h3>
149
+ <ul
150
+ aria-labelledby="sortable-connected-shown"
151
+ aria-describedby="sortable-connected-limit"
152
+ class="flex min-h-40 flex-col gap-1 rounded-md bg-surface-muted p-2"
153
+ [(monaSortable)]="shown"
154
+ [sortableCanEnter]="canShow">
155
+ @for (column of shown(); track column) {
156
+ <li
157
+ tabindex="0"
158
+ class="cursor-grab rounded-md border border-border bg-card px-3 py-1.5 text-sm focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-indicator"
159
+ [monaSortableItem]="column">
160
+ {{ column }}
161
+ </li>
162
+ }
163
+ </ul>
164
+ <p id="sortable-connected-limit" class="text-sm text-muted-foreground">
165
+ {{ shown().length }} of {{ maxShown }} columns
166
+ </p>
167
+ </section>
168
+ </div>
169
+ ```
170
+
171
+ ### Rows that wrap, with handles
172
+
173
+ `sortableOrientation="mixed"` is for items laid out in rows that wrap, such as tiles. A `monaSortableHandle` makes only the grip start a drag, so the rest of the tile can hold text to select or controls to use. The keyboard moves the tile from anywhere in it. `sortableLabel` names each tile in announcements, where its text would also read the figure.
174
+
175
+ `tiles-example.component.ts`
176
+
177
+ ```typescript
178
+ import { Component, signal } from "@angular/core";
179
+ import { LucideGripVertical } from "@lucide/angular";
180
+ import { SortableDirective, SortableHandleDirective, SortableItemDirective } from "@nanahoshi/mona-ui/sortable";
181
+
182
+ interface Widget {
183
+ readonly id: string;
184
+ readonly title: string;
185
+ readonly value: string;
186
+ }
187
+
188
+ @Component({
189
+ selector: "app-sortable-tiles-example",
190
+ imports: [LucideGripVertical, SortableDirective, SortableHandleDirective, SortableItemDirective],
191
+ templateUrl: "./tiles-example.component.html"
192
+ })
193
+ export class SortableTilesExampleComponent {
194
+ protected readonly widgets = signal<Widget[]>([
195
+ { id: "visitors", title: "Visitors", value: "12,480" },
196
+ { id: "signups", title: "Sign-ups", value: "312" },
197
+ { id: "revenue", title: "Revenue", value: "$8,920" },
198
+ { id: "churn", title: "Churn", value: "1.8%" },
199
+ { id: "tickets", title: "Open tickets", value: "27" }
200
+ ]);
201
+ }
202
+ ```
203
+
204
+ `tiles-example.component.html`
205
+
206
+ ```html
207
+ <ul
208
+ aria-label="Dashboard widgets"
209
+ class="flex w-[30rem] max-w-full flex-wrap gap-3"
210
+ [(monaSortable)]="widgets"
211
+ sortableOrientation="mixed">
212
+ @for (widget of widgets(); track widget.id) {
213
+ <li
214
+ tabindex="0"
215
+ class="flex w-36 flex-col gap-2 rounded-lg border border-border bg-card p-3 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-indicator"
216
+ [monaSortableItem]="widget"
217
+ [sortableLabel]="widget.title">
218
+ <div class="flex items-center justify-between gap-2">
219
+ <span class="text-sm text-muted-foreground">{{ widget.title }}</span>
220
+ <svg
221
+ monaSortableHandle
222
+ lucideGripVertical
223
+ aria-hidden="true"
224
+ class="text-muted-foreground"
225
+ [size]="16"></svg>
226
+ </div>
227
+ <span class="text-2xl font-semibold tabular-nums">{{ widget.value }}</span>
228
+ </li>
229
+ }
230
+ </ul>
231
+ ```
232
+
233
+ ## Behavior
234
+
235
+ ### The list doesn't change your data
236
+
237
+ A move first emits `sortableMove` on the list the item lands in. It carries the item, its previous and new index, and both lists' arrays after the move: `previousItems` and `currentItems`, the same array for a move within one list. Call `preventDefault()` to refuse the move. Otherwise each list involved emits its new array through `monaSortableChange`, which `[(monaSortable)]` writes back.
238
+
239
+ ```html
240
+ <ul [monaSortable]="tasks()" (sortableMove)="save($event)">…</ul>
241
+ ```
242
+
243
+ ```typescript
244
+ protected save(event: SortableMoveEvent<Task>): void {
245
+ // Keep the new order only once the server has it.
246
+ event.preventDefault();
247
+ this.api.reorder(event.currentItems).subscribe(() => this.tasks.set([...event.currentItems]));
248
+ }
249
+ ```
250
+
251
+ `moveItem(items, from, to)` returns a copy of an array with one item moved, for moves reported by index, such as [reordered tabs](tabs.md#reordering-tabs).
252
+
253
+ ### Orientation
254
+
255
+ `sortableOrientation` says how the items are laid out, which sets the keys that move them:
256
+
257
+ | Value | Layout | Keys that move an item within the list | Keys that move it to another list of the group |
258
+ | --- | --- | --- | --- |
259
+ | `"vertical"` (default) | A column | `ArrowUp`, `ArrowDown` | `ArrowLeft`, `ArrowRight` |
260
+ | `"horizontal"` | A row | `ArrowLeft`, `ArrowRight` | `ArrowUp`, `ArrowDown` |
261
+ | `"mixed"` | Rows that wrap | All four: up and down to the item above or below | None |
262
+
263
+ In rows that wrap, the items must be the list element's own children.
264
+
265
+ ### Disabling
266
+
267
+ `sortableDisabled` on the list stops its items from moving, and stops items from other lists coming in. On an item, it stops that item from moving; other items still move past it.
268
+
269
+ ### Touch screens
270
+
271
+ On a touch screen, press and hold an item for a moment to pick it up. A quick swipe scrolls the page, or the list, as usual.
272
+
273
+ ## Accessibility
274
+
275
+ Each item must take focus, or hold a control that does, for the keyboard to move it: give it `tabindex="0"`, or put the list's own focus management on it. The directive adds no roles, so keep the semantics of your markup: a `ul` or `ol` of `li` elements, or the roles of the pattern you build.
276
+
277
+ After every move, the list announces the item's name and its new position, "Write the release notes moved to position 1 of 3", and for a move into another list, that list's name too, "Email moved to Shown columns, position 4 of 4". The item's name is its `sortableLabel`, else its `aria-label` or `aria-labelledby` text, else its text without what's `aria-hidden`. The list's name is its `sortableLabel`, else its `aria-label` or `aria-labelledby` text.
278
+
279
+ ### Keyboard
280
+
281
+ With focus on an item, or on an element in it that isn't a text field:
282
+
283
+ | Key | Action |
284
+ | --- | --- |
285
+ | `Control+Shift` with an arrow key (`Command+Shift` on macOS) | Moves the item one place, or to the next list of the group, as the [orientation](#orientation) sets |
286
+ | `Control+Shift+Home` / `Control+Shift+End` | Moves the item to the start or the end of its list |
287
+
288
+ `ArrowLeft` and `ArrowRight` swap in right-to-left layouts. A move into another list keeps the item's position, or puts it last when the list is shorter, and passes over a list that refuses it. Focus stays on the moved item, also when it lands in another list.
289
+
290
+ ### ARIA
291
+
292
+ | Attribute | When present | Value |
293
+ | --- | --- | --- |
294
+ | `aria-keyshortcuts` | On each item that can move | The shortcuts that move it, such as `"Control+Shift+ArrowUp Control+Shift+ArrowDown Control+Shift+Home Control+Shift+End"` |
295
+
296
+ An item with `role="presentation"` or `role="none"` doesn't get `aria-keyshortcuts`, which would conflict with its role. Bind the item's `keyShortcuts()` on the element in it that takes focus instead: `#item="monaSortableItem"`, then `[attr.aria-keyshortcuts]="item.keyShortcuts()"`.
297
+
298
+ ## API
299
+
300
+ Everything below is imported from `@nanahoshi/mona-ui/sortable`. Each name links to its reference page, with every input, output, property and method.
301
+
302
+ | Name | Kind | Description |
303
+ | --- | --- | --- |
304
+ | [`SortableDirective`](api/sortable.md#sortabledirective) | Directive | Lets the user reorder a list's items by dragging them, or with Control+Shift and the arrow keys (Command+Shift on macOS), and announces each move. |
305
+ | [`SortableItemDirective`](api/sortable.md#sortableitemdirective) | Directive | An item of a `monaSortable` list, given the array element it shows. |
306
+ | [`SortableGroupDirective`](api/sortable.md#sortablegroupdirective) | Directive | Connects the sortable lists inside it, so an item can move from one to another: dragged, or with Control+Shift and the arrow keys that cross the lists, such as Left and Right between columns. |
307
+ | [`SortableHandleDirective`](api/sortable.md#sortablehandledirective) | Directive | Marks the part of a sortable item that starts a drag, such as a grip icon. |
308
+ | [`SortableMoveEvent`](api/sortable.md#sortablemoveevent) | Class | A move of an item, by pointer or keyboard, within a sortable list or into another list of its group. |
309
+ | [`moveItem`](api/sortable.md#moveitem) | Function | A copy of `items` with the item at `from` moved to `to`, the index it has afterwards. |
310
+
311
+ ### Types
312
+
313
+ | Type | Kind | Description |
314
+ | --- | --- | --- |
315
+ | [`SORTABLE_DEFAULT_MESSAGES`](api/sortable.md#sortable-default-messages) | Constant | |
316
+ | [`SortableMoveEventOptions`](api/sortable.md#sortablemoveeventoptions) | Interface | |
317
+ | [`SortableMoveKey`](api/sortable.md#sortablemovekey) | Type alias | The keys that move an item, held with Control and Shift (Command and Shift on macOS). |
318
+ | [`SortableOrientation`](api/sortable.md#sortableorientation) | Type alias | How a sortable list lays out its items: in a column (`vertical`), in a row (`horizontal`), or in rows that wrap (`mixed`), such as a grid of cards. |
319
+
320
+ **Related types:** [`MonaSortableMessages`](api/i18n.md#monasortablemessages), [`PreventableEvent`](api/common.md#preventableevent)