@nanahoshi/mona-ui 0.25.1 → 0.26.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/README.md +2 -0
- package/command/package.json +4 -0
- package/docs/auto-complete.md +733 -0
- package/docs/avatar.md +220 -0
- package/docs/breadcrumb.md +320 -0
- package/docs/button-group.md +392 -0
- package/docs/button.md +256 -0
- package/docs/calendar.md +515 -0
- package/docs/card.md +292 -0
- package/docs/chart.md +4058 -0
- package/docs/checkbox.md +374 -0
- package/docs/chip.md +339 -0
- package/docs/circular-progress-bar.md +287 -0
- package/docs/collapsible.md +308 -0
- package/docs/color-gradient.md +336 -0
- package/docs/color-palette.md +317 -0
- package/docs/color-picker.md +387 -0
- package/docs/combo-box.md +764 -0
- package/docs/command.md +582 -0
- package/docs/contextmenu.md +530 -0
- package/docs/date-picker.md +251 -0
- package/docs/datetime-picker.md +284 -0
- package/docs/decimal-textbox.md +260 -0
- package/docs/dialog.md +822 -0
- package/docs/dropdown-button.md +507 -0
- package/docs/dropdown-list.md +779 -0
- package/docs/editor.md +374 -0
- package/docs/expansion-panel.md +348 -0
- package/docs/fieldset.md +217 -0
- package/docs/forms.md +162 -0
- package/docs/grid.md +2053 -0
- package/docs/input.md +197 -0
- package/docs/installation.md +54 -0
- package/docs/introduction.md +46 -0
- package/docs/label.md +340 -0
- package/docs/list-box.md +637 -0
- package/docs/list-view.md +584 -0
- package/docs/menubar.md +559 -0
- package/docs/multi-select.md +765 -0
- package/docs/notification.md +460 -0
- package/docs/numeric-textbox.md +301 -0
- package/docs/otp-input.md +539 -0
- package/docs/pager.md +513 -0
- package/docs/placeholder.md +176 -0
- package/docs/popover.md +423 -0
- package/docs/popup-menu.md +658 -0
- package/docs/popup.md +617 -0
- package/docs/progress-bar.md +368 -0
- package/docs/radio-button.md +451 -0
- package/docs/range-slider.md +367 -0
- package/docs/rating.md +518 -0
- package/docs/scroll-view.md +375 -0
- package/docs/segmented.md +434 -0
- package/docs/sheet.md +348 -0
- package/docs/sidebar.md +1126 -0
- package/docs/skeleton.md +181 -0
- package/docs/slider.md +423 -0
- package/docs/spinner.md +370 -0
- package/docs/split-button.md +522 -0
- package/docs/splitter.md +342 -0
- package/docs/stepper.md +539 -0
- package/docs/switch.md +340 -0
- package/docs/tabs.md +542 -0
- package/docs/textarea.md +196 -0
- package/docs/textbox.md +332 -0
- package/docs/theming.md +403 -0
- package/docs/time-picker.md +254 -0
- package/docs/tooltip-directive.md +340 -0
- package/docs/tooltip.md +321 -0
- package/docs/tree-view.md +1018 -0
- package/docs/window.md +663 -0
- package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-breadcrumb.mjs +8 -0
- package/fesm2022/nanahoshi-mona-ui-button.mjs +12 -0
- package/fesm2022/nanahoshi-mona-ui-calendar.mjs +5 -2
- package/fesm2022/nanahoshi-mona-ui-chart.mjs +86 -0
- package/fesm2022/nanahoshi-mona-ui-check-box.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-circular-progress-bar.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-collapsible.mjs +16 -2
- package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-command.mjs +924 -0
- package/fesm2022/nanahoshi-mona-ui-common.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +10 -6
- package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-dialog.mjs +9 -5
- package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +9 -5
- package/fesm2022/nanahoshi-mona-ui-dropdowns.mjs +55 -1
- package/fesm2022/nanahoshi-mona-ui-editor.mjs +3 -2
- package/fesm2022/nanahoshi-mona-ui-expansion-panel.mjs +13 -0
- package/fesm2022/nanahoshi-mona-ui-fieldset.mjs +5 -0
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-2tVhD2hK.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DjNnVxHE.mjs} +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-BAN70Wcn.mjs → nanahoshi-mona-ui-grid-grid-list.component-ihQIKeP-.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-C_kCaA5b.mjs → nanahoshi-mona-ui-grid-grid-row.component-BpnybNcs.mjs} +18 -35
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-BsNfrAHz.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-CYlgfc7c.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CEfVa7eo.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-LCzfCYd3.mjs} +4653 -4529
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +1 -0
- package/fesm2022/nanahoshi-mona-ui-internal-popup-menu.mjs +168 -0
- package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +19 -1
- package/fesm2022/nanahoshi-mona-ui-list-box.mjs +14 -0
- package/fesm2022/nanahoshi-mona-ui-list-view.mjs +32 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-menubar.mjs +15 -8
- package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +8 -5
- package/fesm2022/nanahoshi-mona-ui-notification.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-otp-input.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-pager.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-popover.mjs +14 -6
- package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +48 -183
- package/fesm2022/nanahoshi-mona-ui-popup.mjs +16 -0
- package/fesm2022/nanahoshi-mona-ui-progress-bar.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-rating.mjs +2 -0
- package/fesm2022/nanahoshi-mona-ui-segmented.mjs +1 -0
- package/fesm2022/nanahoshi-mona-ui-sheet.mjs +5 -5
- package/fesm2022/nanahoshi-mona-ui-sidebar.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-slider.mjs +7 -2
- package/fesm2022/nanahoshi-mona-ui-split-button.mjs +9 -6
- package/fesm2022/nanahoshi-mona-ui-stepper.mjs +18 -21
- package/fesm2022/nanahoshi-mona-ui-tabs.mjs +11 -8
- package/fesm2022/nanahoshi-mona-ui-text-box.mjs +9 -1
- package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +16 -5
- package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +13 -11
- package/fesm2022/nanahoshi-mona-ui-window.mjs +12 -5
- package/i18n/catalogs/en-US.messages.json +10 -0
- package/internal/popup-menu/package.json +4 -0
- package/llms.txt +123 -0
- package/locales/ar-sa/ar-sa.messages.json +10 -0
- package/locales/de-de/de-de.messages.json +10 -0
- package/locales/es-es/es-es.messages.json +10 -0
- package/locales/fr-fr/fr-fr.messages.json +10 -0
- package/locales/id-id/id-id.messages.json +10 -0
- package/locales/it-it/it-it.messages.json +10 -0
- package/locales/ja-jp/ja-jp.messages.json +10 -0
- package/locales/ko-kr/ko-kr.messages.json +10 -0
- package/locales/pt-br/pt-br.messages.json +10 -0
- package/locales/ru-ru/ru-ru.messages.json +10 -0
- package/locales/tr-tr/tr-tr.messages.json +10 -0
- package/locales/zh-cn/zh-cn.messages.json +10 -0
- package/locales/zh-tw/zh-tw.messages.json +10 -0
- package/package.json +9 -1
- package/types/nanahoshi-mona-ui-auto-complete.d.ts +1 -1
- package/types/nanahoshi-mona-ui-breadcrumb.d.ts +8 -0
- package/types/nanahoshi-mona-ui-button.d.ts +12 -0
- package/types/nanahoshi-mona-ui-calendar.d.ts +3 -0
- package/types/nanahoshi-mona-ui-chart.d.ts +200 -0
- package/types/nanahoshi-mona-ui-check-box.d.ts +4 -0
- package/types/nanahoshi-mona-ui-circular-progress-bar.d.ts +4 -0
- package/types/nanahoshi-mona-ui-collapsible.d.ts +10 -0
- package/types/nanahoshi-mona-ui-combo-box.d.ts +1 -1
- package/types/nanahoshi-mona-ui-command.d.ts +253 -0
- package/types/nanahoshi-mona-ui-common.d.ts +17 -1
- package/types/nanahoshi-mona-ui-contextmenu.d.ts +5 -2
- package/types/nanahoshi-mona-ui-date-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-datetime-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-dialog.d.ts +58 -1
- package/types/nanahoshi-mona-ui-dropdown-button.d.ts +7 -3
- package/types/nanahoshi-mona-ui-dropdowns.d.ts +55 -1
- package/types/nanahoshi-mona-ui-editor.d.ts +31 -0
- package/types/nanahoshi-mona-ui-expansion-panel.d.ts +13 -0
- package/types/nanahoshi-mona-ui-fieldset.d.ts +5 -0
- package/types/nanahoshi-mona-ui-grid.d.ts +162 -35
- package/types/nanahoshi-mona-ui-i18n.d.ts +144 -1
- package/types/nanahoshi-mona-ui-internal-list.d.ts +16 -1
- package/types/nanahoshi-mona-ui-internal-popup-menu.d.ts +165 -0
- package/types/nanahoshi-mona-ui-internal-tree.d.ts +21 -2
- package/types/nanahoshi-mona-ui-internal.d.ts +4 -5
- package/types/nanahoshi-mona-ui-label.d.ts +1 -0
- package/types/nanahoshi-mona-ui-list-box.d.ts +27 -4
- package/types/nanahoshi-mona-ui-list-view.d.ts +34 -1
- package/types/nanahoshi-mona-ui-list.d.ts +1 -1
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +10 -0
- package/types/nanahoshi-mona-ui-menubar.d.ts +10 -3
- package/types/nanahoshi-mona-ui-multi-select.d.ts +3 -3
- package/types/nanahoshi-mona-ui-notification.d.ts +9 -0
- package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +1 -1
- package/types/nanahoshi-mona-ui-otp-input.d.ts +1 -0
- package/types/nanahoshi-mona-ui-pager.d.ts +5 -1
- package/types/nanahoshi-mona-ui-popover.d.ts +9 -1
- package/types/nanahoshi-mona-ui-popup-menu.d.ts +48 -161
- package/types/nanahoshi-mona-ui-popup.d.ts +16 -0
- package/types/nanahoshi-mona-ui-progress-bar.d.ts +4 -0
- package/types/nanahoshi-mona-ui-rating.d.ts +2 -0
- package/types/nanahoshi-mona-ui-segmented.d.ts +1 -0
- package/types/nanahoshi-mona-ui-sheet.d.ts +1 -1
- package/types/nanahoshi-mona-ui-slider.d.ts +2 -0
- package/types/nanahoshi-mona-ui-spinner.d.ts +7 -0
- package/types/nanahoshi-mona-ui-split-button.d.ts +7 -4
- package/types/nanahoshi-mona-ui-stepper.d.ts +11 -2
- package/types/nanahoshi-mona-ui-tabs.d.ts +4 -1
- package/types/nanahoshi-mona-ui-text-box.d.ts +9 -1
- package/types/nanahoshi-mona-ui-time-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-tooltip.d.ts +10 -2
- package/types/nanahoshi-mona-ui-tree-view.d.ts +6 -5
- package/types/nanahoshi-mona-ui-window.d.ts +66 -1
package/docs/sidebar.md
ADDED
|
@@ -0,0 +1,1126 @@
|
|
|
1
|
+
# Sidebar
|
|
2
|
+
|
|
3
|
+
> A composable application shell with collapsible side panels.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/sidebar`
|
|
6
|
+
|
|
7
|
+
**Selectors:** `mona-sidebar-layout`, `mona-sidebar`, `[monaSidebarInset]`, `[monaSidebarTrigger]`, and the menu parts below
|
|
8
|
+
|
|
9
|
+
Sidebar is a composable application shell. `mona-sidebar-layout` lays out one or more `mona-sidebar` panels beside a `[monaSidebarInset]` main region, and owns what they share — the breakpoint, the backdrop. Each panel keeps its own state. Everything else — headers, groups, menus, rows, footers — is a directive you apply to your own markup, so the structure stays yours.
|
|
10
|
+
|
|
11
|
+
On wide viewports the sidebar is a column that can collapse to an icon rail or off-canvas entirely. Below `mobileBreakpoint` it presents as a modal overlay drawer with its own open state, a backdrop, focus trapping, and Escape to dismiss.
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
The sidebar is split into a small number of structural pieces and a set of content directives.
|
|
16
|
+
|
|
17
|
+
- `SidebarLayoutComponent` (`mona-sidebar-layout`) provides the row layout and what the panels share — the breakpoint, and the one backdrop behind whichever drawer is open. It is the only piece that must wrap the others.
|
|
18
|
+
- `SidebarComponent` (`mona-sidebar`) is the panel, and owns its own state. It takes `width`, `collapsible`, `variant`, `side` and `expanded`, and switches itself to a modal drawer on compact viewports. A layout can hold more than one.
|
|
19
|
+
- `SidebarInsetDirective` (`[monaSidebarInset]`) marks the main region beside the panel. It fills the remaining width, scrolls independently, and goes inert behind an open drawer.
|
|
20
|
+
- `SidebarTriggerDirective` (`[monaSidebarTrigger]`) toggles a sidebar from anywhere inside the layout, naming one with `for` where there is more than one.
|
|
21
|
+
|
|
22
|
+
Content is projected in author order, so a header, content region and footer appear exactly where you write them. None of the directives add wrapper elements.
|
|
23
|
+
|
|
24
|
+
### The parts
|
|
25
|
+
|
|
26
|
+
Apart from the skeleton, everything below is a directive applied to your own element. None of them are required, and none add markup of their own. The [API](#api) section lists their inputs.
|
|
27
|
+
|
|
28
|
+
| Part | Host | Purpose |
|
|
29
|
+
| --- | --- | --- |
|
|
30
|
+
| `[monaSidebarHeader]` | any | Pinned region at the top, above the scrolling content |
|
|
31
|
+
| `[monaSidebarContent]` | any | The scrolling region between header and footer |
|
|
32
|
+
| `[monaSidebarFooter]` | any | Pinned region at the bottom |
|
|
33
|
+
| `[monaSidebarGroup]` | any | A titled section; stack as many as you need |
|
|
34
|
+
| `[monaSidebarGroupHeader]` | any | The row holding a group's label and action; collapses away on the rail |
|
|
35
|
+
| `[monaSidebarGroupLabel]` | any | The group's name, which the group is labelled by; fades out on the rail |
|
|
36
|
+
| `[monaSidebarGroupAction]` | `button` | A control in the group header's corner; needs an `aria-label` |
|
|
37
|
+
| `[monaSidebarGroupContent]` | any | The group's body, wrapping its menu |
|
|
38
|
+
| `[monaSidebarMenu]` | `ul` | A list of rows |
|
|
39
|
+
| `[monaSidebarMenuItem]` | `li` | One row; owns the highlight and `active` |
|
|
40
|
+
| `[monaSidebarMenuButton]` | `a` / `button` | The row's control; takes `tooltip`, `size`, `disabled`, `closeOnSelect` |
|
|
41
|
+
| `[monaSidebarMenuAction]` | `button` | A trailing control inside the row; needs an `aria-label` |
|
|
42
|
+
| `[monaSidebarMenuBadge]` | any | A trailing count or status; stands down on the rail |
|
|
43
|
+
| `[monaSidebarMenuSub]` | `ul` | An indented submenu inside a collapsible item |
|
|
44
|
+
| `[monaSidebarInput]` | `input` | A text input sized for the sidebar; stands down on the rail |
|
|
45
|
+
| `[monaSidebarSeparator]` | any | A rule between regions |
|
|
46
|
+
| `[monaSidebarRail]` | `button` | A pointer shortcut along the panel's edge; not a keyboard control — see below |
|
|
47
|
+
| `mona-sidebar-menu-skeleton` | element | A loading placeholder row |
|
|
48
|
+
|
|
49
|
+
A row is an item plus a control, and optionally something trailing:
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<li monaSidebarMenuItem [active]="isCurrent()">
|
|
53
|
+
<a monaSidebarMenuButton routerLink="/inbox" tooltip="Inbox">
|
|
54
|
+
<svg lucideInbox [size]="16"></svg>
|
|
55
|
+
<span>Inbox</span>
|
|
56
|
+
</a>
|
|
57
|
+
<span monaSidebarMenuBadge>12</span>
|
|
58
|
+
</li>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Import & Quick Start
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import {
|
|
65
|
+
SidebarComponent,
|
|
66
|
+
SidebarContentDirective,
|
|
67
|
+
SidebarInsetDirective,
|
|
68
|
+
SidebarLayoutComponent,
|
|
69
|
+
SidebarMenuButtonDirective,
|
|
70
|
+
SidebarMenuDirective,
|
|
71
|
+
SidebarMenuItemDirective,
|
|
72
|
+
SidebarTriggerDirective
|
|
73
|
+
} from "@nanahoshi/mona-ui/sidebar";
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```html
|
|
77
|
+
<mona-sidebar-layout>
|
|
78
|
+
<mona-sidebar collapsible="icon">
|
|
79
|
+
<nav monaSidebarContent aria-label="Main">
|
|
80
|
+
<ul monaSidebarMenu>
|
|
81
|
+
<li monaSidebarMenuItem [active]="true">
|
|
82
|
+
<a monaSidebarMenuButton href="/inbox" tooltip="Inbox">
|
|
83
|
+
<svg lucideInbox [size]="16"></svg>
|
|
84
|
+
<span>Inbox</span>
|
|
85
|
+
</a>
|
|
86
|
+
</li>
|
|
87
|
+
</ul>
|
|
88
|
+
</nav>
|
|
89
|
+
</mona-sidebar>
|
|
90
|
+
|
|
91
|
+
<main monaSidebarInset>
|
|
92
|
+
<button monaSidebarTrigger aria-label="Toggle sidebar">Menu</button>
|
|
93
|
+
<router-outlet></router-outlet>
|
|
94
|
+
</main>
|
|
95
|
+
</mona-sidebar-layout>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Examples
|
|
99
|
+
|
|
100
|
+
### Collapsing to icons
|
|
101
|
+
|
|
102
|
+
With `collapsible="icon"` the panel narrows to a rail of icons. Each row's `tooltip` names it there, and the rail along the edge and the trigger both toggle it.
|
|
103
|
+
|
|
104
|
+
`icon-rail-example.component.ts`
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { Component, signal } from "@angular/core";
|
|
108
|
+
import { LucideArchive, LucideDynamicIcon, LucideInbox, LucidePanelLeft, LucideSend } from "@lucide/angular";
|
|
109
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
110
|
+
import {
|
|
111
|
+
SidebarComponent,
|
|
112
|
+
SidebarContentDirective,
|
|
113
|
+
SidebarGroupContentDirective,
|
|
114
|
+
SidebarGroupDirective,
|
|
115
|
+
SidebarGroupHeaderDirective,
|
|
116
|
+
SidebarGroupLabelDirective,
|
|
117
|
+
SidebarInsetDirective,
|
|
118
|
+
SidebarLayoutComponent,
|
|
119
|
+
SidebarMenuBadgeDirective,
|
|
120
|
+
SidebarMenuButtonDirective,
|
|
121
|
+
SidebarMenuDirective,
|
|
122
|
+
SidebarMenuItemDirective,
|
|
123
|
+
SidebarRailDirective,
|
|
124
|
+
SidebarTriggerDirective
|
|
125
|
+
} from "@nanahoshi/mona-ui/sidebar";
|
|
126
|
+
|
|
127
|
+
@Component({
|
|
128
|
+
selector: "app-sidebar-icon-rail-example",
|
|
129
|
+
imports: [
|
|
130
|
+
ButtonDirective,
|
|
131
|
+
LucideDynamicIcon,
|
|
132
|
+
LucidePanelLeft,
|
|
133
|
+
SidebarComponent,
|
|
134
|
+
SidebarContentDirective,
|
|
135
|
+
SidebarGroupContentDirective,
|
|
136
|
+
SidebarGroupDirective,
|
|
137
|
+
SidebarGroupHeaderDirective,
|
|
138
|
+
SidebarGroupLabelDirective,
|
|
139
|
+
SidebarInsetDirective,
|
|
140
|
+
SidebarLayoutComponent,
|
|
141
|
+
SidebarMenuBadgeDirective,
|
|
142
|
+
SidebarMenuButtonDirective,
|
|
143
|
+
SidebarMenuDirective,
|
|
144
|
+
SidebarMenuItemDirective,
|
|
145
|
+
SidebarRailDirective,
|
|
146
|
+
SidebarTriggerDirective
|
|
147
|
+
],
|
|
148
|
+
templateUrl: "./icon-rail-example.component.html"
|
|
149
|
+
})
|
|
150
|
+
export class SidebarIconRailExampleComponent {
|
|
151
|
+
protected readonly current = signal("Inbox");
|
|
152
|
+
protected readonly folders = [
|
|
153
|
+
{ href: "/mail/inbox", icon: LucideInbox, label: "Inbox", unread: 12 },
|
|
154
|
+
{ href: "/mail/sent", icon: LucideSend, label: "Sent", unread: 0 },
|
|
155
|
+
{ href: "/mail/archive", icon: LucideArchive, label: "Archive", unread: 0 }
|
|
156
|
+
];
|
|
157
|
+
|
|
158
|
+
/** Stands in for the router, so the example stays on this page. */
|
|
159
|
+
protected open(event: Event, label: string): void {
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
this.current.set(label);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`icon-rail-example.component.html`
|
|
167
|
+
|
|
168
|
+
```html
|
|
169
|
+
<mona-sidebar-layout class="h-80 border border-border" modalScope="layout">
|
|
170
|
+
<mona-sidebar collapsible="icon">
|
|
171
|
+
<nav monaSidebarContent aria-label="Mail">
|
|
172
|
+
<div monaSidebarGroup>
|
|
173
|
+
<div monaSidebarGroupHeader>
|
|
174
|
+
<div monaSidebarGroupLabel>Mail</div>
|
|
175
|
+
</div>
|
|
176
|
+
<div monaSidebarGroupContent>
|
|
177
|
+
<ul monaSidebarMenu>
|
|
178
|
+
@for (folder of folders; track folder.label) {
|
|
179
|
+
<li monaSidebarMenuItem [active]="current() === folder.label">
|
|
180
|
+
<a monaSidebarMenuButton [href]="folder.href" [tooltip]="folder.label" (click)="open($event, folder.label)">
|
|
181
|
+
<svg aria-hidden="true" [lucideIcon]="folder.icon" [size]="16"></svg>
|
|
182
|
+
<span>{{ folder.label }}</span>
|
|
183
|
+
</a>
|
|
184
|
+
@if (folder.unread) {
|
|
185
|
+
<span monaSidebarMenuBadge>{{ folder.unread }}</span>
|
|
186
|
+
}
|
|
187
|
+
</li>
|
|
188
|
+
}
|
|
189
|
+
</ul>
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
</nav>
|
|
193
|
+
<button monaSidebarRail type="button"></button>
|
|
194
|
+
</mona-sidebar>
|
|
195
|
+
|
|
196
|
+
<div class="gap-2 p-4" monaSidebarInset>
|
|
197
|
+
<button monaButton monaSidebarTrigger aria-label="Toggle sidebar" look="ghost" type="button" [iconOnly]="true">
|
|
198
|
+
<svg lucidePanelLeft aria-hidden="true" [size]="16"></svg>
|
|
199
|
+
</button>
|
|
200
|
+
<p class="text-sm">Showing {{ current() }}</p>
|
|
201
|
+
</div>
|
|
202
|
+
</mona-sidebar-layout>
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### With a submenu
|
|
206
|
+
|
|
207
|
+
A submenu is a `monaCollapsible` item whose content is a `monaSidebarMenuSub` list.
|
|
208
|
+
|
|
209
|
+
`submenus-example.component.ts`
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
import { Component } from "@angular/core";
|
|
213
|
+
import { LucideBookOpen, LucideChevronRight, LucideFolder, LucidePanelLeft } from "@lucide/angular";
|
|
214
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
215
|
+
import {
|
|
216
|
+
CollapsibleContentDirective,
|
|
217
|
+
CollapsibleDirective,
|
|
218
|
+
CollapsibleTriggerDirective
|
|
219
|
+
} from "@nanahoshi/mona-ui/collapsible";
|
|
220
|
+
import {
|
|
221
|
+
SidebarComponent,
|
|
222
|
+
SidebarContentDirective,
|
|
223
|
+
SidebarInsetDirective,
|
|
224
|
+
SidebarLayoutComponent,
|
|
225
|
+
SidebarMenuButtonDirective,
|
|
226
|
+
SidebarMenuDirective,
|
|
227
|
+
SidebarMenuItemDirective,
|
|
228
|
+
SidebarMenuSubDirective,
|
|
229
|
+
SidebarTriggerDirective
|
|
230
|
+
} from "@nanahoshi/mona-ui/sidebar";
|
|
231
|
+
|
|
232
|
+
@Component({
|
|
233
|
+
selector: "app-sidebar-submenus-example",
|
|
234
|
+
imports: [
|
|
235
|
+
ButtonDirective,
|
|
236
|
+
CollapsibleContentDirective,
|
|
237
|
+
CollapsibleDirective,
|
|
238
|
+
CollapsibleTriggerDirective,
|
|
239
|
+
LucideBookOpen,
|
|
240
|
+
LucideChevronRight,
|
|
241
|
+
LucideFolder,
|
|
242
|
+
LucidePanelLeft,
|
|
243
|
+
SidebarComponent,
|
|
244
|
+
SidebarContentDirective,
|
|
245
|
+
SidebarInsetDirective,
|
|
246
|
+
SidebarLayoutComponent,
|
|
247
|
+
SidebarMenuButtonDirective,
|
|
248
|
+
SidebarMenuDirective,
|
|
249
|
+
SidebarMenuItemDirective,
|
|
250
|
+
SidebarMenuSubDirective,
|
|
251
|
+
SidebarTriggerDirective
|
|
252
|
+
],
|
|
253
|
+
templateUrl: "./submenus-example.component.html"
|
|
254
|
+
})
|
|
255
|
+
export class SidebarSubmenusExampleComponent {
|
|
256
|
+
protected readonly pages = ["Button", "Card", "Tabs"];
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
`submenus-example.component.html`
|
|
261
|
+
|
|
262
|
+
```html
|
|
263
|
+
<mona-sidebar-layout class="h-80 border border-border" modalScope="layout">
|
|
264
|
+
<mona-sidebar collapsible="icon">
|
|
265
|
+
<nav monaSidebarContent aria-label="Documentation">
|
|
266
|
+
<ul monaSidebarMenu>
|
|
267
|
+
<li monaSidebarMenuItem>
|
|
268
|
+
<a monaSidebarMenuButton href="/docs" tooltip="Introduction" (click)="$event.preventDefault()">
|
|
269
|
+
<svg lucideBookOpen aria-hidden="true" [size]="16"></svg>
|
|
270
|
+
<span>Introduction</span>
|
|
271
|
+
</a>
|
|
272
|
+
</li>
|
|
273
|
+
<li #components="monaCollapsible" monaCollapsible monaSidebarMenuItem [expanded]="true">
|
|
274
|
+
<button monaCollapsibleTrigger monaSidebarMenuButton tooltip="Components" type="button">
|
|
275
|
+
<svg lucideFolder aria-hidden="true" [size]="16"></svg>
|
|
276
|
+
<span>Components</span>
|
|
277
|
+
<svg
|
|
278
|
+
class="ms-auto transition-transform"
|
|
279
|
+
lucideChevronRight
|
|
280
|
+
aria-hidden="true"
|
|
281
|
+
[size]="16"
|
|
282
|
+
[style.rotate]="components.expanded() ? '90deg' : '0deg'"></svg>
|
|
283
|
+
</button>
|
|
284
|
+
<ul monaCollapsibleContent monaSidebarMenuSub>
|
|
285
|
+
@for (page of pages; track page) {
|
|
286
|
+
<li monaSidebarMenuItem>
|
|
287
|
+
<a monaSidebarMenuButton href="/docs" (click)="$event.preventDefault()">{{ page }}</a>
|
|
288
|
+
</li>
|
|
289
|
+
}
|
|
290
|
+
</ul>
|
|
291
|
+
</li>
|
|
292
|
+
</ul>
|
|
293
|
+
</nav>
|
|
294
|
+
</mona-sidebar>
|
|
295
|
+
|
|
296
|
+
<div class="p-4" monaSidebarInset>
|
|
297
|
+
<button monaButton monaSidebarTrigger aria-label="Toggle sidebar" look="ghost" type="button" [iconOnly]="true">
|
|
298
|
+
<svg lucidePanelLeft aria-hidden="true" [size]="16"></svg>
|
|
299
|
+
</button>
|
|
300
|
+
</div>
|
|
301
|
+
</mona-sidebar-layout>
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Two sidebars
|
|
305
|
+
|
|
306
|
+
Each sidebar has an `id`, and each trigger names the one it toggles with `for`.
|
|
307
|
+
|
|
308
|
+
`two-sidebars-example.component.ts`
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
import { Component, signal } from "@angular/core";
|
|
312
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
313
|
+
import {
|
|
314
|
+
SidebarComponent,
|
|
315
|
+
SidebarContentDirective,
|
|
316
|
+
SidebarInsetDirective,
|
|
317
|
+
SidebarLayoutComponent,
|
|
318
|
+
SidebarMenuButtonDirective,
|
|
319
|
+
SidebarMenuDirective,
|
|
320
|
+
SidebarMenuItemDirective,
|
|
321
|
+
SidebarTriggerDirective
|
|
322
|
+
} from "@nanahoshi/mona-ui/sidebar";
|
|
323
|
+
|
|
324
|
+
@Component({
|
|
325
|
+
selector: "app-sidebar-two-sidebars-example",
|
|
326
|
+
imports: [
|
|
327
|
+
ButtonDirective,
|
|
328
|
+
SidebarComponent,
|
|
329
|
+
SidebarContentDirective,
|
|
330
|
+
SidebarInsetDirective,
|
|
331
|
+
SidebarLayoutComponent,
|
|
332
|
+
SidebarMenuButtonDirective,
|
|
333
|
+
SidebarMenuDirective,
|
|
334
|
+
SidebarMenuItemDirective,
|
|
335
|
+
SidebarTriggerDirective
|
|
336
|
+
],
|
|
337
|
+
templateUrl: "./two-sidebars-example.component.html"
|
|
338
|
+
})
|
|
339
|
+
export class SidebarTwoSidebarsExampleComponent {
|
|
340
|
+
protected readonly detailsOpen = signal(false);
|
|
341
|
+
protected readonly navOpen = signal(true);
|
|
342
|
+
protected readonly projects = ["Website redesign", "Mobile app", "Billing"];
|
|
343
|
+
}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
`two-sidebars-example.component.html`
|
|
347
|
+
|
|
348
|
+
```html
|
|
349
|
+
<mona-sidebar-layout class="h-72 border border-border" modalScope="layout">
|
|
350
|
+
<mona-sidebar id="example-nav" side="start" width="12rem" [(expanded)]="navOpen">
|
|
351
|
+
<nav monaSidebarContent aria-label="Projects">
|
|
352
|
+
<ul monaSidebarMenu>
|
|
353
|
+
@for (project of projects; track project) {
|
|
354
|
+
<li monaSidebarMenuItem [active]="project === projects[0]">
|
|
355
|
+
<a monaSidebarMenuButton href="/projects" (click)="$event.preventDefault()">{{ project }}</a>
|
|
356
|
+
</li>
|
|
357
|
+
}
|
|
358
|
+
</ul>
|
|
359
|
+
</nav>
|
|
360
|
+
</mona-sidebar>
|
|
361
|
+
|
|
362
|
+
<div class="gap-2 p-4" monaSidebarInset>
|
|
363
|
+
<div class="flex gap-2">
|
|
364
|
+
<button monaButton monaSidebarTrigger for="example-nav" type="button">Projects</button>
|
|
365
|
+
<button monaButton monaSidebarTrigger for="example-details" type="button">Details</button>
|
|
366
|
+
</div>
|
|
367
|
+
<p class="text-sm">Projects open: {{ navOpen() }}, details open: {{ detailsOpen() }}</p>
|
|
368
|
+
</div>
|
|
369
|
+
|
|
370
|
+
<mona-sidebar id="example-details" aria-label="Details" side="end" width="12rem" [(expanded)]="detailsOpen">
|
|
371
|
+
<div class="space-y-1 p-3 text-sm" monaSidebarContent>
|
|
372
|
+
<p class="font-semibold">Website redesign</p>
|
|
373
|
+
<p>Owner: Grace Hopper</p>
|
|
374
|
+
<p>Due: 14 March</p>
|
|
375
|
+
</div>
|
|
376
|
+
</mona-sidebar>
|
|
377
|
+
</mona-sidebar-layout>
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
## Theming
|
|
381
|
+
|
|
382
|
+
The sidebar draws from its own colour roles, so it can sit apart from the page content without restyling every part: `--color-sidebar`, `--color-sidebar-foreground`, `--color-sidebar-primary`, `--color-sidebar-primary-foreground`, `--color-sidebar-accent`, `--color-sidebar-accent-foreground`, `--color-sidebar-border` and `--color-sidebar-ring`.
|
|
383
|
+
|
|
384
|
+
Every built-in theme defines them for each of its variants. A custom theme can build the whole set from one background with `createSidebarColorRoles()` from `@nanahoshi/mona-ui/theme`.
|
|
385
|
+
|
|
386
|
+
### Variants
|
|
387
|
+
|
|
388
|
+
| Variant | Treatment |
|
|
389
|
+
| --- | --- |
|
|
390
|
+
| `sidebar` (default) | Flush against the edge with a single border |
|
|
391
|
+
| `floating` | Detached on its own rounded, shadowed surface |
|
|
392
|
+
| `inset` | Transparent; the raised surface moves onto the inset region instead |
|
|
393
|
+
|
|
394
|
+
`width`, `iconWidth` and `mobileWidth` are the width the sidebar's *contents* receive. The variant's border is added on top, so a `3rem` icon rail always leaves exactly one `2rem` icon square whatever border the variant draws. The `sidebar` variant has no border as a drawer, so `mobileWidth` is its whole width.
|
|
395
|
+
|
|
396
|
+
## Behavior
|
|
397
|
+
|
|
398
|
+
### Controlled state
|
|
399
|
+
|
|
400
|
+
`expanded` is a two-way model on `mona-sidebar`. On a compact viewport it reflects the drawer, so one binding drives both presentations:
|
|
401
|
+
|
|
402
|
+
```html
|
|
403
|
+
<mona-sidebar-layout>
|
|
404
|
+
<mona-sidebar [(expanded)]="sidebarOpen">…</mona-sidebar>
|
|
405
|
+
</mona-sidebar-layout>
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### More than one sidebar
|
|
409
|
+
|
|
410
|
+
A layout can hold more than one sidebar — a navigation column on one edge and an inspector on the other. Each keeps its own state on its own binding, and each needs an `id` so a trigger can name it, as in the [Two sidebars](#two-sidebars) example.
|
|
411
|
+
|
|
412
|
+
A trigger with no `for` drives the sidebar it is written inside, falling back to the first sidebar in the layout — which is all a layout with a single sidebar ever needs. A `for` naming no sidebar leaves the trigger inert rather than throwing.
|
|
413
|
+
|
|
414
|
+
On a compact viewport only one drawer is open at a time: opening one closes the other, and they share the single backdrop the layout paints behind them. When one drawer opens another, closing it sends focus back to whatever opened the first. The inset steps out of the way for whichever drawer is open, and takes its surface from the first sidebar in author order.
|
|
415
|
+
|
|
416
|
+
### Remembering the state across reloads
|
|
417
|
+
|
|
418
|
+
Set `persistKey` and the sidebar comes back the way it was left:
|
|
419
|
+
|
|
420
|
+
```html
|
|
421
|
+
<mona-sidebar persistKey="nav">…</mona-sidebar>
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
Nothing is stored without a key — the sidebar never writes to storage on its own. Give each sidebar in a layout its own key.
|
|
425
|
+
|
|
426
|
+
Only the docked state is kept. A drawer is never restored open, because on the viewport that makes one it would cover the page on load, and opening a drawer never overwrites the state the desktop comes back to. A stored value wins over `expanded` and is pushed back out through that binding, so do not set a key on a sidebar whose state is already restored elsewhere.
|
|
427
|
+
|
|
428
|
+
#### Where it is kept
|
|
429
|
+
|
|
430
|
+
The default is `localStorage`, under exactly the key given, with no prefix, so pick one nothing else in the application writes to. Storage that is unavailable — a server, private browsing, a full quota — is not an error: the sidebar just opens the way its `expanded` input says.
|
|
431
|
+
|
|
432
|
+
**A server-rendered application will flash.** `localStorage` cannot be read on the server, so the markup is rendered with the default state and corrected on hydration. To avoid it, supply storage the server can read too — a cookie, or state transferred from the request:
|
|
433
|
+
|
|
434
|
+
```typescript
|
|
435
|
+
import { provideSidebarStorage, type SidebarStorage } from "@nanahoshi/mona-ui/sidebar";
|
|
436
|
+
|
|
437
|
+
const cookieStorage: SidebarStorage = {
|
|
438
|
+
read: key => { … }, // null when nothing is stored
|
|
439
|
+
write: (key, expanded) => { … }
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
bootstrapApplication(AppComponent, {
|
|
443
|
+
providers: [provideSidebarStorage(cookieStorage)]
|
|
444
|
+
});
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
`read` returns `null` when it has nothing for that key, which leaves the sidebar on its input's state. A storage that throws is reported in development and otherwise treated the same way.
|
|
448
|
+
|
|
449
|
+
`provideSidebarStorage()` also takes a factory, which runs in an injection context, for storage that needs something from the current request:
|
|
450
|
+
|
|
451
|
+
```typescript
|
|
452
|
+
provideSidebarStorage(() => new CookieStorage(inject(REQUEST)))
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
A value the default storage doesn't recognize, such as another feature's entry under the same key, counts as nothing stored, and stays there until the sidebar's state changes. Nothing is written until then. Storage isn't watched, so tabs don't follow each other.
|
|
456
|
+
|
|
457
|
+
### Reading the sidebar from a descendant
|
|
458
|
+
|
|
459
|
+
`injectSidebar()` returns the sidebar's state and the commands that are safe to issue from anywhere:
|
|
460
|
+
|
|
461
|
+
```typescript
|
|
462
|
+
import { injectSidebar } from "@nanahoshi/mona-ui/sidebar";
|
|
463
|
+
|
|
464
|
+
@Component({ … })
|
|
465
|
+
export class WorkspaceSwitcherComponent {
|
|
466
|
+
protected readonly sidebar = injectSidebar();
|
|
467
|
+
|
|
468
|
+
protected onSelect(): void {
|
|
469
|
+
if (this.sidebar.compact()) {
|
|
470
|
+
this.sidebar.collapse();
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
The controller exposes `expanded`, `state`, `iconOnly`, `compact`, `mobileOpen`, `side`, `variant`, `collapsible` and `sidebarId` as signals, plus `expand()`, `collapse()` and `toggle()`. The [API](#api) section describes each one.
|
|
477
|
+
|
|
478
|
+
Structural facts are readable but not settable. `side`, `variant` and `collapsible` are authored as inputs on `mona-sidebar`; writing them from a descendant would leave the component and the shared state disagreeing until the next change detection pass. Bind the inputs instead.
|
|
479
|
+
|
|
480
|
+
Inside a `mona-sidebar` it reads that sidebar. Elsewhere in a `mona-sidebar-layout`, such as a toolbar in the inset, it reads the layout's first sidebar in author order, or the one you name with `injectSidebar({ for: "inspector" })`. A sidebar that hasn't rendered yet reads as closed, and commands to it do nothing.
|
|
481
|
+
|
|
482
|
+
Pass `{ optional: true }` for a component that may be used outside a layout.
|
|
483
|
+
|
|
484
|
+
### Collapsible modes
|
|
485
|
+
|
|
486
|
+
| Mode | Collapsed behaviour |
|
|
487
|
+
| --- | --- |
|
|
488
|
+
| `offcanvas` (default) | Panel shrinks to nothing and is made `inert`, so nothing inside stays focusable |
|
|
489
|
+
| `icon` | Panel narrows to `iconWidth`; labels, badges, trailing actions and submenus stand aside |
|
|
490
|
+
| `none` | Collapsing is disabled; the panel stays at full width. Below `mobileBreakpoint` it's still a drawer that opens and closes |
|
|
491
|
+
|
|
492
|
+
If focus is on something that collapsing takes away, it moves to a trigger for that sidebar, or to its rail when there's no trigger, rather than falling to the page.
|
|
493
|
+
|
|
494
|
+
### Submenus
|
|
495
|
+
|
|
496
|
+
A submenu is an ordinary `monaCollapsible` on an ordinary item — the sidebar adds no disclosure of its own. Apply `monaCollapsible` to the item, `monaCollapsibleTrigger` to its control, and `monaCollapsibleContent` to a `monaSidebarMenuSub` list, as in the [With a submenu](#with-a-submenu) example.
|
|
497
|
+
|
|
498
|
+
Nesting is not limited to one level: a `monaSidebarMenuSub` can hold another collapsible item, as deep as the navigation needs. Each level is a disclosure in its own right, with its own trigger and its own open state.
|
|
499
|
+
|
|
500
|
+
#### On the icon rail
|
|
501
|
+
|
|
502
|
+
A submenu cannot render in a rail one icon wide, and there's no flyout. While on the rail every item keeps its disclosure closed, at every depth, so each trigger's `aria-expanded` stays truthful and the content stays `inert`. Activating a submenu's row on the rail expands the sidebar and opens that submenu, so its pages can always be reached. A row with no submenu leaves the rail as it is. Whatever was open before collapsing is restored when the sidebar expands again — level by level, so a submenu that was closed stays closed.
|
|
503
|
+
|
|
504
|
+
### Responsive behaviour
|
|
505
|
+
|
|
506
|
+
Below `mobileBreakpoint` (default `768`) the sidebar becomes a modal drawer:
|
|
507
|
+
|
|
508
|
+
- Slides in from its docked edge; everything outside it goes `inert` and the page stops scrolling
|
|
509
|
+
- It's a `dialog` named by `aria-label` or `aria-labelledby`, with a localized default
|
|
510
|
+
- Focus is trapped inside it, on the panel itself if it has no controls. On close, however it closed, focus returns to whatever opened it, unless it has already moved somewhere else
|
|
511
|
+
- Escape and backdrop clicks close it, wherever focus is. A docked sidebar ignores Escape. A control that calls `preventDefault()` on the key keeps it, and so does a popup opened from the drawer. In nested layouts, it closes only the inner drawer
|
|
512
|
+
- Drawer state is separate from the desktop state and resets whenever the viewport crosses the breakpoint
|
|
513
|
+
- Activating a row closes the drawer, since the destination is underneath it — opt out with `[closeOnSelect]="false"`. A row that opens a submenu leaves it open without that binding
|
|
514
|
+
|
|
515
|
+
While the viewport is compact, `[(expanded)]` reports the drawer, so it reads `false` on a phone from the start. To remember the docked state, use `persistKey` rather than saving that value.
|
|
516
|
+
|
|
517
|
+
Set `mobileBreakpoint` to `0` to keep the docked presentation at every size.
|
|
518
|
+
|
|
519
|
+
```html
|
|
520
|
+
<mona-sidebar-layout [mobileBreakpoint]="1024">
|
|
521
|
+
<mona-sidebar mobileWidth="20rem">…</mona-sidebar>
|
|
522
|
+
</mona-sidebar-layout>
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
#### How far the drawer's modality reaches
|
|
526
|
+
|
|
527
|
+
By default an open drawer makes the whole page inert and locks its scroll, so an app header above the layout can't be reached behind it. Popups opened from the drawer, such as a menu or a tooltip, stay usable. The lock only acts when the page itself scrolls: in an app whose root doesn't, there's nothing for it to lock. The inset stops scrolling behind the drawer either way.
|
|
528
|
+
|
|
529
|
+
A sidebar embedded in part of a page can keep this to its layout, with `modalScope`. Anything beside the layout that has to stay usable while a drawer is open, such as a toolbar or a Close button, needs this too. What's around the layout stays usable and the page keeps scrolling, so the drawer isn't `aria-modal` then:
|
|
530
|
+
|
|
531
|
+
```html
|
|
532
|
+
<mona-sidebar-layout modalScope="layout">…</mona-sidebar-layout>
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
The backdrop covers the layout either way, and never more than that.
|
|
536
|
+
|
|
537
|
+
### Direction
|
|
538
|
+
|
|
539
|
+
Prefer `side="start"` and `side="end"`, which follow the document's writing direction. `"left"` and `"right"` are aliases of them rather than physical sides, so `side="left"` sits on the right under RTL.
|
|
540
|
+
|
|
541
|
+
The panel's border, the drawer's edge and the rail don't use logical properties. Each resolves to a physical left or right from the direction, so they follow it too. To override that border through `class`, name the physical side, such as `border-r-0`. `tailwind-merge` treats `border-e-0` as a different class, so it doesn't replace the border.
|
|
542
|
+
|
|
543
|
+
### Server rendering
|
|
544
|
+
|
|
545
|
+
Supply a stable `id` on `mona-sidebar` so the client does not hydrate onto a different generated id:
|
|
546
|
+
|
|
547
|
+
```html
|
|
548
|
+
<mona-sidebar id="app-sidebar">…</mona-sidebar>
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
Where `matchMedia` is unavailable — a server render, a test environment — the sidebar keeps its docked presentation, which is the one that degrades gracefully.
|
|
552
|
+
|
|
553
|
+
`persistKey` needs storage the server can read, or the remembered state arrives a frame late. See [Where it is kept](#where-it-is-kept).
|
|
554
|
+
|
|
555
|
+
- Call it in an injection context. It throws when there's no sidebar or layout around the caller, unless `optional` is set.
|
|
556
|
+
|
|
557
|
+
## Accessibility
|
|
558
|
+
|
|
559
|
+
These are requirements, not suggestions. The component supplies what it can and relies on you for the rest.
|
|
560
|
+
|
|
561
|
+
### Provide a landmark
|
|
562
|
+
|
|
563
|
+
`mona-sidebar` deliberately carries no ARIA role. A sidebar usually holds more than navigation — a team switcher, a search box, a profile menu — so labelling the whole region `navigation` would over-describe it.
|
|
564
|
+
|
|
565
|
+
Wrap the menus in a labelled `nav` instead:
|
|
566
|
+
|
|
567
|
+
```html
|
|
568
|
+
<nav monaSidebarContent aria-label="Main">…</nav>
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
If the entire region really is navigation, set the role on the panel and give it a name:
|
|
572
|
+
|
|
573
|
+
```html
|
|
574
|
+
<mona-sidebar role="navigation" aria-label="Main">…</mona-sidebar>
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
Label every landmark. Two unlabelled `nav` elements on a page are indistinguishable to a screen reader user.
|
|
578
|
+
|
|
579
|
+
### Provide a trigger
|
|
580
|
+
|
|
581
|
+
`monaSidebarRail` is deliberately outside the tab order: it is a pointer shortcut, and a tab stop onto a 4px strip would be noise. It is **not** a substitute for a trigger. Always render a `monaSidebarTrigger` as well, or the sidebar cannot be opened from the keyboard at all. That includes small viewports, where the rail is hidden: below `640px`, and inside a drawer at any width.
|
|
582
|
+
|
|
583
|
+
Give the trigger an accessible name. The rail has a localized one by default, and takes an `aria-label` if you want another. The rail goes inside the sidebar, which positions it, and the trigger can go anywhere in the layout:
|
|
584
|
+
|
|
585
|
+
```html
|
|
586
|
+
<mona-sidebar>
|
|
587
|
+
…
|
|
588
|
+
<button monaSidebarRail></button>
|
|
589
|
+
</mona-sidebar>
|
|
590
|
+
<main monaSidebarInset>
|
|
591
|
+
<button monaSidebarTrigger aria-label="Toggle sidebar">…</button>
|
|
592
|
+
</main>
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
A `button` host needs nothing further. On any other element, including an `a` without `href`, the trigger supplies `role`, a tab stop, and Enter/Space activation itself.
|
|
596
|
+
|
|
597
|
+
On a sidebar that can't collapse (`collapsible="none"`) a trigger has nothing to do on a wide viewport, so it reports `aria-disabled` there rather than an open disclosure. A `for` that finds no sidebar leaves the trigger inert and warns in development. `for` only reaches sidebars in the trigger's own layout.
|
|
598
|
+
|
|
599
|
+
### Use anchors for destinations
|
|
600
|
+
|
|
601
|
+
`monaSidebarMenuButton` applies to both `a` and `button`. Use an anchor for anything that navigates:
|
|
602
|
+
|
|
603
|
+
```html
|
|
604
|
+
<a monaSidebarMenuButton routerLink="/billing" tooltip="Billing">…</a>
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
A button cannot be opened in a new tab, middle-clicked, previewed in the status bar, or followed when JavaScript fails. Reserve `button` for actions — a disclosure trigger, a sign-out.
|
|
608
|
+
|
|
609
|
+
Mark the current destination on the **item**, which owns the row's highlight. The row's control picks up `aria-current="page"` from it:
|
|
610
|
+
|
|
611
|
+
```html
|
|
612
|
+
<li monaSidebarMenuItem [active]="isCurrent()">…</li>
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
### Label the icon rail
|
|
616
|
+
|
|
617
|
+
While collapsed to icons the labels are clipped away. Set `tooltip` on every row, and the row shows it as a tooltip on hover and on keyboard focus, on the rail only. Keep a label inside the row as well: that's its accessible name, in both states.
|
|
618
|
+
|
|
619
|
+
`mona-sidebar` shows these itself, and they open toward the content. There's nothing to import, and it isn't a `title`: the browser adds no tooltip of its own, and a `monaTooltip` in `content` mode around the sidebar doesn't pick the row up. A `title` you put on a row yourself stays there, so use one or the other.
|
|
620
|
+
|
|
621
|
+
## API
|
|
622
|
+
|
|
623
|
+
Everything below is imported from `@nanahoshi/mona-ui/sidebar`.
|
|
624
|
+
|
|
625
|
+
### `SidebarComponent`
|
|
626
|
+
|
|
627
|
+
The sidebar region itself. Content is projected in author order, so header, content and footer
|
|
628
|
+
parts appear exactly where they are written.
|
|
629
|
+
|
|
630
|
+
Below the layout's `mobileBreakpoint` it presents as a modal overlay drawer: focus is trapped
|
|
631
|
+
inside it while open, restored to whatever opened it on close, and everything outside it is made
|
|
632
|
+
inert, as far as the layout's `modalScope` says. It is not a navigation landmark by itself — wrap
|
|
633
|
+
the menus in a labelled `nav`, or set `role` and `aria-label` if the whole region is navigation.
|
|
634
|
+
|
|
635
|
+
**Selector:** `mona-sidebar`
|
|
636
|
+
|
|
637
|
+
#### Inputs
|
|
638
|
+
|
|
639
|
+
| Name | Type | Default | Description |
|
|
640
|
+
| --- | --- | --- | --- |
|
|
641
|
+
| `aria-label` | `string` | `""` | Accessible name for the sidebar region. Required when `role` is set, and used as the drawer's name on compact viewports, which otherwise has a localized default. |
|
|
642
|
+
| `aria-labelledby` | `string` | `""` | The id of the element that names the sidebar region, in place of `aria-label`. A docked sidebar with no `role` ignores it. |
|
|
643
|
+
| `class` | `ClassInputType` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
644
|
+
| `collapsible` | `SidebarCollapsibleMode` | `"offcanvas"` | How the sidebar behaves when collapsed. `"icon"` keeps a narrow rail of icons visible, `"offcanvas"` removes it from the layout entirely, and `"none"` disables collapsing altogether. |
|
|
645
|
+
| `expanded` (two-way) | `boolean` | `true` | Sets whether this sidebar is open. Supports two-way binding. While the viewport is compact this reflects the drawer, so one binding drives both presentations, and it reads `false` on a phone from the start. To remember the docked state, use `persistKey` rather than saving this. |
|
|
646
|
+
| `iconWidth` | `string \| number` | `"3rem"` | Width of the icon rail while collapsed. Only applies when `collapsible` is `"icon"`. Numbers are treated as pixels. |
|
|
647
|
+
| `id` | `string` | `""` | Id for the sidebar element, referenced by triggers through `aria-controls`. Supply a stable value when the markup is server rendered, so the client does not hydrate onto a different generated id. Falls back to a generated id. |
|
|
648
|
+
| `mobileWidth` | `string \| number` | `"18rem"` | Width of the overlay drawer on compact viewports. Numbers are treated as pixels. |
|
|
649
|
+
| `persistKey` | `string` | `""` | Remembers whether this sidebar was left open, under this key. Unset means nothing is stored — no key, no storage written. Only the docked state is kept. A drawer is never restored open: on the viewport that makes one, it would cover the page on load. A stored value wins over `expanded`, and is pushed back out through that binding, so do not set a key on a sidebar whose state is already restored elsewhere. Where it is kept is `SIDEBAR_STORAGE`, which defaults to `localStorage`. A server-rendered application cannot read that until hydration and so flashes the default first; supply storage the server can read through `provideSidebarStorage()`. |
|
|
650
|
+
| `role` | `string` | `""` | ARIA role for the sidebar region. Leave unset and wrap the menus in a labelled `nav` when the sidebar holds more than navigation; set `"navigation"` with an `aria-label` when it does not. Ignored on compact viewports, where the drawer is a `dialog`. |
|
|
651
|
+
| `side` | `SidebarSide` | `"start"` | Which edge the sidebar sits on. Prefer `"start"` and `"end"`, which follow the document's writing direction; `"left"` and `"right"` are aliases of them. |
|
|
652
|
+
| `variant` | `SidebarVariant` | `"sidebar"` | The visual treatment of the sidebar. `"floating"` detaches it from the edge on its own surface, and `"inset"` moves that raised surface onto the region beside it instead. |
|
|
653
|
+
| `width` | `string \| number` | `"16rem"` | Width of the sidebar while expanded. Numbers are treated as pixels. |
|
|
654
|
+
|
|
655
|
+
#### Outputs
|
|
656
|
+
|
|
657
|
+
| Name | Type | Description |
|
|
658
|
+
| --- | --- | --- |
|
|
659
|
+
| `expandedChange` | `boolean` | Emitted when `expanded` changes. |
|
|
660
|
+
|
|
661
|
+
### `SidebarLayoutComponent`
|
|
662
|
+
|
|
663
|
+
Lays its children out in a row and owns what they share. Project one or more `mona-sidebar`
|
|
664
|
+
elements and an element marked with `monaSidebarInset` into it. Each sidebar keeps its own open
|
|
665
|
+
state, on its own `[(expanded)]` binding, so a layout can hold a navigation column on one edge and
|
|
666
|
+
an inspector on the other.
|
|
667
|
+
|
|
668
|
+
Below `mobileBreakpoint` sidebars present as overlay drawers instead of columns. A drawer has its
|
|
669
|
+
own open state, so a sidebar collapsed on a desktop does not come back open on a phone, and it is
|
|
670
|
+
reset whenever the viewport crosses the breakpoint. Only one drawer is open at a time: opening one
|
|
671
|
+
closes any other, and they share the single backdrop this layout paints behind them.
|
|
672
|
+
|
|
673
|
+
**Selector:** `mona-sidebar-layout`
|
|
674
|
+
|
|
675
|
+
#### Inputs
|
|
676
|
+
|
|
677
|
+
| Name | Type | Default | Description |
|
|
678
|
+
| --- | --- | --- | --- |
|
|
679
|
+
| `class` | `ClassInputType` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
680
|
+
| `mobileBreakpoint` | `number` | `768` | Viewport width, in pixels, below which the sidebar presents as an overlay drawer. Set to `0` to keep the docked presentation at every size. |
|
|
681
|
+
| `modalScope` | `SidebarModalScope` | `"page"` | How far an open drawer's modality reaches. `"page"` makes everything outside the drawer inert and locks the page's scroll. Use `"layout"` for a sidebar embedded in part of a page: what's around the layout stays usable, so the drawer isn't `aria-modal`. |
|
|
682
|
+
|
|
683
|
+
### `SidebarMenuSkeletonComponent`
|
|
684
|
+
|
|
685
|
+
A loading placeholder shaped like a menu item. Its label bar is clipped on the icon rail, where the
|
|
686
|
+
real labels are not visible either.
|
|
687
|
+
|
|
688
|
+
**Selector:** `mona-sidebar-menu-skeleton`
|
|
689
|
+
|
|
690
|
+
#### Inputs
|
|
691
|
+
|
|
692
|
+
| Name | Type | Default | Description |
|
|
693
|
+
| --- | --- | --- | --- |
|
|
694
|
+
| `labelWidth` | `string \| number` | `"60%"` | Width of the label bar. Varying it across a list keeps the placeholder from looking like a rigid grid. Numbers are treated as pixels. |
|
|
695
|
+
| `showIcon` | `boolean` | `true` | Renders a square standing in for the item's icon. |
|
|
696
|
+
|
|
697
|
+
### `SidebarMenuButtonDirective`
|
|
698
|
+
|
|
699
|
+
A row in a sidebar menu. Applies to a `button` for an action and to an `a` for a destination —
|
|
700
|
+
an anchor keeps `href`, `routerLink`, middle-click, open-in-new-tab and the browser's own status
|
|
701
|
+
bar preview, none of which a button can offer.
|
|
702
|
+
|
|
703
|
+
On a compact viewport, following a link closes the drawer, since the destination it navigates to is
|
|
704
|
+
underneath it. A row that opens a submenu leaves the drawer open, and on the icon rail it expands the
|
|
705
|
+
sidebar, since that's the only place the submenu can open.
|
|
706
|
+
|
|
707
|
+
**Selector:** `a[monaSidebarMenuButton], button[monaSidebarMenuButton]`
|
|
708
|
+
**Exported as:** `monaSidebarMenuButton`
|
|
709
|
+
|
|
710
|
+
#### Inputs
|
|
711
|
+
|
|
712
|
+
| Name | Type | Default | Description |
|
|
713
|
+
| --- | --- | --- | --- |
|
|
714
|
+
| `class` | `ClassInputType` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
715
|
+
| `closeOnSelect` | `boolean \| undefined` | `undefined` | Closes the overlay drawer after this row is activated. Only applies on compact viewports, where the drawer covers the destination being navigated to. Set to `false` for rows that do not navigate. Leave it unset on a `monaCollapsibleTrigger`, which keeps the drawer open. |
|
|
716
|
+
| `disabled` | `boolean` | `false` | Renders the row as unavailable and suppresses activation, including a `routerLink` and any `click` handler on it. A disabled anchor gives up its `href`. |
|
|
717
|
+
| `size` | `SidebarMenuButtonSize` | `"medium"` | How much room this row's leading visual needs. Use `"large"` when it opens with something avatar sized, so the icon rail lets it fill the square instead of insetting and clipping it. |
|
|
718
|
+
| `tooltip` | `string` | `""` | Text identifying this item while the sidebar is collapsed to its icon rail, where the label is clipped away. Shown as a tooltip on hover and on keyboard focus, on the rail only. |
|
|
719
|
+
|
|
720
|
+
### `SidebarMenuItemDirective`
|
|
721
|
+
|
|
722
|
+
**Selector:** `li[monaSidebarMenuItem]`
|
|
723
|
+
|
|
724
|
+
#### Inputs
|
|
725
|
+
|
|
726
|
+
| Name | Type | Default | Description |
|
|
727
|
+
| --- | --- | --- | --- |
|
|
728
|
+
| `active` | `boolean` | `false` | Marks this row as the current sidebar destination. The row owns the selected surface so trailing badges and actions remain inside one continuous highlight. |
|
|
729
|
+
| `class` | `ClassInputType` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
730
|
+
|
|
731
|
+
### `SidebarFooterDirective`
|
|
732
|
+
|
|
733
|
+
The region at the bottom of the sidebar, below its content. Holds what stays put while the content
|
|
734
|
+
scrolls — a profile menu, a sign-out.
|
|
735
|
+
|
|
736
|
+
**Selector:** `[monaSidebarFooter]`
|
|
737
|
+
|
|
738
|
+
#### Inputs
|
|
739
|
+
|
|
740
|
+
| Name | Type | Default | Description |
|
|
741
|
+
| --- | --- | --- | --- |
|
|
742
|
+
| `class` | `ClassInputType` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
743
|
+
|
|
744
|
+
### `SidebarHeaderDirective`
|
|
745
|
+
|
|
746
|
+
The region at the top of the sidebar, above its content. Holds what stays put while the content
|
|
747
|
+
scrolls — a workspace switcher, a search box.
|
|
748
|
+
|
|
749
|
+
**Selector:** `[monaSidebarHeader]`
|
|
750
|
+
|
|
751
|
+
#### Inputs
|
|
752
|
+
|
|
753
|
+
| Name | Type | Default | Description |
|
|
754
|
+
| --- | --- | --- | --- |
|
|
755
|
+
| `class` | `ClassInputType` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
756
|
+
|
|
757
|
+
### `SidebarInsetDirective`
|
|
758
|
+
|
|
759
|
+
Marks the main region beside the sidebar. Fills the remaining width and scrolls independently.
|
|
760
|
+
Takes on the raised surface when the sidebar uses the `inset` variant.
|
|
761
|
+
|
|
762
|
+
It sits beside the sidebars rather than inside one, so it answers to the layout as a whole: it steps
|
|
763
|
+
out of the way for whichever drawer is open, and where a layout holds more than one sidebar it takes
|
|
764
|
+
its surface from the first one in author order.
|
|
765
|
+
|
|
766
|
+
**Selector:** `[monaSidebarInset]`
|
|
767
|
+
|
|
768
|
+
#### Inputs
|
|
769
|
+
|
|
770
|
+
| Name | Type | Default | Description |
|
|
771
|
+
| --- | --- | --- | --- |
|
|
772
|
+
| `class` | `ClassInputType` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
773
|
+
|
|
774
|
+
### `SidebarMenuBadgeDirective`
|
|
775
|
+
|
|
776
|
+
A trailing count or status badge on a menu item. Stands down on the icon rail, where it would
|
|
777
|
+
crowd out the icon it belongs to.
|
|
778
|
+
|
|
779
|
+
**Selector:** `[monaSidebarMenuBadge]`
|
|
780
|
+
|
|
781
|
+
#### Inputs
|
|
782
|
+
|
|
783
|
+
| Name | Type | Default | Description |
|
|
784
|
+
| --- | --- | --- | --- |
|
|
785
|
+
| `class` | `ClassInputType` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
786
|
+
|
|
787
|
+
### `SidebarMenuDirective`
|
|
788
|
+
|
|
789
|
+
**Selector:** `ul[monaSidebarMenu]`
|
|
790
|
+
|
|
791
|
+
#### Inputs
|
|
792
|
+
|
|
793
|
+
| Name | Type | Default | Description |
|
|
794
|
+
| --- | --- | --- | --- |
|
|
795
|
+
| `class` | `ClassInputType` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
796
|
+
|
|
797
|
+
### `SidebarMenuSubDirective`
|
|
798
|
+
|
|
799
|
+
An indented submenu inside a `monaSidebarMenuItem` that is also a `monaCollapsible`.
|
|
800
|
+
|
|
801
|
+
It carries no hiding of its own on the icon rail. `SidebarMenuItemDirective` closes the disclosure
|
|
802
|
+
there instead, which leaves the trigger's `aria-expanded` truthful and lets the collapsible content
|
|
803
|
+
directive apply its own `inert`. Hiding it here as well used to produce the opposite: a submenu the
|
|
804
|
+
trigger still described as expanded, with focusable items, that nobody could see.
|
|
805
|
+
|
|
806
|
+
**Selector:** `ul[monaSidebarMenuSub]`
|
|
807
|
+
|
|
808
|
+
#### Inputs
|
|
809
|
+
|
|
810
|
+
| Name | Type | Default | Description |
|
|
811
|
+
| --- | --- | --- | --- |
|
|
812
|
+
| `class` | `ClassInputType` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
813
|
+
|
|
814
|
+
### `SidebarRailDirective`
|
|
815
|
+
|
|
816
|
+
A thin strip along the sidebar's inner edge that toggles it. Place it inside `mona-sidebar`,
|
|
817
|
+
which positions it. Hidden on narrow viewports, where the edge is too easy to hit by accident.
|
|
818
|
+
|
|
819
|
+
Deliberately outside the tab order: it is a pointer shortcut for what `monaSidebarTrigger` already
|
|
820
|
+
does, and a second tab stop onto a 4px strip would be noise for keyboard users. Provide a
|
|
821
|
+
`monaSidebarTrigger` as well — the rail is not a substitute for it.
|
|
822
|
+
|
|
823
|
+
**Selector:** `button[monaSidebarRail]`
|
|
824
|
+
|
|
825
|
+
#### Inputs
|
|
826
|
+
|
|
827
|
+
| Name | Type | Default | Description |
|
|
828
|
+
| --- | --- | --- | --- |
|
|
829
|
+
| `aria-label` | `string` | `""` | Accessible name of the rail, which otherwise has a localized default. |
|
|
830
|
+
|
|
831
|
+
### `SidebarSeparatorDirective`
|
|
832
|
+
|
|
833
|
+
A horizontal rule between sidebar regions. Tightens its inset on the icon rail.
|
|
834
|
+
|
|
835
|
+
**Selector:** `[monaSidebarSeparator]`
|
|
836
|
+
|
|
837
|
+
#### Inputs
|
|
838
|
+
|
|
839
|
+
| Name | Type | Default | Description |
|
|
840
|
+
| --- | --- | --- | --- |
|
|
841
|
+
| `class` | `ClassInputType` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
842
|
+
|
|
843
|
+
### `SidebarTriggerDirective`
|
|
844
|
+
|
|
845
|
+
Toggles a sidebar. Can be placed anywhere inside a `mona-sidebar-layout`, including in the inset,
|
|
846
|
+
and adds no styling of its own.
|
|
847
|
+
|
|
848
|
+
By default it drives the sidebar it is written inside. Set `for` to the id of a `mona-sidebar` to
|
|
849
|
+
drive that one instead, which is what a trigger in a shared header needs when the layout holds more
|
|
850
|
+
than one sidebar. A `for` that matches no sidebar leaves the trigger inert rather than throwing, so
|
|
851
|
+
a sidebar that has not rendered yet does not take the page down with it, and warns in development.
|
|
852
|
+
|
|
853
|
+
A `button` is the right host and needs nothing further. On any other element the directive supplies
|
|
854
|
+
the rest of the button contract — `role`, a tab stop, and Enter/Space activation — so a `div`, a
|
|
855
|
+
`span` or an `a` without `href` is still operable by keyboard rather than silently mouse-only.
|
|
856
|
+
|
|
857
|
+
A sidebar that can't collapse has nothing for a trigger to do on a wide viewport, so the trigger
|
|
858
|
+
reports itself as disabled there rather than as an open disclosure.
|
|
859
|
+
|
|
860
|
+
**Selector:** `[monaSidebarTrigger]`
|
|
861
|
+
**Exported as:** `monaSidebarTrigger`
|
|
862
|
+
|
|
863
|
+
#### Inputs
|
|
864
|
+
|
|
865
|
+
| Name | Type | Default | Description |
|
|
866
|
+
| --- | --- | --- | --- |
|
|
867
|
+
| `for` | `string` | `""` | Id of the `mona-sidebar` to toggle. Leave unset to toggle the sidebar this trigger is written inside. |
|
|
868
|
+
|
|
869
|
+
### `SidebarContentDirective`
|
|
870
|
+
|
|
871
|
+
**Selector:** `[monaSidebarContent]`
|
|
872
|
+
|
|
873
|
+
### `SidebarGroupActionDirective`
|
|
874
|
+
|
|
875
|
+
A control in the corner of a group header — an add or overflow button. Stands down on the icon
|
|
876
|
+
rail, where there is no header row left to sit in. Give it an `aria-label`: it is icon-only.
|
|
877
|
+
|
|
878
|
+
**Selector:** `button[monaSidebarGroupAction]`
|
|
879
|
+
|
|
880
|
+
### `SidebarGroupContentDirective`
|
|
881
|
+
|
|
882
|
+
The body of a `monaSidebarGroup`, below its header. Wraps the menu itself.
|
|
883
|
+
|
|
884
|
+
**Selector:** `[monaSidebarGroupContent]`
|
|
885
|
+
|
|
886
|
+
### `SidebarGroupDirective`
|
|
887
|
+
|
|
888
|
+
A titled section of the sidebar, grouping a label and its menu. Stack as many as the sidebar
|
|
889
|
+
needs; each is an ordinary block, so a `monaSidebarSeparator` between them is optional. A
|
|
890
|
+
`monaSidebarGroupLabel` inside it names the group.
|
|
891
|
+
|
|
892
|
+
**Selector:** `[monaSidebarGroup]`
|
|
893
|
+
|
|
894
|
+
### `SidebarGroupHeaderDirective`
|
|
895
|
+
|
|
896
|
+
The row above a group's content, holding its label and any group action. Collapses to nothing on
|
|
897
|
+
the icon rail rather than leaving an empty gap where the label used to be.
|
|
898
|
+
|
|
899
|
+
**Selector:** `[monaSidebarGroupHeader]`
|
|
900
|
+
|
|
901
|
+
### `SidebarGroupLabelDirective`
|
|
902
|
+
|
|
903
|
+
The name of a group, which the enclosing `monaSidebarGroup` is labelled by. Fades out on the icon
|
|
904
|
+
rail, where there is no width to read it in.
|
|
905
|
+
|
|
906
|
+
**Selector:** `[monaSidebarGroupLabel]`
|
|
907
|
+
|
|
908
|
+
### `SidebarInputDirective`
|
|
909
|
+
|
|
910
|
+
A text input sized for the sidebar, composing `monaTextBox`. Stands down on the icon rail,
|
|
911
|
+
where there is no room to type.
|
|
912
|
+
|
|
913
|
+
**Selector:** `input[monaSidebarInput]`
|
|
914
|
+
|
|
915
|
+
### `SidebarMenuActionDirective`
|
|
916
|
+
|
|
917
|
+
A trailing control on a menu item — an overflow menu, a pin. Sits inside the row's highlight and
|
|
918
|
+
stands down on the icon rail. Give it an `aria-label`: it is icon-only.
|
|
919
|
+
|
|
920
|
+
**Selector:** `button[monaSidebarMenuAction]`
|
|
921
|
+
|
|
922
|
+
### `LocalStorageSidebarStorage`
|
|
923
|
+
|
|
924
|
+
The default `SidebarStorage`: `localStorage`, under the sidebar's `persistKey`.
|
|
925
|
+
|
|
926
|
+
Reads report `null` anywhere `localStorage` cannot answer, and writes are dropped there. That
|
|
927
|
+
covers the server, where there is no such thing, and a browser that refuses it — Safari's private
|
|
928
|
+
mode throws on access rather than returning empty, and a full quota throws on write. None of that
|
|
929
|
+
is worth taking an application down over: the sidebar simply opens the way its input says.
|
|
930
|
+
|
|
931
|
+
A server-rendered application gets the default state in its markup and the remembered one on
|
|
932
|
+
hydration, which shows as a flash. Storage that the server can read too — a cookie, or state
|
|
933
|
+
transferred from the request — avoids it; supply it through `provideSidebarStorage()`.
|
|
934
|
+
|
|
935
|
+
#### Methods
|
|
936
|
+
|
|
937
|
+
| Signature |
|
|
938
|
+
| --- |
|
|
939
|
+
| `read(key: string): boolean \| null` |
|
|
940
|
+
| `write(key: string, expanded: boolean): void` |
|
|
941
|
+
|
|
942
|
+
### `injectSidebar`
|
|
943
|
+
|
|
944
|
+
Reads a sidebar from an injection context: the one that encloses the caller, or from elsewhere in a
|
|
945
|
+
`mona-sidebar-layout`, such as a toolbar in the inset, the layout's first sidebar. Name another one with `for`.
|
|
946
|
+
|
|
947
|
+
Returns the sidebar's state and the commands that are safe to issue from anywhere — opening,
|
|
948
|
+
closing and toggling, each routed to whichever presentation is current. Structural facts such as
|
|
949
|
+
the side, variant and collapsible mode are readable but not settable; those are authored as inputs
|
|
950
|
+
on `mona-sidebar`, and writing them from a descendant would only desynchronise the two.
|
|
951
|
+
|
|
952
|
+
In a layout it follows the sidebar rather than holding it, because the caller may be created first. Until there is
|
|
953
|
+
one, it reads as closed and its commands do nothing.
|
|
954
|
+
|
|
955
|
+
```typescript
|
|
956
|
+
function injectSidebar(options: InjectSidebarOptions & { optional: true }): SidebarController | null;
|
|
957
|
+
function injectSidebar(options?: InjectSidebarOptions): SidebarController;
|
|
958
|
+
```
|
|
959
|
+
|
|
960
|
+
### `provideSidebarStorage`
|
|
961
|
+
|
|
962
|
+
Replaces where sidebars remember whether they were left open. The default is `localStorage`, which
|
|
963
|
+
the server cannot read; supply a cookie- or request-backed storage here to have a server-rendered
|
|
964
|
+
application render the remembered state rather than correcting it on hydration.
|
|
965
|
+
|
|
966
|
+
```typescript
|
|
967
|
+
function provideSidebarStorage(storage: SidebarStorage | (() => SidebarStorage)): EnvironmentProviders;
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
### Types
|
|
971
|
+
|
|
972
|
+
#### `SIDEBAR_DEFAULT_MESSAGES`
|
|
973
|
+
|
|
974
|
+
```typescript
|
|
975
|
+
const SIDEBAR_DEFAULT_MESSAGES: MonaSidebarMessages;
|
|
976
|
+
```
|
|
977
|
+
|
|
978
|
+
#### `SIDEBAR_STORAGE`
|
|
979
|
+
|
|
980
|
+
Where sidebars given a `persistKey` remember whether they were left open. Defaults to
|
|
981
|
+
`localStorage`. Replace it with `provideSidebarStorage()` — with something the server can read too,
|
|
982
|
+
for an application that renders there.
|
|
983
|
+
|
|
984
|
+
```typescript
|
|
985
|
+
const SIDEBAR_STORAGE: InjectionToken<SidebarStorage>;
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
#### `SidebarController`
|
|
989
|
+
|
|
990
|
+
The safe, read-and-command view of one sidebar, returned by `injectSidebar()`.
|
|
991
|
+
|
|
992
|
+
Structural facts — side, variant, collapsible mode — are readable but not settable. They are
|
|
993
|
+
authored as inputs on `mona-sidebar`, and letting a descendant write them would leave the service
|
|
994
|
+
and the component disagreeing about the same sidebar, with the component winning on the next
|
|
995
|
+
change detection pass. Consumers who need them to change should bind the inputs.
|
|
996
|
+
|
|
997
|
+
| Name | Type | Description |
|
|
998
|
+
| --- | --- | --- |
|
|
999
|
+
| `collapsible` (read-only) | `Signal<SidebarCollapsibleMode>` | How the sidebar behaves when collapsed, as authored on `mona-sidebar`. |
|
|
1000
|
+
| `compact` (read-only) | `Signal<boolean>` | Whether the viewport is narrow enough that the sidebar presents as an overlay drawer rather than as a column in the layout. |
|
|
1001
|
+
| `expanded` (read-only) | `Signal<boolean>` | Whether the sidebar is showing at full width. On a compact viewport this reports the drawer's state, so a single binding drives both presentations. |
|
|
1002
|
+
| `iconOnly` (read-only) | `Signal<boolean>` | Whether the sidebar is currently reduced to its icon rail, meaning parts that only make sense at full width — labels, trailing actions, submenus — should step aside. Never true while compact, where the drawer always presents at full width. |
|
|
1003
|
+
| `mobileOpen` (read-only) | `Signal<boolean>` | Whether the overlay drawer is open. Only meaningful while `compact` is true. |
|
|
1004
|
+
| `side` (read-only) | `Signal<SidebarLogicalSide>` | Which edge the sidebar sits on, resolved to a direction-relative side. |
|
|
1005
|
+
| `sidebarId` (read-only) | `Signal<string>` | The id of the sidebar element, for `aria-controls` on a custom trigger. |
|
|
1006
|
+
| `state` (read-only) | `Signal<"expanded" \| "collapsed">` | The expanded state as a string, for `data-state` bindings and styling hooks. |
|
|
1007
|
+
| `variant` (read-only) | `Signal<SidebarVariant>` | The visual treatment of the sidebar, as authored on `mona-sidebar`. |
|
|
1008
|
+
|
|
1009
|
+
**Methods**
|
|
1010
|
+
|
|
1011
|
+
| Signature | Description |
|
|
1012
|
+
| --- | --- |
|
|
1013
|
+
| `collapse(): void` | Closes the sidebar. On a compact viewport this closes the drawer instead. |
|
|
1014
|
+
| `expand(): void` | Opens the sidebar. On a compact viewport this opens the drawer instead. |
|
|
1015
|
+
| `toggle(): void` | Flips the sidebar between open and closed, on whichever presentation is current. |
|
|
1016
|
+
|
|
1017
|
+
#### `SidebarStorage`
|
|
1018
|
+
|
|
1019
|
+
Where a sidebar remembers whether it was left open. Supplied through `SIDEBAR_STORAGE`, and only
|
|
1020
|
+
ever consulted for a sidebar that was given a `persistKey`.
|
|
1021
|
+
|
|
1022
|
+
Only the docked state is ever handed to it. A drawer on a compact viewport is deliberately never
|
|
1023
|
+
persisted: restoring one open would cover the page on load, in front of the content the reader
|
|
1024
|
+
asked for.
|
|
1025
|
+
|
|
1026
|
+
**Methods**
|
|
1027
|
+
|
|
1028
|
+
| Signature | Description |
|
|
1029
|
+
| --- | --- |
|
|
1030
|
+
| `read(key: string): boolean \| null` | The remembered state for `key`, or `null` when nothing has been stored under it — including when this storage cannot answer, such as on the server. A `null` leaves the sidebar on whatever its `expanded` input says. |
|
|
1031
|
+
| `write(key: string, expanded: boolean): void` | Records the docked state for `key`. Failing to store it must not throw. |
|
|
1032
|
+
|
|
1033
|
+
#### `InjectSidebarOptions`
|
|
1034
|
+
|
|
1035
|
+
| Name | Type | Description |
|
|
1036
|
+
| --- | --- | --- |
|
|
1037
|
+
| `for?` (read-only) | `string` | Reads the sidebar with this id in the enclosing layout, rather than the nearest one. Needs a layout. |
|
|
1038
|
+
| `optional?` (read-only) | `boolean` | Returns `null` instead of throwing when there is no enclosing sidebar or layout. |
|
|
1039
|
+
|
|
1040
|
+
#### `SidebarCollapsibleMode`
|
|
1041
|
+
|
|
1042
|
+
How the sidebar behaves when it is collapsed.
|
|
1043
|
+
|
|
1044
|
+
- `offcanvas` — the sidebar collapses to zero width and leaves the layout.
|
|
1045
|
+
- `icon` — the sidebar shrinks to a narrow rail that keeps icons visible.
|
|
1046
|
+
- `none` — the sidebar cannot be collapsed and stays at its full width.
|
|
1047
|
+
|
|
1048
|
+
```typescript
|
|
1049
|
+
type SidebarCollapsibleMode = "offcanvas" | "icon" | "none";
|
|
1050
|
+
```
|
|
1051
|
+
|
|
1052
|
+
#### `SidebarLogicalSide`
|
|
1053
|
+
|
|
1054
|
+
The direction-relative side, once the `left`/`right` aliases have been folded in.
|
|
1055
|
+
|
|
1056
|
+
```typescript
|
|
1057
|
+
type SidebarLogicalSide = "start" | "end";
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
#### `SidebarMenuButtonSize`
|
|
1061
|
+
|
|
1062
|
+
How much room the button's leading visual needs.
|
|
1063
|
+
|
|
1064
|
+
- `medium` — sized for an icon, which the icon rail insets so it sits centred in the square.
|
|
1065
|
+
- `large` — sized for a full-height visual such as an avatar, which fills the rail square edge to
|
|
1066
|
+
edge, and which is given a taller row while the sidebar is expanded.
|
|
1067
|
+
|
|
1068
|
+
```typescript
|
|
1069
|
+
type SidebarMenuButtonSize = "medium" | "large";
|
|
1070
|
+
```
|
|
1071
|
+
|
|
1072
|
+
#### `SidebarModalScope`
|
|
1073
|
+
|
|
1074
|
+
How far an open drawer's modality reaches.
|
|
1075
|
+
- `"page"` makes everything outside the drawer inert and locks the page's scroll, and the drawer is `aria-modal`.
|
|
1076
|
+
- `"layout"` does that within `mona-sidebar-layout` only, for a sidebar embedded in part of a page. What's around the
|
|
1077
|
+
layout stays usable, so the drawer isn't `aria-modal`.
|
|
1078
|
+
|
|
1079
|
+
```typescript
|
|
1080
|
+
type SidebarModalScope = "page" | "layout";
|
|
1081
|
+
```
|
|
1082
|
+
|
|
1083
|
+
#### `SidebarSide`
|
|
1084
|
+
|
|
1085
|
+
Which edge of the layout the sidebar sits on. Also determines its order within the layout
|
|
1086
|
+
and which side its rail and border are drawn on.
|
|
1087
|
+
|
|
1088
|
+
`start` and `end` are the preferred values: they follow the document's writing direction, so a
|
|
1089
|
+
`start` sidebar sits on the left in LTR and on the right in RTL without the consumer branching.
|
|
1090
|
+
|
|
1091
|
+
`left` and `right` are retained as aliases of `start` and `end`. They were always a poor
|
|
1092
|
+
description of the behaviour — the layout orders the sidebar with flexbox, which is
|
|
1093
|
+
direction-relative, so `side="left"` already rendered on the right under RTL.
|
|
1094
|
+
|
|
1095
|
+
```typescript
|
|
1096
|
+
type SidebarSide = "start" | "end" | "left" | "right";
|
|
1097
|
+
```
|
|
1098
|
+
|
|
1099
|
+
#### `SidebarVariant`
|
|
1100
|
+
|
|
1101
|
+
The visual treatment of the sidebar region.
|
|
1102
|
+
|
|
1103
|
+
- `sidebar` — flush against the edge of the layout, separated by a single border.
|
|
1104
|
+
- `floating` — detached from the edge, with its own rounded, bordered surface.
|
|
1105
|
+
- `inset` — the sidebar itself is plain, and the inset region beside it becomes the raised surface.
|
|
1106
|
+
|
|
1107
|
+
```typescript
|
|
1108
|
+
type SidebarVariant = "sidebar" | "floating" | "inset";
|
|
1109
|
+
```
|
|
1110
|
+
|
|
1111
|
+
#### `ClassInputType`
|
|
1112
|
+
|
|
1113
|
+
From `@nanahoshi/mona-ui/common`.
|
|
1114
|
+
|
|
1115
|
+
```typescript
|
|
1116
|
+
type ClassInputType = string | string[] | Record<string, unknown> | null | undefined;
|
|
1117
|
+
```
|
|
1118
|
+
|
|
1119
|
+
#### `MonaSidebarMessages`
|
|
1120
|
+
|
|
1121
|
+
From `@nanahoshi/mona-ui/i18n`.
|
|
1122
|
+
|
|
1123
|
+
| Name | Type |
|
|
1124
|
+
| --- | --- |
|
|
1125
|
+
| `drawerLabel` (read-only) | `string` |
|
|
1126
|
+
| `rail` (read-only) | `string` |
|