@nanahoshi/mona-ui 0.25.0 → 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-group.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-button.mjs +14 -2
- package/fesm2022/nanahoshi-mona-ui-calendar.mjs +5 -2
- package/fesm2022/nanahoshi-mona-ui-chart.mjs +108 -22
- package/fesm2022/nanahoshi-mona-ui-check-box.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-chip.mjs +1 -1
- 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-scroll-view.mjs +7 -3
- package/fesm2022/nanahoshi-mona-ui-segmented.mjs +2 -1
- 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 +8 -3
- package/fesm2022/nanahoshi-mona-ui-split-button.mjs +10 -7
- 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-theme.mjs +53 -21
- 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/styles.css +12 -2
- 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,260 @@
|
|
|
1
|
+
# Decimal Text Box
|
|
2
|
+
|
|
3
|
+
> A numeric input whose value is a decimal string, for exact values like money.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/numeric-text-box`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-decimal-text-box`
|
|
8
|
+
|
|
9
|
+
`DecimalTextBoxComponent` is a numeric input whose value is a decimal string, such as `"1234.56"`, instead of a JavaScript `number`. Use it for money, quantities with many digits, and any value that must not be rounded. It has the same spinner buttons, bounds, decimal formatting, and signal-forms support as the numeric text box, with no precision limit.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
A JavaScript `number` holds integers exactly only up to `9007199254740991` (`Number.MAX_SAFE_INTEGER`), and decimals only up to about 15 significant digits. `NumericTextBoxComponent` refuses input past that limit rather than round it. `DecimalTextBoxComponent` keeps its value as a decimal string and does all of its arithmetic exactly, so there is no limit:
|
|
14
|
+
|
|
15
|
+
- Typing `12345678901234567890.12` stores `"12345678901234567890.12"`.
|
|
16
|
+
- Stepping `"0.1"` by `"0.2"` gives `"0.3"`, not `0.30000000000000004`.
|
|
17
|
+
|
|
18
|
+
Use `NumericTextBoxComponent` when a `number` is enough, such as for counts or percentages. Use `DecimalTextBoxComponent` when the value is sent to a backend as a decimal type (for example `DECIMAL`, `BigDecimal` or `decimal`), or when its digits must survive unchanged.
|
|
19
|
+
|
|
20
|
+
> **Forms.** `DecimalTextBoxComponent` implements `FormValueControl<string | 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.
|
|
21
|
+
|
|
22
|
+
## Import & Quick Start
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { DecimalTextBoxComponent } from "@nanahoshi/mona-ui/numeric-text-box";
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Direct value binding**
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<mona-decimal-text-box
|
|
32
|
+
[(value)]="amount"
|
|
33
|
+
[decimals]="2"
|
|
34
|
+
minValue="0"
|
|
35
|
+
aria-label="Amount">
|
|
36
|
+
</mona-decimal-text-box>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### The value format
|
|
40
|
+
|
|
41
|
+
The value is a **canonical decimal string**: an optional `-`, ASCII digits, and an optional `.` followed by digits. It never contains grouping, an exponent, leading zeros or trailing fraction zeros, so equal amounts always have equal strings:
|
|
42
|
+
|
|
43
|
+
| User types (`de-DE`) | `value` |
|
|
44
|
+
|----------------------|------------------|
|
|
45
|
+
| `1.234,50` | `"1234.5"` |
|
|
46
|
+
| `-0,0` | `"0"` |
|
|
47
|
+
| `0012` | `"12"` |
|
|
48
|
+
|
|
49
|
+
The displayed text is localized; the value is not. `decimals` controls how many fraction digits are shown and accepted, not the value's format. Set a value the same way, as a canonical decimal string. A value that is not a decimal string (for example `"1,5"` or `"1e3"`) logs a dev-mode warning.
|
|
50
|
+
|
|
51
|
+
## Examples
|
|
52
|
+
|
|
53
|
+
### Bounds and step
|
|
54
|
+
|
|
55
|
+
`minValue`, `maxValue` and `step` accept a decimal string or a number. A string keeps every digit; a number is converted to its shortest decimal form.
|
|
56
|
+
|
|
57
|
+
`bounds-example.component.ts`
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { Component, signal } from "@angular/core";
|
|
61
|
+
import { DecimalTextBoxComponent } from "@nanahoshi/mona-ui/numeric-text-box";
|
|
62
|
+
|
|
63
|
+
@Component({
|
|
64
|
+
selector: "app-decimal-textbox-bounds-example",
|
|
65
|
+
imports: [DecimalTextBoxComponent],
|
|
66
|
+
templateUrl: "./bounds-example.component.html"
|
|
67
|
+
})
|
|
68
|
+
export class DecimalTextboxBoundsExampleComponent {
|
|
69
|
+
protected readonly rate = signal<string | null>("12345678901234567890.1234");
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`bounds-example.component.html`
|
|
74
|
+
|
|
75
|
+
```html
|
|
76
|
+
<div class="flex max-w-sm flex-col gap-3">
|
|
77
|
+
<mona-decimal-text-box
|
|
78
|
+
aria-label="Rate"
|
|
79
|
+
maxValue="99999999999999999999.9999"
|
|
80
|
+
minValue="0"
|
|
81
|
+
step="0.0001"
|
|
82
|
+
[decimals]="4"
|
|
83
|
+
[(value)]="rate" />
|
|
84
|
+
<p class="text-sm break-all">Value: {{ rate() ?? "empty" }}</p>
|
|
85
|
+
</div>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The spinner buttons, arrow keys and mouse wheel stop at `minValue` and `maxValue`. On blur, a value outside the range is corrected to the nearest bound.
|
|
89
|
+
|
|
90
|
+
### Custom formatter
|
|
91
|
+
|
|
92
|
+
`formatNumber` from `@nanahoshi/mona-ui/i18n` formats a decimal string exactly. `formatter` affects the unfocused display string. It does not replace the focused edit buffer.
|
|
93
|
+
|
|
94
|
+
`formatter-example.component.ts`
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { Component, signal } from "@angular/core";
|
|
98
|
+
import { formatNumber } from "@nanahoshi/mona-ui/i18n";
|
|
99
|
+
import { DecimalTextBoxComponent } from "@nanahoshi/mona-ui/numeric-text-box";
|
|
100
|
+
|
|
101
|
+
@Component({
|
|
102
|
+
selector: "app-decimal-textbox-formatter-example",
|
|
103
|
+
imports: [DecimalTextBoxComponent],
|
|
104
|
+
templateUrl: "./formatter-example.component.html"
|
|
105
|
+
})
|
|
106
|
+
export class DecimalTextboxFormatterExampleComponent {
|
|
107
|
+
protected readonly amount = signal<string | null>("1234567.5");
|
|
108
|
+
protected readonly currencyFormatter = (value: string | null): string =>
|
|
109
|
+
value == null ? "" : formatNumber(value, "en-US", { currency: "USD", style: "currency" });
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`formatter-example.component.html`
|
|
114
|
+
|
|
115
|
+
```html
|
|
116
|
+
<div class="flex max-w-sm flex-col gap-3">
|
|
117
|
+
<mona-decimal-text-box aria-label="Amount" [decimals]="2" [formatter]="currencyFormatter" [(value)]="amount" />
|
|
118
|
+
<p class="text-sm">Value: {{ amount() ?? "empty" }}</p>
|
|
119
|
+
</div>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Signal forms
|
|
123
|
+
|
|
124
|
+
The form field holds the canonical decimal string, whatever the display locale.
|
|
125
|
+
|
|
126
|
+
`forms-example.component.ts`
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { Component, signal } from "@angular/core";
|
|
130
|
+
import { form, FormField, required } from "@angular/forms/signals";
|
|
131
|
+
import { DecimalTextBoxComponent } from "@nanahoshi/mona-ui/numeric-text-box";
|
|
132
|
+
|
|
133
|
+
@Component({
|
|
134
|
+
selector: "app-decimal-textbox-forms-example",
|
|
135
|
+
imports: [DecimalTextBoxComponent, FormField],
|
|
136
|
+
templateUrl: "./forms-example.component.html"
|
|
137
|
+
})
|
|
138
|
+
export class DecimalTextboxFormsExampleComponent {
|
|
139
|
+
readonly #model = signal<{ amount: string | null }>({ amount: "1250" });
|
|
140
|
+
protected readonly payment = form(this.#model, path => {
|
|
141
|
+
required(path.amount, { message: "Enter an amount." });
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`forms-example.component.html`
|
|
147
|
+
|
|
148
|
+
```html
|
|
149
|
+
<div class="flex max-w-sm flex-col gap-1">
|
|
150
|
+
<mona-decimal-text-box
|
|
151
|
+
aria-describedby="decimal-amount-error"
|
|
152
|
+
aria-label="Amount"
|
|
153
|
+
minValue="0"
|
|
154
|
+
[decimals]="2"
|
|
155
|
+
[formField]="payment.amount" />
|
|
156
|
+
<p aria-live="polite" class="text-sm text-error" id="decimal-amount-error">
|
|
157
|
+
@if (payment.amount().touched()) {
|
|
158
|
+
@for (error of payment.amount().errors(); track error.kind) {
|
|
159
|
+
{{ error.message }}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
</p>
|
|
163
|
+
<p class="text-sm">Sent to the server: {{ payment.amount().value() ?? "null" }}</p>
|
|
164
|
+
</div>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Parsing and validating text
|
|
168
|
+
|
|
169
|
+
`@nanahoshi/mona-ui/i18n` has helpers for working with the same text outside the component:
|
|
170
|
+
|
|
171
|
+
| Name | Description |
|
|
172
|
+
|--------------------------------|--------------------------------------------------------------------------------------------|
|
|
173
|
+
| `parseLocalizedDecimal` | Parses localized text to a canonical decimal string, with no precision limit. |
|
|
174
|
+
| `validateLocalizedDecimal` | Validates complete or pasted text and returns the decimal string and an invalid `reason`. |
|
|
175
|
+
| `validateLocalizedDecimalEdit` | Validates text while it is typed. |
|
|
176
|
+
| `formatNumber` | Accepts a decimal string and formats it exactly. |
|
|
177
|
+
|
|
178
|
+
## Accessibility
|
|
179
|
+
|
|
180
|
+
`DecimalTextBoxComponent` renders the same markup as `NumericTextBoxComponent`: `role="spinbutton"` on the inner input, with `aria-valuenow`, `aria-valuemin` and `aria-valuemax` set to the decimal strings and `aria-valuetext` set to the formatted display value.
|
|
181
|
+
|
|
182
|
+
**Consumer responsibilities**
|
|
183
|
+
|
|
184
|
+
- Name the control the same way as `NumericTextBoxComponent`: point a `<label for>` or `<mona-label for>` at `inputId`, wrap it in `<mona-label text="...">`, or set `aria-labelledby` or `aria-label`. `[for]` bound to a template reference only moves focus to the input, and doesn't name it.
|
|
185
|
+
|
|
186
|
+
## API
|
|
187
|
+
|
|
188
|
+
Everything below is imported from `@nanahoshi/mona-ui/numeric-text-box`.
|
|
189
|
+
|
|
190
|
+
### `DecimalTextBoxComponent`
|
|
191
|
+
|
|
192
|
+
A numeric input whose value is a decimal string, for amounts a JavaScript `number` cannot hold exactly (money,
|
|
193
|
+
quantities with many digits, identifiers). Typing, paste, spin buttons and bounds use exact decimal arithmetic,
|
|
194
|
+
so there is no precision limit. The value is canonical: `"-1234.5"`, with `.` as the separator and no grouping,
|
|
195
|
+
exponent, leading zeros or trailing fraction zeros.
|
|
196
|
+
|
|
197
|
+
**Selector:** `mona-decimal-text-box`
|
|
198
|
+
**Implements:** `FormValueControl<string \| null>`
|
|
199
|
+
|
|
200
|
+
#### Inputs
|
|
201
|
+
|
|
202
|
+
| Name | Type | Default | Description |
|
|
203
|
+
| --- | --- | --- | --- |
|
|
204
|
+
| `aria-describedby` | `string` | `""` | ID of an element that provides an extended description for the input, such as a hint or an error message. |
|
|
205
|
+
| `aria-label` | `string \| null` | `null` | Accessible name for the input. Prefer a visible label, linked through `inputId` or `aria-labelledby`. |
|
|
206
|
+
| `aria-labelledby` | `string` | `""` | ID of an external element that provides the accessible name for the input. |
|
|
207
|
+
| `class` | `string` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
208
|
+
| `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. |
|
|
209
|
+
| `disabled` | `boolean` | `false` | Sets whether the input is disabled. |
|
|
210
|
+
| `formatter` | `Action<string \| null, string> \| null` | `null` | Formats the value to be displayed in the input when the input is not focused. |
|
|
211
|
+
| `inputId` | `string` | `a generated ID` | ID of the inner input, so a `<label for>` or `<mona-label for>` can point at it. |
|
|
212
|
+
| `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. |
|
|
213
|
+
| `maxValue` | `string \| number \| null` | `null` | Maximum value that can be entered, as a decimal string or a number. |
|
|
214
|
+
| `minValue` | `string \| number \| null` | `null` | Minimum value that can be entered, as a decimal string or a number. |
|
|
215
|
+
| `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). |
|
|
216
|
+
| `placeholder` | `string` | `""` | Text shown in the input while it is empty. It isn't a label: it disappears once there is a value. |
|
|
217
|
+
| `readonly` | `boolean` | `false` | Sets whether the input is readonly. The spin buttons are hidden while it is. |
|
|
218
|
+
| `required` | `boolean` | `false` | Sets whether the input is required. |
|
|
219
|
+
| `rounded` | `"full" \| "large" \| "medium" \| "none" \| "small"` | ```medium``` | Sets the border radius of the input. |
|
|
220
|
+
| `size` | `"large" \| "medium" \| "small"` | ```medium``` | Sets the size of the input. |
|
|
221
|
+
| `spinners` | `boolean` | `true` | Sets whether the spin buttons are visible. |
|
|
222
|
+
| `step` | `string \| number` | `"1"` | Step value to increment or decrement the value, as a decimal string or a number. |
|
|
223
|
+
| `tabindex` | `number` | `0` | Tab index of the input. |
|
|
224
|
+
| `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. |
|
|
225
|
+
| `value` (two-way) | `string \| null` | `null` | Two-way bindable current value, as a canonical decimal string such as `"-1234.5"`. |
|
|
226
|
+
|
|
227
|
+
#### Outputs
|
|
228
|
+
|
|
229
|
+
| Name | Type | Description |
|
|
230
|
+
| --- | --- | --- |
|
|
231
|
+
| `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. |
|
|
232
|
+
| `inputFocus` | `FocusEvent` | Emits when the inner input element is focused. |
|
|
233
|
+
| `inputFocusOut` | `FocusEvent` | Emits when the inner input element loses focus. |
|
|
234
|
+
| `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. |
|
|
235
|
+
| `valueChange` | `string \| null` | Emitted when `value` changes. |
|
|
236
|
+
|
|
237
|
+
#### Methods
|
|
238
|
+
|
|
239
|
+
| Signature | Description |
|
|
240
|
+
| --- | --- |
|
|
241
|
+
| `decrease(): void` | Steps the value down by `step` and moves focus to the input. |
|
|
242
|
+
| `focus(options?: FocusOptions): void` | Moves focus to the input, with the caret at the end. |
|
|
243
|
+
| `increase(): void` | Steps the value up by `step` and moves focus to the input. |
|
|
244
|
+
| `onBlur(event: FocusEvent): void` | Runs when focus leaves an element inside the component: clamps the value and marks the field touched. |
|
|
245
|
+
|
|
246
|
+
### `NumericTextBoxPrefixTemplateDirective`
|
|
247
|
+
|
|
248
|
+
**Selector:** `ng-template[monaNumericTextBoxPrefixTemplate]`
|
|
249
|
+
|
|
250
|
+
### Types
|
|
251
|
+
|
|
252
|
+
#### `Action`
|
|
253
|
+
|
|
254
|
+
From `@nanahoshi/mona-ui/common`.
|
|
255
|
+
|
|
256
|
+
A function taking a `P` and returning an `R`.
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
type Action<P = void, R = void> = (arg: P) => R;
|
|
260
|
+
```
|