@nanahoshi/mona-ui 0.25.1 → 0.26.1
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/chart/README.md +2 -2
- 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-bar.md +714 -0
- package/docs/chart-financial.md +567 -0
- package/docs/chart-funnel.md +546 -0
- package/docs/chart-heatmap.md +535 -0
- package/docs/chart-line-area.md +462 -0
- package/docs/chart-pie.md +645 -0
- package/docs/chart-radar.md +518 -0
- package/docs/chart-radial.md +658 -0
- package/docs/chart-scatter.md +479 -0
- package/docs/chart-treemap.md +651 -0
- package/docs/chart.md +2465 -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 +212 -66
- 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 +133 -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 +250 -20
- 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/switch.md
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
# Switch
|
|
2
|
+
|
|
3
|
+
> A binary on and off toggle with optional state labels.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/switch`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-switch`
|
|
8
|
+
|
|
9
|
+
`SwitchComponent` renders a binary on/off toggle switch with optional state labels, a customizable sliding handle, and signal forms integration via `FormCheckboxControl`.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
`SwitchComponent` represents a binary setting that takes immediate effect when toggled. Use it when the action is immediate and the on/off metaphor communicates the intent clearly — for example, enabling a notification preference or activating dark mode.
|
|
14
|
+
|
|
15
|
+
**Use Switch instead of Checkbox when:**
|
|
16
|
+
|
|
17
|
+
- The change takes effect immediately without a form submission step
|
|
18
|
+
- The on/off states benefit from distinct visible labels or icons inside the track
|
|
19
|
+
- A sliding handle conveys the toggle metaphor better than a checkmark
|
|
20
|
+
|
|
21
|
+
**Use Checkbox instead when:**
|
|
22
|
+
|
|
23
|
+
- The control is part of a form the user submits explicitly
|
|
24
|
+
- Multiple boolean options are listed together
|
|
25
|
+
- An indeterminate "select all" state is needed
|
|
26
|
+
|
|
27
|
+
## Import & Quick Start
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { SwitchComponent } from "@nanahoshi/mona-ui/switch";
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Direct binding:**
|
|
34
|
+
|
|
35
|
+
```html
|
|
36
|
+
<mona-switch [(checked)]="enabled" aria-label="Enable notifications"></mona-switch>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Examples
|
|
40
|
+
|
|
41
|
+
### Labels in the track
|
|
42
|
+
|
|
43
|
+
`onLabel` and `offLabel` display text inside the switch track on the respective sides of the handle. They don't name the switch, so it still needs a label.
|
|
44
|
+
|
|
45
|
+
`labels-example.component.ts`
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { Component, signal } from "@angular/core";
|
|
49
|
+
import { LabelComponent } from "@nanahoshi/mona-ui/label";
|
|
50
|
+
import { SwitchComponent } from "@nanahoshi/mona-ui/switch";
|
|
51
|
+
|
|
52
|
+
@Component({
|
|
53
|
+
selector: "app-switch-labels-example",
|
|
54
|
+
imports: [LabelComponent, SwitchComponent],
|
|
55
|
+
templateUrl: "./labels-example.component.html"
|
|
56
|
+
})
|
|
57
|
+
export class SwitchLabelsExampleComponent {
|
|
58
|
+
protected readonly bluetooth = signal(false);
|
|
59
|
+
protected readonly wifi = signal(true);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`labels-example.component.html`
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<div class="flex flex-col items-start gap-3">
|
|
67
|
+
<mona-label text="Wi-Fi">
|
|
68
|
+
<mona-switch offLabel="Off" onLabel="On" [(checked)]="wifi" />
|
|
69
|
+
</mona-label>
|
|
70
|
+
<mona-label text="Bluetooth">
|
|
71
|
+
<mona-switch offLabel="Off" onLabel="On" size="large" [(checked)]="bluetooth" />
|
|
72
|
+
</mona-label>
|
|
73
|
+
<p class="text-sm">Wi-Fi is {{ wifi() ? "on" : "off" }}, Bluetooth is {{ bluetooth() ? "on" : "off" }}.</p>
|
|
74
|
+
</div>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Icons
|
|
78
|
+
|
|
79
|
+
Replace the text with any markup using the `monaSwitchOnLabelTemplate` and `monaSwitchOffLabelTemplate` structural directives. When both a string input and a template are provided, the template takes precedence.
|
|
80
|
+
|
|
81
|
+
Use `monaSwitchHandleContentTemplate` to put content in the handle. Its context holds the checked state as the implicit variable.
|
|
82
|
+
|
|
83
|
+
`icons-example.component.ts`
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { Component, signal } from "@angular/core";
|
|
87
|
+
import { LucideMoon, LucideSun, LucideVolume2, LucideVolumeX } from "@lucide/angular";
|
|
88
|
+
import { LabelComponent } from "@nanahoshi/mona-ui/label";
|
|
89
|
+
import {
|
|
90
|
+
SwitchComponent,
|
|
91
|
+
SwitchHandleContentTemplateDirective,
|
|
92
|
+
SwitchOffLabelTemplateDirective,
|
|
93
|
+
SwitchOnLabelTemplateDirective
|
|
94
|
+
} from "@nanahoshi/mona-ui/switch";
|
|
95
|
+
|
|
96
|
+
@Component({
|
|
97
|
+
selector: "app-switch-icons-example",
|
|
98
|
+
imports: [
|
|
99
|
+
LabelComponent,
|
|
100
|
+
LucideMoon,
|
|
101
|
+
LucideSun,
|
|
102
|
+
LucideVolume2,
|
|
103
|
+
LucideVolumeX,
|
|
104
|
+
SwitchComponent,
|
|
105
|
+
SwitchHandleContentTemplateDirective,
|
|
106
|
+
SwitchOffLabelTemplateDirective,
|
|
107
|
+
SwitchOnLabelTemplateDirective
|
|
108
|
+
],
|
|
109
|
+
templateUrl: "./icons-example.component.html"
|
|
110
|
+
})
|
|
111
|
+
export class SwitchIconsExampleComponent {
|
|
112
|
+
protected readonly darkMode = signal(false);
|
|
113
|
+
protected readonly sound = signal(true);
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`icons-example.component.html`
|
|
118
|
+
|
|
119
|
+
```html
|
|
120
|
+
<div class="flex flex-col items-start gap-3">
|
|
121
|
+
<mona-label text="Dark mode">
|
|
122
|
+
<mona-switch [(checked)]="darkMode">
|
|
123
|
+
<ng-template monaSwitchOnLabelTemplate>
|
|
124
|
+
<svg lucideMoon aria-hidden="true" [size]="14"></svg>
|
|
125
|
+
</ng-template>
|
|
126
|
+
<ng-template monaSwitchOffLabelTemplate>
|
|
127
|
+
<svg lucideSun aria-hidden="true" [size]="14"></svg>
|
|
128
|
+
</ng-template>
|
|
129
|
+
</mona-switch>
|
|
130
|
+
</mona-label>
|
|
131
|
+
<mona-label text="Sound">
|
|
132
|
+
<mona-switch [(checked)]="sound">
|
|
133
|
+
<ng-template let-on monaSwitchHandleContentTemplate>
|
|
134
|
+
@if (on) {
|
|
135
|
+
<svg lucideVolume2 aria-hidden="true" [size]="12"></svg>
|
|
136
|
+
} @else {
|
|
137
|
+
<svg lucideVolumeX aria-hidden="true" [size]="12"></svg>
|
|
138
|
+
}
|
|
139
|
+
</ng-template>
|
|
140
|
+
</mona-switch>
|
|
141
|
+
</mona-label>
|
|
142
|
+
</div>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Signal forms
|
|
146
|
+
|
|
147
|
+
`forms-example.component.ts`
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { Component, signal } from "@angular/core";
|
|
151
|
+
import { disabled, form, FormField } from "@angular/forms/signals";
|
|
152
|
+
import { LabelComponent } from "@nanahoshi/mona-ui/label";
|
|
153
|
+
import { SwitchComponent } from "@nanahoshi/mona-ui/switch";
|
|
154
|
+
|
|
155
|
+
@Component({
|
|
156
|
+
selector: "app-switch-forms-example",
|
|
157
|
+
imports: [FormField, LabelComponent, SwitchComponent],
|
|
158
|
+
templateUrl: "./forms-example.component.html"
|
|
159
|
+
})
|
|
160
|
+
export class SwitchFormsExampleComponent {
|
|
161
|
+
readonly #model = signal({ digest: false, emails: true });
|
|
162
|
+
protected readonly settings = form(this.#model, path => {
|
|
163
|
+
disabled(path.digest, ({ valueOf }) => !valueOf(path.emails));
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`forms-example.component.html`
|
|
169
|
+
|
|
170
|
+
```html
|
|
171
|
+
<div class="flex flex-col items-start gap-3">
|
|
172
|
+
<mona-label text="Email notifications">
|
|
173
|
+
<mona-switch [formField]="settings.emails" />
|
|
174
|
+
</mona-label>
|
|
175
|
+
<mona-label text="Weekly digest">
|
|
176
|
+
<mona-switch [formField]="settings.digest" />
|
|
177
|
+
</mona-label>
|
|
178
|
+
<p class="text-sm">
|
|
179
|
+
Emails: {{ settings.emails().value() ? "on" : "off" }}, digest: {{ settings.digest().value() ? "on" : "off" }}
|
|
180
|
+
</p>
|
|
181
|
+
</div>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The signal forms `disabled` rule disables the digest switch while email notifications are off.
|
|
185
|
+
|
|
186
|
+
## Appearance & Styling
|
|
187
|
+
|
|
188
|
+
### Size presets
|
|
189
|
+
|
|
190
|
+
| `size` | Description |
|
|
191
|
+
|----------|-------------------------------|
|
|
192
|
+
| `small` | Compact track and handle |
|
|
193
|
+
| `medium` | Standard size (default) |
|
|
194
|
+
| `large` | Wider track and taller handle |
|
|
195
|
+
|
|
196
|
+
### Rounded presets
|
|
197
|
+
|
|
198
|
+
| `rounded` | Shape |
|
|
199
|
+
|-----------|-------------------------------------|
|
|
200
|
+
| `none` | No rounding |
|
|
201
|
+
| `small` | Slight rounding |
|
|
202
|
+
| `medium` | Moderate rounding |
|
|
203
|
+
| `large` | Strong rounding |
|
|
204
|
+
| `full` | Fully rounded, pill shape (default) |
|
|
205
|
+
|
|
206
|
+
### Visual states
|
|
207
|
+
|
|
208
|
+
| State | Appearance |
|
|
209
|
+
|-----------------|---------------------------------------------------------------------------|
|
|
210
|
+
| Off | Track uses the theme's input background and border |
|
|
211
|
+
| On (checked) | Track fills with the primary color |
|
|
212
|
+
| Focused | Visible focus indicator |
|
|
213
|
+
| Disabled | Disabled colors, no pointer interaction |
|
|
214
|
+
| Read-only | Default cursor, otherwise unchanged |
|
|
215
|
+
| Invalid (forms) | Error color once touched, when `invalid` is `true` or a `required` switch is off |
|
|
216
|
+
|
|
217
|
+
### Custom classes
|
|
218
|
+
|
|
219
|
+
Pass additional CSS classes via the `class` attribute. They are merged onto the host element via `tailwind-merge`:
|
|
220
|
+
|
|
221
|
+
```html
|
|
222
|
+
<mona-switch [(checked)]="enabled" class="my-2" aria-label="Enable feature"></mona-switch>
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Behavior
|
|
226
|
+
|
|
227
|
+
### Read-only
|
|
228
|
+
|
|
229
|
+
`readonly` blocks toggling by pointer, keyboard and label, while the switch stays focusable and readable. It sets `aria-readonly="true"`. With `[formField]`, the signal forms `readonly` rule writes it.
|
|
230
|
+
|
|
231
|
+
## Forms Integration
|
|
232
|
+
|
|
233
|
+
`SwitchComponent` implements `FormCheckboxControl` from `@angular/forms/signals`. Connect it to a signal form field using the `[formField]` binding provided by the signal forms `FormField` directive, as in the signal forms example.
|
|
234
|
+
|
|
235
|
+
`FormField` writes `checked`, `disabled`, `invalid`, `readonly`, `required` and `touched`. Don't set those on the same element, because Angular rejects the template. The `touch` output fires when the switch is toggled or loses focus, marking the field as touched. The signal forms `required` rule treats a switch that's off as empty.
|
|
236
|
+
|
|
237
|
+
The switch has no `name` input, because it has no native input.
|
|
238
|
+
|
|
239
|
+
`SwitchComponent` doesn't implement `ControlValueAccessor`. `[(ngModel)]` binds to its `checked` model through Angular's support for custom controls, the same way it does for `CheckBoxComponent`. Import `FormsModule` for it.
|
|
240
|
+
|
|
241
|
+
## Accessibility
|
|
242
|
+
|
|
243
|
+
`SwitchComponent` manages the following on its host element:
|
|
244
|
+
|
|
245
|
+
| Attribute | When present | Value |
|
|
246
|
+
|-------------------|----------------------------|---------------------------------------------|
|
|
247
|
+
| `role` | Always | `"switch"` |
|
|
248
|
+
| `aria-checked` | Always | `true` or `false` |
|
|
249
|
+
| `aria-disabled` | When disabled | `true` |
|
|
250
|
+
| `aria-invalid` | When the invalid state shows | `true` |
|
|
251
|
+
| `aria-readonly` | When read-only | `true` |
|
|
252
|
+
| `aria-required` | When required | `true` |
|
|
253
|
+
| `tabindex` | Always | The `tabindex` input, or `-1` when disabled |
|
|
254
|
+
|
|
255
|
+
**Consumer responsibilities:**
|
|
256
|
+
|
|
257
|
+
The switch has no visible text label of its own. You must provide an accessible name using one of:
|
|
258
|
+
|
|
259
|
+
- `aria-label` input: `<mona-switch aria-label="Enable dark mode">`
|
|
260
|
+
- `aria-labelledby` input: reference an existing element by ID: `<mona-switch aria-labelledby="setting-label-id">`
|
|
261
|
+
- A `mona-label` with `text` wrapped around it. A click on the caption toggles the switch.
|
|
262
|
+
- A `mona-label` or `label[monaLabel]` bound to it with `[for]="ref"`. A string `for` can't work, because the switch has no native input.
|
|
263
|
+
|
|
264
|
+
The `onLabel` and `offLabel` inputs display text *inside the track* — they do not serve as the accessible name for the switch element.
|
|
265
|
+
|
|
266
|
+
**Keyboard interaction:**
|
|
267
|
+
|
|
268
|
+
| Key | Action |
|
|
269
|
+
|---------|---------------------------|
|
|
270
|
+
| `Space` | Toggles the switch on/off |
|
|
271
|
+
| `Enter` | Toggles the switch on/off |
|
|
272
|
+
|
|
273
|
+
`Space` also suppresses the default browser page-scroll behavior.
|
|
274
|
+
|
|
275
|
+
## API
|
|
276
|
+
|
|
277
|
+
Everything below is imported from `@nanahoshi/mona-ui/switch`.
|
|
278
|
+
|
|
279
|
+
### `SwitchComponent`
|
|
280
|
+
|
|
281
|
+
**Selector:** `mona-switch`
|
|
282
|
+
**Implements:** `FormCheckboxControl`
|
|
283
|
+
|
|
284
|
+
#### Inputs
|
|
285
|
+
|
|
286
|
+
| Name | Type | Default | Description |
|
|
287
|
+
| --- | --- | --- | --- |
|
|
288
|
+
| `aria-label` | `string \| null` | `null` | Accessible name for the host element. Describe what the component represents. When empty, assistive technology announces the role without a label. |
|
|
289
|
+
| `aria-labelledby` | `string \| null` | `null` | ID of an external element that provides the accessible name for the host element. |
|
|
290
|
+
| `checked` (two-way) | `boolean` | `false` | Whether the control is checked. |
|
|
291
|
+
| `class` | `string` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
292
|
+
| `disabled` | `boolean` | `false` | Renders the component with reduced visual emphasis and removes pointer interaction. |
|
|
293
|
+
| `invalid` | `boolean` | `false` | Marks the switch as invalid. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
294
|
+
| `offLabel` | `string` | `""` | Label displayed inside the switch track when it is in the off state. |
|
|
295
|
+
| `onLabel` | `string` | `""` | Label displayed inside the switch track when it is in the on state. |
|
|
296
|
+
| `readonly` | `boolean` | `false` | Prevents value changes while the control stays focusable and readable. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
297
|
+
| `required` | `boolean` | `false` | Marks the switch as required for form validation. |
|
|
298
|
+
| `rounded` | `"full" \| "large" \| "medium" \| "none" \| "small"` | `"full"` | Border-radius preset applied to the component. |
|
|
299
|
+
| `size` | `"large" \| "medium" \| "small"` | `"medium"` | Size preset controlling the component's dimensions. |
|
|
300
|
+
| `tabindex` | `string \| number` | `0` | Tab index of the switch while it's enabled. |
|
|
301
|
+
| `touched` | `boolean` | `false` | Marks the switch as touched. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
302
|
+
|
|
303
|
+
#### Outputs
|
|
304
|
+
|
|
305
|
+
| Name | Type | Description |
|
|
306
|
+
| --- | --- | --- |
|
|
307
|
+
| `checkedChange` | `boolean` | Emitted when `checked` changes. |
|
|
308
|
+
| `touch` | `void` | Emitted when the switch loses focus or its value changes. |
|
|
309
|
+
|
|
310
|
+
#### Methods
|
|
311
|
+
|
|
312
|
+
| Signature | Description |
|
|
313
|
+
| --- | --- |
|
|
314
|
+
| `focus(options?: FocusOptions): void` | Moves focus to the switch. |
|
|
315
|
+
|
|
316
|
+
### `SwitchHandleContentTemplateDirective`
|
|
317
|
+
|
|
318
|
+
**Selector:** `ng-template[monaSwitchHandleContentTemplate]`
|
|
319
|
+
|
|
320
|
+
#### Template context
|
|
321
|
+
|
|
322
|
+
| Name | Type |
|
|
323
|
+
| --- | --- |
|
|
324
|
+
| `$implicit` | `boolean` |
|
|
325
|
+
|
|
326
|
+
### `SwitchOffLabelTemplateDirective`
|
|
327
|
+
|
|
328
|
+
**Selector:** `ng-template[monaSwitchOffLabelTemplate]`
|
|
329
|
+
|
|
330
|
+
### `SwitchOnLabelTemplateDirective`
|
|
331
|
+
|
|
332
|
+
**Selector:** `ng-template[monaSwitchOnLabelTemplate]`
|
|
333
|
+
|
|
334
|
+
### Types
|
|
335
|
+
|
|
336
|
+
#### `SwitchHandleContentTemplateContext`
|
|
337
|
+
|
|
338
|
+
| Name | Type |
|
|
339
|
+
| --- | --- |
|
|
340
|
+
| `$implicit` (read-only) | `boolean` |
|