@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/checkbox.md
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
# Checkbox
|
|
2
|
+
|
|
3
|
+
> A checkbox with label handling and an indeterminate state.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/check-box`
|
|
6
|
+
|
|
7
|
+
**Selectors:** `mona-check-box` · `input[type='checkbox'][monaCheckbox]`
|
|
8
|
+
|
|
9
|
+
`CheckBoxComponent` renders a custom-styled checkbox with label management, indeterminate state, and signal forms support. `CheckboxDirective` applies the same visual style to a native `<input type="checkbox">` when full layout control is required.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Mona UI provides two ways to render a styled checkbox:
|
|
14
|
+
|
|
15
|
+
**`CheckBoxComponent` (`mona-check-box`)** is a self-contained component. It wraps a visually hidden native `<input type="checkbox">` (accessible to screen readers) and a visible custom box that tracks focus and checked state via CSS peer selectors. It implements `FormCheckboxControl` from `@angular/forms/signals` and supports an optional text label or projected content.
|
|
16
|
+
|
|
17
|
+
**`CheckboxDirective` (`monaCheckbox`)** is an attribute directive applied directly to your own `<input type="checkbox">`. It adds Mona UI styling while keeping the native element as the form control. Because it targets a native input, Angular's built-in form directives (`[(ngModel)]`, `[formControl]`, `formControlName`) work on it without any additional wiring.
|
|
18
|
+
|
|
19
|
+
**Choose `CheckBoxComponent` when:**
|
|
20
|
+
|
|
21
|
+
- You want a ready-made label + checkbox layout without writing wrapper markup
|
|
22
|
+
- You need indeterminate state, read-only state, label positioning, or label size variants
|
|
23
|
+
- You are using signal forms via the `[formField]` binding
|
|
24
|
+
|
|
25
|
+
**Choose `CheckboxDirective` when:**
|
|
26
|
+
|
|
27
|
+
- You need full control over the surrounding markup — your own `<label>`, positioning
|
|
28
|
+
- You want to use `[formControl]` or `formControlName` (Angular's standard forms work on the native input directly)
|
|
29
|
+
- You want native browser checkbox behavior with Mona UI styling
|
|
30
|
+
|
|
31
|
+
## Import & Quick Start
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { CheckBoxComponent } from "@nanahoshi/mona-ui/check-box"; // component
|
|
35
|
+
import { CheckboxDirective } from "@nanahoshi/mona-ui/check-box"; // directive
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Add the imported symbols to your standalone component's `imports` array.
|
|
39
|
+
|
|
40
|
+
### The component
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<mona-check-box label="Accept terms"></mona-check-box>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**`ngModel`:**
|
|
47
|
+
|
|
48
|
+
`CheckBoxComponent` doesn't implement `ControlValueAccessor`. `[(ngModel)]` still works, because Angular binds it to the `checked` model of a custom control. Import `FormsModule` for it.
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
|
|
52
|
+
<mona-check-box label="Accept terms" [(ngModel)]="accepted"></mona-check-box>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
> **Listening to changes:** Use `(inputChange)` for raw DOM `change` events. For signal forms, the `[formField]` binding handles value synchronization automatically.
|
|
56
|
+
|
|
57
|
+
## Examples
|
|
58
|
+
|
|
59
|
+
### Labels
|
|
60
|
+
|
|
61
|
+
The text comes from `label` or from projected content. When `label` is non-empty it takes precedence over projected content. `labelPosition="before"` puts the text before the box.
|
|
62
|
+
|
|
63
|
+
`labels-example.component.ts`
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { Component, signal } from "@angular/core";
|
|
67
|
+
import { CheckBoxComponent } from "@nanahoshi/mona-ui/check-box";
|
|
68
|
+
|
|
69
|
+
@Component({
|
|
70
|
+
selector: "app-checkbox-labels-example",
|
|
71
|
+
imports: [CheckBoxComponent],
|
|
72
|
+
templateUrl: "./labels-example.component.html"
|
|
73
|
+
})
|
|
74
|
+
export class CheckboxLabelsExampleComponent {
|
|
75
|
+
protected readonly releases = signal(true);
|
|
76
|
+
protected readonly signedIn = signal(false);
|
|
77
|
+
protected readonly terms = signal(false);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`labels-example.component.html`
|
|
82
|
+
|
|
83
|
+
```html
|
|
84
|
+
<div class="flex flex-col items-start gap-3">
|
|
85
|
+
<mona-check-box label="Email me about new releases" [(checked)]="releases" />
|
|
86
|
+
<mona-check-box label="Keep me signed in" labelPosition="before" [(checked)]="signedIn" />
|
|
87
|
+
<mona-check-box [(checked)]="terms">
|
|
88
|
+
I accept the <strong>terms of service</strong>
|
|
89
|
+
</mona-check-box>
|
|
90
|
+
<mona-check-box label="Sync contacts" [disabled]="true" />
|
|
91
|
+
<p class="text-sm">Terms accepted: {{ terms() ? "yes" : "no" }}</p>
|
|
92
|
+
</div>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Select all
|
|
96
|
+
|
|
97
|
+
`indeterminate` shows a dash and sets `aria-checked="mixed"`. It's independent of `checked`.
|
|
98
|
+
|
|
99
|
+
`indeterminate-example.component.ts`
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { Component, computed, signal } from "@angular/core";
|
|
103
|
+
import { CheckBoxComponent } from "@nanahoshi/mona-ui/check-box";
|
|
104
|
+
|
|
105
|
+
interface Topping {
|
|
106
|
+
readonly name: string;
|
|
107
|
+
readonly selected: boolean;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@Component({
|
|
111
|
+
selector: "app-checkbox-indeterminate-example",
|
|
112
|
+
imports: [CheckBoxComponent],
|
|
113
|
+
templateUrl: "./indeterminate-example.component.html"
|
|
114
|
+
})
|
|
115
|
+
export class CheckboxIndeterminateExampleComponent {
|
|
116
|
+
protected readonly allSelected = computed(() => this.toppings().every(topping => topping.selected));
|
|
117
|
+
protected readonly someSelected = computed(
|
|
118
|
+
() => !this.allSelected() && this.toppings().some(topping => topping.selected)
|
|
119
|
+
);
|
|
120
|
+
protected readonly toppings = signal<readonly Topping[]>([
|
|
121
|
+
{ name: "Cheese", selected: true },
|
|
122
|
+
{ name: "Mushrooms", selected: false },
|
|
123
|
+
{ name: "Olives", selected: false }
|
|
124
|
+
]);
|
|
125
|
+
|
|
126
|
+
protected select(name: string, selected: boolean): void {
|
|
127
|
+
this.toppings.update(toppings =>
|
|
128
|
+
toppings.map(topping => (topping.name === name ? { ...topping, selected } : topping))
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
protected selectAll(selected: boolean): void {
|
|
133
|
+
this.toppings.update(toppings => toppings.map(topping => ({ ...topping, selected })));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`indeterminate-example.component.html`
|
|
139
|
+
|
|
140
|
+
```html
|
|
141
|
+
<div class="flex flex-col items-start gap-2">
|
|
142
|
+
<mona-check-box
|
|
143
|
+
label="All toppings"
|
|
144
|
+
[checked]="allSelected()"
|
|
145
|
+
[indeterminate]="someSelected()"
|
|
146
|
+
(checkedChange)="selectAll($event)" />
|
|
147
|
+
<div class="ms-6 flex flex-col items-start gap-2">
|
|
148
|
+
@for (topping of toppings(); track topping.name) {
|
|
149
|
+
<mona-check-box
|
|
150
|
+
[checked]="topping.selected"
|
|
151
|
+
[label]="topping.name"
|
|
152
|
+
(checkedChange)="select(topping.name, $event)" />
|
|
153
|
+
}
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
A user change clears it and then toggles `checked`, as on a native checkbox, and `indeterminateChange` emits `false`. A one-way `[indeterminate]` binding only writes again when its bound value changes: if it stays `true` after a click, the dash stays gone. Use `[(indeterminate)]`, or recompute the bound value after each change, as this example does.
|
|
159
|
+
|
|
160
|
+
### Signal forms
|
|
161
|
+
|
|
162
|
+
`CheckBoxComponent` implements `FormCheckboxControl` from `@angular/forms/signals`, so it takes `[formField]`. `FormField` writes `checked`, `disabled`, `invalid`, `name`, `readonly`, `required` and `touched`. Don't set those on the same element, because Angular rejects the template. The signal forms `required` rule treats an unchecked box as empty.
|
|
163
|
+
|
|
164
|
+
`forms-example.component.ts`
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
import { Component, signal } from "@angular/core";
|
|
168
|
+
import { form, FormField, required } from "@angular/forms/signals";
|
|
169
|
+
import { CheckBoxComponent } from "@nanahoshi/mona-ui/check-box";
|
|
170
|
+
|
|
171
|
+
@Component({
|
|
172
|
+
selector: "app-checkbox-forms-example",
|
|
173
|
+
imports: [CheckBoxComponent, FormField],
|
|
174
|
+
templateUrl: "./forms-example.component.html"
|
|
175
|
+
})
|
|
176
|
+
export class CheckboxFormsExampleComponent {
|
|
177
|
+
readonly #model = signal({ newsletter: false, terms: false });
|
|
178
|
+
protected readonly signup = form(this.#model, path => {
|
|
179
|
+
required(path.terms, { message: "Accept the terms to continue." });
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
`forms-example.component.html`
|
|
185
|
+
|
|
186
|
+
```html
|
|
187
|
+
<div class="flex flex-col items-start gap-3">
|
|
188
|
+
<mona-check-box label="Send me the monthly newsletter" [formField]="signup.newsletter" />
|
|
189
|
+
<mona-check-box
|
|
190
|
+
aria-describedby="checkbox-terms-error"
|
|
191
|
+
label="I accept the terms of service"
|
|
192
|
+
[formField]="signup.terms" />
|
|
193
|
+
<p aria-live="polite" class="text-sm text-error" id="checkbox-terms-error">
|
|
194
|
+
@if (signup.terms().touched()) {
|
|
195
|
+
@for (error of signup.terms().errors(); track error.kind) {
|
|
196
|
+
{{ error.message }}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
</p>
|
|
200
|
+
<p class="text-sm">Form valid: {{ signup().valid() ? "yes" : "no" }}</p>
|
|
201
|
+
</div>
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### The directive
|
|
205
|
+
|
|
206
|
+
The directive leaves all label composition and form wiring to the consumer. The native `<input>` retains its standard keyboard behavior, form submission semantics, and Angular forms support.
|
|
207
|
+
|
|
208
|
+
`directive-example.component.ts`
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
import { Component, signal } from "@angular/core";
|
|
212
|
+
import { CheckboxDirective } from "@nanahoshi/mona-ui/check-box";
|
|
213
|
+
|
|
214
|
+
@Component({
|
|
215
|
+
selector: "app-checkbox-directive-example",
|
|
216
|
+
imports: [CheckboxDirective],
|
|
217
|
+
templateUrl: "./directive-example.component.html"
|
|
218
|
+
})
|
|
219
|
+
export class CheckboxDirectiveExampleComponent {
|
|
220
|
+
protected readonly chosen = signal<readonly string[]>(["Comments"]);
|
|
221
|
+
protected readonly topics = ["Comments", "Mentions", "New followers"];
|
|
222
|
+
|
|
223
|
+
protected toggle(topic: string, event: Event): void {
|
|
224
|
+
const { checked } = event.target as HTMLInputElement;
|
|
225
|
+
this.chosen.update(chosen => (checked ? [...chosen, topic] : chosen.filter(item => item !== topic)));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
`directive-example.component.html`
|
|
231
|
+
|
|
232
|
+
```html
|
|
233
|
+
<fieldset class="flex flex-col gap-2">
|
|
234
|
+
<legend class="mb-1 text-sm font-medium">Notify me about</legend>
|
|
235
|
+
@for (topic of topics; track topic) {
|
|
236
|
+
<label class="flex items-center gap-2 text-sm">
|
|
237
|
+
<input monaCheckbox type="checkbox" [checked]="chosen().includes(topic)" (change)="toggle(topic, $event)" />
|
|
238
|
+
{{ topic }}
|
|
239
|
+
</label>
|
|
240
|
+
}
|
|
241
|
+
</fieldset>
|
|
242
|
+
<p class="mt-3 text-sm">Notifying about: {{ chosen().join(", ") || "nothing" }}</p>
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Appearance & Styling
|
|
246
|
+
|
|
247
|
+
### Rounded presets
|
|
248
|
+
|
|
249
|
+
Both `CheckBoxComponent` and `CheckboxDirective` accept the same `rounded` input:
|
|
250
|
+
|
|
251
|
+
| `rounded` | Shape |
|
|
252
|
+
|-----------|-----------------------------|
|
|
253
|
+
| `none` | No rounding |
|
|
254
|
+
| `small` | Slight rounding |
|
|
255
|
+
| `medium` | Moderate rounding (default) |
|
|
256
|
+
| `large` | Strong rounding |
|
|
257
|
+
| `full` | Pill / fully rounded |
|
|
258
|
+
|
|
259
|
+
### Visual states
|
|
260
|
+
|
|
261
|
+
| State | Appearance |
|
|
262
|
+
|-----------------|------------------------------------------------------------|
|
|
263
|
+
| Unchecked | Empty box with the theme's input background and border |
|
|
264
|
+
| Checked | Filled box using the primary color, with a checkmark |
|
|
265
|
+
| Indeterminate | Filled box using the primary color, with a dash indicator |
|
|
266
|
+
| Focused | Focus border and ring |
|
|
267
|
+
| Disabled | Disabled colors, no pointer interaction |
|
|
268
|
+
| Read-only | Default cursor, otherwise unchanged |
|
|
269
|
+
| Invalid (forms) | Error border and ring |
|
|
270
|
+
|
|
271
|
+
On the component, the invalid state shows once `touched` is `true` and either `invalid` is `true` or `required` is `true` and the box is unchecked. On the directive it needs both `invalid` and `touched`.
|
|
272
|
+
|
|
273
|
+
### Label size (component only)
|
|
274
|
+
|
|
275
|
+
| `labelSize` | Description |
|
|
276
|
+
|-------------|-------------------------------|
|
|
277
|
+
| `small` | Compact label text |
|
|
278
|
+
| `medium` | Standard label text (default) |
|
|
279
|
+
| `large` | Larger label text |
|
|
280
|
+
|
|
281
|
+
### Custom classes
|
|
282
|
+
|
|
283
|
+
Use the `class` input to extend styles. On `CheckBoxComponent` it targets the outer `<label>` container; on `CheckboxDirective` it targets the `<input>` element directly:
|
|
284
|
+
|
|
285
|
+
```html
|
|
286
|
+
|
|
287
|
+
<mona-check-box label="Bold label" class="font-semibold"></mona-check-box>
|
|
288
|
+
<input type="checkbox" monaCheckbox class="my-2" />
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Behavior
|
|
292
|
+
|
|
293
|
+
### Read-only
|
|
294
|
+
|
|
295
|
+
`readonly` cancels the click, so the value and the indeterminate state don't change. The control stays focusable and readable, and the native input gets `aria-readonly="true"`. With `[formField]`, the signal forms `readonly` rule writes it.
|
|
296
|
+
|
|
297
|
+
`CheckboxDirective` has no `readonly` input, and the HTML `readonly` attribute has no effect on a native checkbox.
|
|
298
|
+
|
|
299
|
+
## Accessibility
|
|
300
|
+
|
|
301
|
+
`CheckBoxComponent` renders the native `<input type="checkbox">` as visually hidden but accessible to screen readers. The native input's `aria-label` is the `aria-label` input, or else the `label` text. When both are empty, the accessible name comes from the wrapping `<label>` element, which includes any projected content. Always provide a `label`, meaningful projected content, `aria-label` or `aria-labelledby`.
|
|
302
|
+
|
|
303
|
+
`CheckBoxComponent` renders its own `<label>`, so don't wrap it in `mona-label`. To label it from outside, bind a `mona-label` or `label[monaLabel]` to it with `[for]="ref"`, or point a `for` at its `inputId`. A click on such a label toggles the box.
|
|
304
|
+
|
|
305
|
+
When `indeterminate` is `true`, the component sets `aria-checked="mixed"` on the native input, which is the correct ARIA value for a partially selected checkbox (e.g., a "select all" control with some children selected).
|
|
306
|
+
|
|
307
|
+
Keyboard interaction is handled by the underlying native input. Space toggles the checked state; Enter does not activate checkboxes (browser default for `<input type="checkbox">`).
|
|
308
|
+
|
|
309
|
+
Native `<input type="checkbox">` elements are included in the tab order by default; `CheckboxDirective` does not override this behavior.
|
|
310
|
+
|
|
311
|
+
## API
|
|
312
|
+
|
|
313
|
+
Everything below is imported from `@nanahoshi/mona-ui/check-box`.
|
|
314
|
+
|
|
315
|
+
### `CheckBoxComponent`
|
|
316
|
+
|
|
317
|
+
**Selector:** `mona-check-box`
|
|
318
|
+
**Implements:** `FormCheckboxControl`
|
|
319
|
+
|
|
320
|
+
#### Inputs
|
|
321
|
+
|
|
322
|
+
| Name | Type | Default | Description |
|
|
323
|
+
| --- | --- | --- | --- |
|
|
324
|
+
| `aria-describedby` | `string` | `""` | Id of an element that describes the check box, such as an error message. |
|
|
325
|
+
| `aria-label` | `string` | `""` | Accessible name of the check box when it has no visible label. |
|
|
326
|
+
| `aria-labelledby` | `string` | `""` | Id of the element that labels the check box. |
|
|
327
|
+
| `checked` (two-way) | `boolean` | `false` | Whether the control is checked. |
|
|
328
|
+
| `class` | `string` | `""` | Additional CSS classes merged onto the label container via `tailwind-merge`. |
|
|
329
|
+
| `disabled` | `boolean` | `false` | Renders the component with reduced visual emphasis and removes pointer interaction. |
|
|
330
|
+
| `indeterminate` | `boolean` | `false` | Activates indeterminate mode, showing a dash instead of a checkmark. A user change clears it, as it does on a native checkbox. Use `[(indeterminate)]` to follow that, because a one-way binding only writes again when the bound value changes. |
|
|
331
|
+
| `inputId` | `string` | `generated` | Id of the native checkbox input. Point a `<label for>` at it to label the check box from outside. A unique id is generated when it isn't set. |
|
|
332
|
+
| `invalid` | `boolean` | `false` | Marks the checkbox as invalid. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
333
|
+
| `label` | `string` | `""` | Text label displayed alongside the checkbox. When provided, takes precedence over projected content. |
|
|
334
|
+
| `labelPosition` | `"before" \| "after"` | `"after"` | Position of the label relative to the checkbox. |
|
|
335
|
+
| `labelSize` | `"large" \| "medium" \| "small"` | `"medium"` | Controls the font size of the label text. |
|
|
336
|
+
| `name` | `string` | `""` | Name of the native checkbox input, used in native form submission. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
337
|
+
| `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. |
|
|
338
|
+
| `required` | `boolean` | `false` | Marks the control as required for form validation. |
|
|
339
|
+
| `rounded` | `"full" \| "large" \| "medium" \| "none" \| "small"` | `"medium"` | Border-radius preset applied to the checkmark box. |
|
|
340
|
+
| `tabIndex` | `number` | `0` | Tab index of the native checkbox input. |
|
|
341
|
+
| `touched` | `boolean` | `false` | Marks the checkbox as touched. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
342
|
+
|
|
343
|
+
#### Outputs
|
|
344
|
+
|
|
345
|
+
| Name | Type | Description |
|
|
346
|
+
| --- | --- | --- |
|
|
347
|
+
| `checkedChange` | `boolean` | Emitted when `checked` changes. |
|
|
348
|
+
| `indeterminateChange` | `boolean` | Emitted with `false` when a user change clears the indeterminate mode. |
|
|
349
|
+
| `inputBlur` | `FocusEvent` | Emitted when the checkbox input loses focus. |
|
|
350
|
+
| `inputChange` | `Event` | Emitted when the checkbox value changes. |
|
|
351
|
+
| `inputFocus` | `FocusEvent` | Emitted when the checkbox input gains focus. |
|
|
352
|
+
| `touch` | `void` | Emitted when the checkbox loses focus or its value changes. |
|
|
353
|
+
|
|
354
|
+
#### Methods
|
|
355
|
+
|
|
356
|
+
| Signature | Description |
|
|
357
|
+
| --- | --- |
|
|
358
|
+
| `focus(options?: FocusOptions): void` | Moves focus to the native checkbox input. |
|
|
359
|
+
|
|
360
|
+
### `CheckboxDirective`
|
|
361
|
+
|
|
362
|
+
Applies Mona UI styling to a native `<input type="checkbox">`. All native checkbox behaviors — keyboard interaction,
|
|
363
|
+
form submission, `indeterminate` state, and Angular forms directives — are preserved.
|
|
364
|
+
|
|
365
|
+
**Selector:** `input[type='checkbox'][monaCheckbox]`
|
|
366
|
+
|
|
367
|
+
#### Inputs
|
|
368
|
+
|
|
369
|
+
| Name | Type | Default | Description |
|
|
370
|
+
| --- | --- | --- | --- |
|
|
371
|
+
| `class` | `string` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
372
|
+
| `invalid` | `boolean` | `false` | Marks the checkbox as invalid, triggering error border and ring styling. |
|
|
373
|
+
| `rounded` | `"full" \| "large" \| "medium" \| "none" \| "small"` | `"medium"` | Border-radius preset applied to the checkbox. |
|
|
374
|
+
| `touched` | `boolean` | `false` | Marks the checkbox as touched. Error styling is only shown when both `invalid` and `touched` are `true`. |
|