@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
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# Numeric Text Box
|
|
2
|
+
|
|
3
|
+
> A number input with spinner buttons, bounds and decimal formatting.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/numeric-text-box`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-numeric-text-box`
|
|
8
|
+
|
|
9
|
+
`NumericTextBoxComponent` is a numeric input with optional spinner buttons, bounded values, configurable decimal formatting, and signal-forms support. When the field is focused, it shows the raw edit text; when it is not focused, it shows the formatted value.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Use `NumericTextBoxComponent` when the user must enter a numeric value and the control should stay numeric throughout editing. It is a good fit for counts, quantities, prices, and other fixed-point values where step changes and clamping are useful.
|
|
14
|
+
|
|
15
|
+
Use `TextBoxComponent` when the user needs freeform text. `NumericTextBoxComponent` formats the value for display and keeps the underlying value numeric.
|
|
16
|
+
|
|
17
|
+
> **Forms.** `NumericTextBoxComponent` implements `FormValueControl<number | null>` from `@angular/forms/signals`, so use `[formField]` with signal forms. It has no `ControlValueAccessor`, but `[(ngModel)]`, `[formControl]` and `formControlName` work too, because Angular binds a control's `value` and `touch` directly when it has no accessor.
|
|
18
|
+
|
|
19
|
+
## Import & Quick Start
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { NumericTextBoxComponent } from "@nanahoshi/mona-ui/numeric-text-box";
|
|
23
|
+
import { FormField, form } from "@angular/forms/signals";
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Direct value binding**
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<mona-numeric-text-box
|
|
30
|
+
[(value)]="quantity"
|
|
31
|
+
[minValue]="0"
|
|
32
|
+
[maxValue]="100"
|
|
33
|
+
aria-label="Quantity">
|
|
34
|
+
</mona-numeric-text-box>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Examples
|
|
38
|
+
|
|
39
|
+
### Fixed-point display while editing
|
|
40
|
+
|
|
41
|
+
When the value is `12`, the unfocused control displays `12.00`. While focused, it shows `12`. If the value is `12.5`, the focused edit buffer shows `12.5`.
|
|
42
|
+
|
|
43
|
+
`decimals-example.component.ts`
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { Component, signal } from "@angular/core";
|
|
47
|
+
import { NumericTextBoxComponent } from "@nanahoshi/mona-ui/numeric-text-box";
|
|
48
|
+
|
|
49
|
+
@Component({
|
|
50
|
+
selector: "app-numeric-textbox-decimals-example",
|
|
51
|
+
imports: [NumericTextBoxComponent],
|
|
52
|
+
templateUrl: "./decimals-example.component.html"
|
|
53
|
+
})
|
|
54
|
+
export class NumericTextboxDecimalsExampleComponent {
|
|
55
|
+
protected readonly weight = signal<number | null>(12);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`decimals-example.component.html`
|
|
60
|
+
|
|
61
|
+
```html
|
|
62
|
+
<div class="flex max-w-xs flex-col gap-3">
|
|
63
|
+
<mona-numeric-text-box aria-label="Weight in kilograms" [decimals]="2" [(value)]="weight" />
|
|
64
|
+
<p class="text-sm">Value: {{ weight() ?? "empty" }}</p>
|
|
65
|
+
</div>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Custom formatter
|
|
69
|
+
|
|
70
|
+
`formatter` affects the unfocused display string. It does not replace the focused edit buffer.
|
|
71
|
+
|
|
72
|
+
`formatter-example.component.ts`
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { Component, signal } from "@angular/core";
|
|
76
|
+
import { NumericTextBoxComponent } from "@nanahoshi/mona-ui/numeric-text-box";
|
|
77
|
+
|
|
78
|
+
@Component({
|
|
79
|
+
selector: "app-numeric-textbox-formatter-example",
|
|
80
|
+
imports: [NumericTextBoxComponent],
|
|
81
|
+
templateUrl: "./formatter-example.component.html"
|
|
82
|
+
})
|
|
83
|
+
export class NumericTextboxFormatterExampleComponent {
|
|
84
|
+
protected readonly price = signal<number | null>(49.9);
|
|
85
|
+
|
|
86
|
+
protected readonly currencyFormatter = (value: number | null): string =>
|
|
87
|
+
value == null ? "" : `$ ${value.toFixed(2)}`;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`formatter-example.component.html`
|
|
92
|
+
|
|
93
|
+
```html
|
|
94
|
+
<div class="flex max-w-xs flex-col gap-3">
|
|
95
|
+
<mona-numeric-text-box aria-label="Price" [decimals]="2" [formatter]="currencyFormatter" [(value)]="price" />
|
|
96
|
+
<p class="text-sm">Value: {{ price() ?? "empty" }}</p>
|
|
97
|
+
</div>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Spinner buttons and step size
|
|
101
|
+
|
|
102
|
+
The spinner buttons and arrow keys use the configured `step` value, and stop at `minValue` and `maxValue`.
|
|
103
|
+
|
|
104
|
+
`step-example.component.ts`
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { Component, signal } from "@angular/core";
|
|
108
|
+
import { NumericTextBoxComponent } from "@nanahoshi/mona-ui/numeric-text-box";
|
|
109
|
+
|
|
110
|
+
@Component({
|
|
111
|
+
selector: "app-numeric-textbox-step-example",
|
|
112
|
+
imports: [NumericTextBoxComponent],
|
|
113
|
+
templateUrl: "./step-example.component.html"
|
|
114
|
+
})
|
|
115
|
+
export class NumericTextboxStepExampleComponent {
|
|
116
|
+
protected readonly duration = signal<number | null>(30);
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`step-example.component.html`
|
|
121
|
+
|
|
122
|
+
```html
|
|
123
|
+
<div class="flex max-w-xs flex-col gap-3">
|
|
124
|
+
<mona-numeric-text-box
|
|
125
|
+
aria-label="Meeting length in minutes"
|
|
126
|
+
[maxValue]="240"
|
|
127
|
+
[minValue]="15"
|
|
128
|
+
[step]="15"
|
|
129
|
+
[(value)]="duration" />
|
|
130
|
+
<p class="text-sm">Meeting length: {{ duration() ?? "not set" }} minutes</p>
|
|
131
|
+
</div>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Signal forms with bounds
|
|
135
|
+
|
|
136
|
+
Use the `FormField` directive when you want the form schema to write `value`, `touched`, `invalid`, `disabled`, `readonly`, and `required` into the component.
|
|
137
|
+
|
|
138
|
+
`forms-example.component.ts`
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { Component, signal } from "@angular/core";
|
|
142
|
+
import { form, FormField, required } from "@angular/forms/signals";
|
|
143
|
+
import { NumericTextBoxComponent } from "@nanahoshi/mona-ui/numeric-text-box";
|
|
144
|
+
|
|
145
|
+
@Component({
|
|
146
|
+
selector: "app-numeric-textbox-forms-example",
|
|
147
|
+
imports: [FormField, NumericTextBoxComponent],
|
|
148
|
+
templateUrl: "./forms-example.component.html"
|
|
149
|
+
})
|
|
150
|
+
export class NumericTextboxFormsExampleComponent {
|
|
151
|
+
readonly #model = signal<{ quantity: number | null }>({ quantity: 1 });
|
|
152
|
+
protected readonly order = form(this.#model, path => {
|
|
153
|
+
required(path.quantity, { message: "Enter a quantity." });
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`forms-example.component.html`
|
|
159
|
+
|
|
160
|
+
```html
|
|
161
|
+
<div class="flex max-w-xs flex-col gap-1">
|
|
162
|
+
<mona-numeric-text-box
|
|
163
|
+
aria-describedby="numeric-quantity-error"
|
|
164
|
+
aria-label="Quantity"
|
|
165
|
+
[formField]="order.quantity"
|
|
166
|
+
[maxValue]="10"
|
|
167
|
+
[minValue]="0" />
|
|
168
|
+
<p aria-live="polite" class="text-sm text-error" id="numeric-quantity-error">
|
|
169
|
+
@if (order.quantity().touched()) {
|
|
170
|
+
@for (error of order.quantity().errors(); track error.kind) {
|
|
171
|
+
{{ error.message }}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
</p>
|
|
175
|
+
<p class="text-sm">Quantity: {{ order.quantity().value() ?? "empty" }}</p>
|
|
176
|
+
</div>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Precision
|
|
180
|
+
|
|
181
|
+
A JavaScript `number` holds integers exactly only up to `9007199254740991` (`Number.MAX_SAFE_INTEGER`), and decimals only up to 15 significant digits. Rather than round a value silently, the control refuses the keystroke or paste that would go past that limit, and the spinner buttons stop at `±Number.MAX_SAFE_INTEGER`. For amounts that need more digits, such as money stored as a decimal type, use [`DecimalTextBoxComponent`](/decimal-textbox), whose value is a decimal string with no precision limit.
|
|
182
|
+
|
|
183
|
+
## Forms Integration
|
|
184
|
+
|
|
185
|
+
`NumericTextBoxComponent` implements `FormValueControl<number | null>` from `@angular/forms/signals` and is intended for signal forms use via `[formField]`.
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { disabled, form, FormField, required } from "@angular/forms/signals";
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
The `touch` output fires when focus leaves the component, after the value has been clamped to the bounds. Typing and spinning don't fire it, and neither does moving focus between the input and content inside the component, such as a prefix template.
|
|
192
|
+
|
|
193
|
+
The `invalid` and `touched` inputs are written by `FormField` when the control is used with signal forms. `required` contributes to the invalid state when the value is empty and the control has been touched.
|
|
194
|
+
|
|
195
|
+
## Accessibility
|
|
196
|
+
|
|
197
|
+
`NumericTextBoxComponent` renders `role="spinbutton"` on the inner input element. The host element has no role, and the ARIA inputs below go to the inner input, not the host.
|
|
198
|
+
|
|
199
|
+
| Attribute | When present | Value |
|
|
200
|
+
|--------------------|--------------------------------------------------------------------------------|-------------------------|
|
|
201
|
+
| `role` | Always | `"spinbutton"` |
|
|
202
|
+
| `aria-label` | The `aria-label` input is set | Its value |
|
|
203
|
+
| `aria-labelledby` | The `aria-labelledby` input is set | Its value |
|
|
204
|
+
| `aria-describedby` | The `aria-describedby` input is set | Its value |
|
|
205
|
+
| `aria-invalid` | Once `touched`, when `invalid` is `true` or `required` is `true` with no value | `"true"` |
|
|
206
|
+
| `aria-valuemax` | When `maxValue` is set | `maxValue` |
|
|
207
|
+
| `aria-valuemin` | When `minValue` is set | `minValue` |
|
|
208
|
+
| `aria-valuenow` | When a numeric value is present | Current numeric value |
|
|
209
|
+
| `aria-valuetext` | When the input shows text | Formatted display value |
|
|
210
|
+
|
|
211
|
+
`disabled`, `readonly` and `required` are set as the native attributes of the inner input, which assistive technology reads as those states.
|
|
212
|
+
|
|
213
|
+
**Consumer responsibilities**
|
|
214
|
+
|
|
215
|
+
- Name the control. Point a `<label for>` or `<mona-label for>` at `inputId`, wrap it in `<mona-label text="...">` (the browser names the inner input from the label), or set `aria-labelledby` or `aria-label`. The placeholder is not a label. `[for]` bound to a template reference only moves focus to the input on click, and doesn't name it.
|
|
216
|
+
|
|
217
|
+
## API
|
|
218
|
+
|
|
219
|
+
Everything below is imported from `@nanahoshi/mona-ui/numeric-text-box`.
|
|
220
|
+
|
|
221
|
+
### `NumericTextBoxComponent`
|
|
222
|
+
|
|
223
|
+
**Selector:** `mona-numeric-text-box`
|
|
224
|
+
**Implements:** `FormValueControl<number \| null>`
|
|
225
|
+
|
|
226
|
+
#### Inputs
|
|
227
|
+
|
|
228
|
+
| Name | Type | Default | Description |
|
|
229
|
+
| --- | --- | --- | --- |
|
|
230
|
+
| `aria-describedby` | `string` | `""` | ID of an element that provides an extended description for the input, such as a hint or an error message. |
|
|
231
|
+
| `aria-label` | `string \| null` | `null` | Accessible name for the input. Prefer a visible label, linked through `inputId` or `aria-labelledby`. |
|
|
232
|
+
| `aria-labelledby` | `string` | `""` | ID of an external element that provides the accessible name for the input. |
|
|
233
|
+
| `class` | `string` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
234
|
+
| `decimals` | `number` | `0` | Number of fractional decimal places to display and accept. Values are truncated to an integer and clamped to the range 0–20. Non-finite and negative values normalize to 0. |
|
|
235
|
+
| `disabled` | `boolean` | `false` | Sets whether the input is disabled. |
|
|
236
|
+
| `formatter` | `Action<number \| null, string> \| null` | `null` | Formats the value to be displayed in the input when the input is not focused. |
|
|
237
|
+
| `inputId` | `string` | `a generated ID` | ID of the inner input, so a `<label for>` or `<mona-label for>` can point at it. |
|
|
238
|
+
| `invalid` | `boolean` | `false` | Marks the text box as invalid. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
239
|
+
| `maxValue` | `number \| null` | `null` | Maximum value that can be entered. |
|
|
240
|
+
| `minValue` | `number \| null` | `null` | Minimum value that can be entered. |
|
|
241
|
+
| `nullable` | `boolean` | `true` | Sets whether the input can be empty. When `false`, leaving an empty field sets it to the minimum, or to zero when there is no minimum (clamped to the maximum). |
|
|
242
|
+
| `placeholder` | `string` | `""` | Text shown in the input while it is empty. It isn't a label: it disappears once there is a value. |
|
|
243
|
+
| `readonly` | `boolean` | `false` | Sets whether the input is readonly. The spin buttons are hidden while it is. |
|
|
244
|
+
| `required` | `boolean` | `false` | Sets whether the input is required. |
|
|
245
|
+
| `rounded` | `"full" \| "large" \| "medium" \| "none" \| "small"` | ```medium``` | Sets the border radius of the input. |
|
|
246
|
+
| `size` | `"large" \| "medium" \| "small"` | ```medium``` | Sets the size of the input. |
|
|
247
|
+
| `spinners` | `boolean` | `true` | Sets whether the spin buttons are visible. |
|
|
248
|
+
| `step` | `number` | `1` | Step value to increment or decrement the value. |
|
|
249
|
+
| `tabindex` | `number` | `0` | Tab index of the input. |
|
|
250
|
+
| `touched` | `boolean` | `false` | Sets the touched state of the text box. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
251
|
+
| `value` (two-way) | `number \| null` | `null` | Two-way bindable current value of the numeric text box. |
|
|
252
|
+
|
|
253
|
+
#### Outputs
|
|
254
|
+
|
|
255
|
+
| Name | Type | Description |
|
|
256
|
+
| --- | --- | --- |
|
|
257
|
+
| `inputBlur` | `FocusEvent` | Emits when focus leaves the component, after the value has been clamped to the bounds. Moving focus between the input and elements inside the component (such as a prefix template) doesn't count. |
|
|
258
|
+
| `inputFocus` | `FocusEvent` | Emits when the inner input element is focused. |
|
|
259
|
+
| `inputFocusOut` | `FocusEvent` | Emits when the inner input element loses focus. |
|
|
260
|
+
| `touch` | `void` | Emitted when focus leaves the component, as a native input is touched on blur. Typing and spinning don't count. The `FormField` directive listens to this to mark the field as touched. |
|
|
261
|
+
| `valueChange` | `number \| null` | Emitted when `value` changes. |
|
|
262
|
+
|
|
263
|
+
#### Methods
|
|
264
|
+
|
|
265
|
+
| Signature | Description |
|
|
266
|
+
| --- | --- |
|
|
267
|
+
| `decrease(): void` | Steps the value down by `step` and moves focus to the input. |
|
|
268
|
+
| `focus(options?: FocusOptions): void` | Moves focus to the input, with the caret at the end. |
|
|
269
|
+
| `increase(): void` | Steps the value up by `step` and moves focus to the input. |
|
|
270
|
+
| `onBlur(event: FocusEvent): void` | Runs when focus leaves an element inside the component: clamps the value and marks the field touched. |
|
|
271
|
+
|
|
272
|
+
### `NumericTextBoxPrefixTemplateDirective`
|
|
273
|
+
|
|
274
|
+
**Selector:** `ng-template[monaNumericTextBoxPrefixTemplate]`
|
|
275
|
+
|
|
276
|
+
### Types
|
|
277
|
+
|
|
278
|
+
#### `NUMERIC_TEXT_BOX_DEFAULT_MESSAGES`
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
const NUMERIC_TEXT_BOX_DEFAULT_MESSAGES: MonaNumericTextBoxMessages;
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
#### `Action`
|
|
285
|
+
|
|
286
|
+
From `@nanahoshi/mona-ui/common`.
|
|
287
|
+
|
|
288
|
+
A function taking a `P` and returning an `R`.
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
type Action<P = void, R = void> = (arg: P) => R;
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
#### `MonaNumericTextBoxMessages`
|
|
295
|
+
|
|
296
|
+
From `@nanahoshi/mona-ui/i18n`.
|
|
297
|
+
|
|
298
|
+
| Name | Type |
|
|
299
|
+
| --- | --- |
|
|
300
|
+
| `decrease` (read-only) | `string` |
|
|
301
|
+
| `increase` (read-only) | `string` |
|