@nanahoshi/mona-ui 0.35.0 → 0.36.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/docs/api/common.md +1 -1
- package/docs/api/i18n.md +26 -5
- package/docs/api/locales.md +14 -14
- package/docs/api/masked-text-box.md +137 -0
- package/docs/api/multi-select.md +1 -0
- package/docs/masked-textbox.md +334 -0
- package/docs/multi-select.md +66 -0
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +54 -15
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +10 -1
- package/fesm2022/nanahoshi-mona-ui-masked-text-box.mjs +1302 -0
- package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +29 -1
- package/i18n/catalogs/en-US.messages.json +10 -1
- package/llms.txt +3 -1
- package/locales/ar-sa/ar-sa.messages.json +10 -1
- package/locales/de-de/de-de.messages.json +10 -1
- package/locales/es-es/es-es.messages.json +10 -1
- package/locales/fr-fr/fr-fr.messages.json +10 -1
- package/locales/id-id/id-id.messages.json +10 -1
- package/locales/it-it/it-it.messages.json +10 -1
- package/locales/ja-jp/ja-jp.messages.json +10 -1
- package/locales/ko-kr/ko-kr.messages.json +10 -1
- package/locales/pl-pl/pl-pl.messages.json +10 -1
- package/locales/pt-br/pt-br.messages.json +10 -1
- package/locales/ru-ru/ru-ru.messages.json +10 -1
- package/locales/tr-tr/tr-tr.messages.json +10 -1
- package/locales/zh-cn/zh-cn.messages.json +10 -1
- package/locales/zh-tw/zh-tw.messages.json +10 -1
- package/masked-text-box/package.json +4 -0
- package/package.json +5 -1
- package/types/nanahoshi-mona-ui-i18n.d.ts +20 -0
- package/types/nanahoshi-mona-ui-internal-list.d.ts +12 -0
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +9 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +9 -0
- package/types/nanahoshi-mona-ui-masked-text-box.d.ts +391 -0
- package/types/nanahoshi-mona-ui-multi-select.d.ts +11 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# `@nanahoshi/mona-ui/masked-text-box`
|
|
2
|
+
|
|
3
|
+
Everything `@nanahoshi/mona-ui/masked-text-box` exports.
|
|
4
|
+
|
|
5
|
+
**Guides:** [Masked Text Box](../masked-textbox.md)
|
|
6
|
+
|
|
7
|
+
## `MaskedTextBoxComponent`
|
|
8
|
+
|
|
9
|
+
Component.
|
|
10
|
+
|
|
11
|
+
A text box that takes a value in a fixed format, such as a phone number or a postal code. Each character goes into
|
|
12
|
+
a slot of the mask, and the mask's literals, such as the parentheses and dash of `(000) 000-0000`, are filled in as
|
|
13
|
+
you type. The rest of the mask shows after what's typed, so the format is in view.
|
|
14
|
+
|
|
15
|
+
**Selector:** `mona-masked-text-box`
|
|
16
|
+
**Implements:** `FormValueControl<string>`
|
|
17
|
+
|
|
18
|
+
### Inputs
|
|
19
|
+
|
|
20
|
+
| Name | Type | Default | Description |
|
|
21
|
+
| --- | --- | --- | --- |
|
|
22
|
+
| `aria-describedby` | `string` | `""` | Id of an element that describes the inner input, such as a hint that gives the format. |
|
|
23
|
+
| `aria-label` | `string` | `""` | Accessible name of the inner input. Prefer a visible label, linked through `inputId` or `aria-labelledby`. |
|
|
24
|
+
| `aria-labelledby` | `string` | `""` | Id of the element that labels the inner input. |
|
|
25
|
+
| `class` | `string` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
26
|
+
| `clearButton` | `boolean` | `false` | Displays a clear button that empties the value. The button is hidden while the value is empty or the box is disabled or read-only. |
|
|
27
|
+
| `disabled` | `boolean` | `false` | Renders the component with reduced visual emphasis and removes pointer interaction. |
|
|
28
|
+
| `includeLiterals` | `boolean` | `false` | Whether the value includes the mask's literals: `(555) 123-4567` instead of `5551234567`. |
|
|
29
|
+
| `inputAttributes` | `AttributeConfig` | `{}` | Additional HTML attributes applied directly to the inner `<input>` element, such as `autocomplete`. An `inputmode` here replaces the one the mask picks. |
|
|
30
|
+
| `inputClass` | `string \| string[]` | `""` | Additional CSS classes applied to the inner `<input>` element. |
|
|
31
|
+
| `inputId` | `string` | `generated` | Id of the inner `<input>` element. Point a `<label for>` or `<mona-label for>` at it to label the box. A unique id is generated when it isn't set. |
|
|
32
|
+
| `inputStyle` | `string \| Partial<CSSStyleDeclaration> \| null` | `null` | Inline styles applied to the inner `<input>` element. Accepts a style string or a `CSSStyleDeclaration` partial. |
|
|
33
|
+
| `invalid` | `boolean` | `false` | Marks the box as invalid. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. Once touched, the box also shows as invalid while it's partly filled. |
|
|
34
|
+
| `mask` | `string` | `""` | The format, one character per slot or literal. `0` is a digit, `9` an optional digit, `#` an optional digit, `+` or `-`, `L` a letter, `?` an optional letter, `A` a letter or digit, `a` an optional letter or digit, `&` any character but a space, and `C` an optional one. Anything else is a literal, and so is a character after a backslash, such as `\0`. |
|
|
35
|
+
| `name` | `string` | `""` | Name of the inner input, used by browsers and password managers for autofill. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
36
|
+
| `placeholder` | `string` | `""` | Text shown while the box is empty and doesn't have focus, in place of the mask. |
|
|
37
|
+
| `prompt` | `string` | `"_"` | The character shown in an empty slot. |
|
|
38
|
+
| `readonly` | `boolean` | `false` | Prevents value changes while preserving the component's visual state. |
|
|
39
|
+
| `required` | `boolean` | `false` | Marks the box as required. Triggers the invalid state when the value is empty and the field has been touched. |
|
|
40
|
+
| `rounded` | `"full" \| "large" \| "medium" \| "none" \| "small"` | `"medium"` | Border-radius preset applied to the component. |
|
|
41
|
+
| `rules` | `MaskRules` | `{}` | Mask characters of your own, each mapped to a pattern one character must match, such as `{ H: /[0-9a-f]/i }`. They can replace the built-in ones, and their slots are required. |
|
|
42
|
+
| `size` | `"large" \| "medium" \| "small"` | `"medium"` | Size preset controlling the component's dimensions. |
|
|
43
|
+
| `touched` | `boolean` | `false` | Sets the touched state of the box. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
44
|
+
| `value` (two-way) | `string` | `""` | Two-way bindable value: the characters typed into the slots, up to the last one filled, with a space for an empty slot before it. `includeLiterals` adds the mask's literals. A value that doesn't line up with the mask, such as `555-123-4567` for `(000) 000-0000`, is fitted into it and written back as it reads. |
|
|
45
|
+
|
|
46
|
+
### Outputs
|
|
47
|
+
|
|
48
|
+
| Name | Type | Description |
|
|
49
|
+
| --- | --- | --- |
|
|
50
|
+
| `inputBlur` | `FocusEvent` | Emitted when the inner input loses focus, including when focus moves to the clear button or to content in the prefix or suffix templates. |
|
|
51
|
+
| `inputFocus` | `FocusEvent` | Emitted when the inner input gains focus. |
|
|
52
|
+
| `touch` | `void` | Emitted when focus leaves the box, including its clear button and prefix and suffix content. Form directives (`[formField]`, `ngModel`, `formControl`) listen to this to mark the field as touched. |
|
|
53
|
+
| `valueChange` | `string` | Emitted when `value` changes. |
|
|
54
|
+
|
|
55
|
+
### Methods
|
|
56
|
+
|
|
57
|
+
| Signature | Description |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `focus(options?: FocusOptions): void` | Focuses the inner input and puts the caret at the first empty slot, where typing picks up. |
|
|
60
|
+
|
|
61
|
+
## `MaskedTextBoxPrefixTemplateDirective`
|
|
62
|
+
|
|
63
|
+
Directive.
|
|
64
|
+
|
|
65
|
+
Marks an `<ng-template>` as content before the masked text box's input, such as an icon or a country code. Several
|
|
66
|
+
render in source order.
|
|
67
|
+
|
|
68
|
+
**Selector:** `ng-template[monaMaskedTextBoxPrefixTemplate]`
|
|
69
|
+
|
|
70
|
+
## `MaskedTextBoxSuffixTemplateDirective`
|
|
71
|
+
|
|
72
|
+
Directive.
|
|
73
|
+
|
|
74
|
+
Marks an `<ng-template>` as content after the masked text box's input and its clear button, such as a unit or a
|
|
75
|
+
button. Several render in source order.
|
|
76
|
+
|
|
77
|
+
**Selector:** `ng-template[monaMaskedTextBoxSuffixTemplate]`
|
|
78
|
+
|
|
79
|
+
## `formatMaskedValue`
|
|
80
|
+
|
|
81
|
+
Function.
|
|
82
|
+
|
|
83
|
+
Formats a value for display with its mask's literals, such as `"5551234567"` as `"(555) 123-4567"` for the mask
|
|
84
|
+
`"(000) 000-0000"`. It reads the value as a masked text box with the same options would, and stops after the last
|
|
85
|
+
character the value has. An empty slot before it shows as a space.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
function formatMaskedValue(value: string, mask: string, options: MaskOptions = {}): string;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## `isMaskComplete`
|
|
92
|
+
|
|
93
|
+
Function.
|
|
94
|
+
|
|
95
|
+
Whether a value fills every required slot of a mask, for a validator. An empty value doesn't, so let an optional
|
|
96
|
+
field's validator pass `""` first.
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
function isMaskComplete(value: string, mask: string, options: MaskOptions = {}): boolean;
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## `MASKED_TEXT_BOX_DEFAULT_MESSAGES`
|
|
103
|
+
|
|
104
|
+
Constant.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
const MASKED_TEXT_BOX_DEFAULT_MESSAGES: MonaMaskedTextBoxMessages;
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## `MaskOptions`
|
|
111
|
+
|
|
112
|
+
Interface.
|
|
113
|
+
|
|
114
|
+
How a value is read against a mask, for `isMaskComplete` and `formatMaskedValue`. Pass what the masked
|
|
115
|
+
text box is given.
|
|
116
|
+
|
|
117
|
+
### Properties
|
|
118
|
+
|
|
119
|
+
| Name | Type | Description |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| `includeLiterals?` (read-only) | `boolean` | Whether the value includes the mask's literal characters, as the masked text box's `includeLiterals`. |
|
|
122
|
+
| `rules?` (read-only) | `MaskRules` | Custom mask characters, as the masked text box's `rules`. |
|
|
123
|
+
|
|
124
|
+
**Used by:** [`formatMaskedValue`](masked-text-box.md#formatmaskedvalue), [`isMaskComplete`](masked-text-box.md#ismaskcomplete)
|
|
125
|
+
|
|
126
|
+
## `MaskRules`
|
|
127
|
+
|
|
128
|
+
Type alias.
|
|
129
|
+
|
|
130
|
+
Mask characters of your own, each mapped to a pattern that one character must match, such as `{ H: /[0-9a-f]/i }`
|
|
131
|
+
for a hexadecimal digit. A slot made by a custom rule is required. A rule can replace a built-in one, such as `0`.
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
type MaskRules = Readonly<Record<string, RegExp>>;
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Used by:** [`MaskedTextBoxComponent`](masked-text-box.md#maskedtextboxcomponent), [`MaskOptions`](masked-text-box.md#maskoptions)
|
package/docs/api/multi-select.md
CHANGED
|
@@ -36,6 +36,7 @@ Component.
|
|
|
36
36
|
| `required` | `boolean` | `false` | Sets the required state of the multi select component. |
|
|
37
37
|
| `rounded` | `"full" \| "large" \| "medium" \| "none" \| "small"` | `"medium"` | Sets the border radius of the multi select component. |
|
|
38
38
|
| `showClearButton` | `boolean` | `false` | Renders a button that clears all selected items when at least one item is selected. |
|
|
39
|
+
| `showSelectAll` | `boolean` | `false` | Starts the list with a "Select all" option, which selects every enabled item the filter leaves, or deselects them when they're all selected. Its checkbox shows when only some are. |
|
|
39
40
|
| `size` | `"large" \| "medium" \| "small"` | `"medium"` | The size of the multi select component. |
|
|
40
41
|
| `textField` | `DropdownFieldSelectorType<TData, string>` | `null` | Sets the text field of the multi select component. It can be null, string, or a function that takes an item and returns a string. If null, the item itself will be used as the text representation. |
|
|
41
42
|
| `touched` | `boolean` | `false` | Sets the touched state of the multi select. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# Masked Text Box
|
|
2
|
+
|
|
3
|
+
> A text input for values in a fixed format, such as phone numbers, that fills in the format as you type.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/masked-text-box`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-masked-text-box`
|
|
8
|
+
|
|
9
|
+
`MaskedTextBoxComponent` is a text input for values in one fixed format, such as a phone number, a postal code or a product key. Each character goes into a slot of the mask, the mask's own characters, such as the parentheses and dash of `(000) 000-0000`, are filled in as you type, and the rest of the format shows after what's typed. A character a slot doesn't take is turned down, and screen readers say what the slot takes.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Use a masked text box when a value always has the same shape, and people copy it from somewhere else: a phone number in one country's format, a postal code, the expiry date on a card, a licence key. The mask shows the shape before they start, and fills in the separators so they only type what matters.
|
|
14
|
+
|
|
15
|
+
**Use a masked text box when you need to:**
|
|
16
|
+
|
|
17
|
+
- Take a value whose length and separators never change
|
|
18
|
+
- Show the format in the field itself, as people type
|
|
19
|
+
- Keep separators out of the value, or put them in, whichever way the user typed them
|
|
20
|
+
|
|
21
|
+
**Use something else when:**
|
|
22
|
+
|
|
23
|
+
- The format varies, such as phone numbers from any country, names or street addresses: use a [text box](textbox.md) with a hint, and check the value with a validator. A mask that doesn't fit someone's real value stops them from entering it at all.
|
|
24
|
+
- The value is a date or a time: use the [date picker](date-picker.md) or the [time picker](time-picker.md), which follow the user's locale and offer a calendar or a list.
|
|
25
|
+
- The value is a number in a range: use the [numeric text box](numeric-textbox.md).
|
|
26
|
+
- The value is a one-time code: use the [OTP input](otp-input.md), which shows a box per character and works with autofill from text messages.
|
|
27
|
+
|
|
28
|
+
## Import & Quick Start
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { MaskedTextBoxComponent } from "@nanahoshi/mona-ui/masked-text-box";
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
<mona-form-field label="Phone" hint="10 digits, such as (555) 123-4567.">
|
|
36
|
+
<mona-masked-text-box mask="(000) 000-0000" [(value)]="phone" />
|
|
37
|
+
</mona-form-field>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The value holds what's typed into the slots, `5551234567`. Set `includeLiterals` for `(555) 123-4567`.
|
|
41
|
+
|
|
42
|
+
## Anatomy
|
|
43
|
+
|
|
44
|
+
### Mask characters
|
|
45
|
+
|
|
46
|
+
| Character | Takes | Required |
|
|
47
|
+
|-----------|-------|----------|
|
|
48
|
+
| `0` | A digit | Yes |
|
|
49
|
+
| `9` | A digit | No |
|
|
50
|
+
| `#` | A digit, `+` or `-` | No |
|
|
51
|
+
| `L` | A letter | Yes |
|
|
52
|
+
| `?` | A letter | No |
|
|
53
|
+
| `A` | A letter or a digit | Yes |
|
|
54
|
+
| `a` | A letter or a digit | No |
|
|
55
|
+
| `&` | Any character but a space | Yes |
|
|
56
|
+
| `C` | Any character but a space | No |
|
|
57
|
+
|
|
58
|
+
Any other character is a literal, shown as it is and filled in as you type, such as the parentheses, space and dash of `(000) 000-0000`. A backslash makes a mask character a literal: `\#` is a hash sign. In a template that's `mask="\#HHHHHH"`, and in a TypeScript string the backslash needs escaping, `"\\#HHHHHH"`.
|
|
59
|
+
|
|
60
|
+
A letter is a letter of any script. Digits of any script, such as the Arabic-Indic `٣`, and the full-width digits and letters CJK input methods type, are kept as ASCII, so the value is `3`.
|
|
61
|
+
|
|
62
|
+
`rules` adds mask characters of your own, each a pattern one character must match, such as `{ H: /[0-9a-f]/i }` for a hexadecimal digit. A rule can replace a built-in one, and its slots are required.
|
|
63
|
+
|
|
64
|
+
### Parts
|
|
65
|
+
|
|
66
|
+
| Part | What it is |
|
|
67
|
+
|------|------------|
|
|
68
|
+
| Input | The native `<input>`. It holds what's typed and the literals up to it, and takes the id, the name, the description and `aria-invalid`. |
|
|
69
|
+
| The rest of the mask | Muted text after what's typed: the `prompt` character for each empty slot, and the literals between them. It's drawn behind the input and hidden from assistive technology. |
|
|
70
|
+
| Clear button | Shown with `clearButton` while there's a value. |
|
|
71
|
+
| Prefix and suffix | Content from `ng-template monaMaskedTextBoxPrefixTemplate` and `ng-template monaMaskedTextBoxSuffixTemplate`, such as a country code or a unit. |
|
|
72
|
+
|
|
73
|
+
## Examples
|
|
74
|
+
|
|
75
|
+
### A phone number
|
|
76
|
+
|
|
77
|
+
The value is the ten digits. `formatMaskedValue` formats a stored value with the same mask, for showing it elsewhere, such as in a table. The `autocomplete` token asks autofill for a number in the national format the mask takes.
|
|
78
|
+
|
|
79
|
+
`phone-example.component.ts`
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { Component, computed, signal } from "@angular/core";
|
|
83
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
84
|
+
import { formatMaskedValue, MaskedTextBoxComponent } from "@nanahoshi/mona-ui/masked-text-box";
|
|
85
|
+
|
|
86
|
+
const PHONE_MASK = "(000) 000-0000";
|
|
87
|
+
|
|
88
|
+
@Component({
|
|
89
|
+
selector: "app-masked-textbox-phone-example",
|
|
90
|
+
imports: [FormFieldComponent, MaskedTextBoxComponent],
|
|
91
|
+
templateUrl: "./phone-example.component.html"
|
|
92
|
+
})
|
|
93
|
+
export class MaskedTextboxPhoneExampleComponent {
|
|
94
|
+
protected readonly mask = PHONE_MASK;
|
|
95
|
+
protected readonly phone = signal("5551234567");
|
|
96
|
+
// Autofill offers a number in the national format the mask takes.
|
|
97
|
+
protected readonly phoneAttributes = { autocomplete: "tel-national" };
|
|
98
|
+
protected readonly shown = computed(() => formatMaskedValue(this.phone(), PHONE_MASK));
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`phone-example.component.html`
|
|
103
|
+
|
|
104
|
+
```html
|
|
105
|
+
<div class="flex max-w-xs flex-col gap-3">
|
|
106
|
+
<mona-form-field label="Phone" hint="10 digits, such as (555) 123-4567.">
|
|
107
|
+
<mona-masked-text-box
|
|
108
|
+
[mask]="mask"
|
|
109
|
+
[clearButton]="true"
|
|
110
|
+
[inputAttributes]="phoneAttributes"
|
|
111
|
+
[(value)]="phone" />
|
|
112
|
+
</mona-form-field>
|
|
113
|
+
<dl class="grid grid-cols-[auto_1fr] gap-x-3 text-sm">
|
|
114
|
+
<dt class="text-muted-foreground">Value</dt>
|
|
115
|
+
<dd>{{ phone() || "empty" }}</dd>
|
|
116
|
+
<dt class="text-muted-foreground">Formatted</dt>
|
|
117
|
+
<dd>{{ shown() || "empty" }}</dd>
|
|
118
|
+
</dl>
|
|
119
|
+
</div>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Checking the value is complete
|
|
123
|
+
|
|
124
|
+
`isMaskComplete` tells a validator whether every required slot is filled, and the validator can check more, such as that the month is from 01 to 12. Once touched, the box shows as invalid while it's partly filled, and the form field shows the validator's message.
|
|
125
|
+
|
|
126
|
+
`validation-example.component.ts`
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { Component, signal } from "@angular/core";
|
|
130
|
+
import { form, FormField, required, submit, validate } from "@angular/forms/signals";
|
|
131
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
132
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
133
|
+
import { isMaskComplete, MaskedTextBoxComponent } from "@nanahoshi/mona-ui/masked-text-box";
|
|
134
|
+
|
|
135
|
+
const EXPIRY_MASK = "00/00";
|
|
136
|
+
|
|
137
|
+
@Component({
|
|
138
|
+
selector: "app-masked-textbox-validation-example",
|
|
139
|
+
imports: [ButtonDirective, FormField, FormFieldComponent, MaskedTextBoxComponent],
|
|
140
|
+
templateUrl: "./validation-example.component.html"
|
|
141
|
+
})
|
|
142
|
+
export class MaskedTextboxValidationExampleComponent {
|
|
143
|
+
readonly #model = signal({ expiry: "" });
|
|
144
|
+
protected readonly card = form(this.#model, path => {
|
|
145
|
+
required(path.expiry, { message: "Enter the expiry date." });
|
|
146
|
+
validate(path.expiry, ({ value }) => {
|
|
147
|
+
const expiry = value();
|
|
148
|
+
// An empty field is left to required, which has its own message.
|
|
149
|
+
if (expiry === "") {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
if (!isMaskComplete(expiry, EXPIRY_MASK)) {
|
|
153
|
+
return { kind: "incomplete", message: "Enter the month and the year, such as 08/29." };
|
|
154
|
+
}
|
|
155
|
+
const month = Number(expiry.slice(0, 2));
|
|
156
|
+
return month >= 1 && month <= 12 ? undefined : { kind: "month", message: "Enter a month from 01 to 12." };
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
protected readonly mask = EXPIRY_MASK;
|
|
160
|
+
protected readonly saved = signal(false);
|
|
161
|
+
|
|
162
|
+
protected onSubmit(event: Event): void {
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
void submit(this.card, async () => {
|
|
165
|
+
this.saved.set(true);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
`validation-example.component.html`
|
|
172
|
+
|
|
173
|
+
```html
|
|
174
|
+
<form class="flex max-w-xs flex-col gap-4" novalidate (submit)="onSubmit($event)">
|
|
175
|
+
<mona-form-field label="Expiry date" hint="Month and year, as on the card.">
|
|
176
|
+
<mona-masked-text-box placeholder="MM/YY" class="w-28" [mask]="mask" [formField]="card.expiry" />
|
|
177
|
+
</mona-form-field>
|
|
178
|
+
<div class="flex items-center gap-3">
|
|
179
|
+
<button monaButton look="primary" type="submit">Save card</button>
|
|
180
|
+
@if (saved()) {
|
|
181
|
+
<span class="text-sm" role="status">Saved.</span>
|
|
182
|
+
}
|
|
183
|
+
</div>
|
|
184
|
+
</form>
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### A format of your own
|
|
188
|
+
|
|
189
|
+
A rule for `H` takes a hexadecimal digit, and `\#` puts a literal hash sign first. With `includeLiterals`, the value is a CSS color, which the suffix shows once all six digits are in.
|
|
190
|
+
|
|
191
|
+
`custom-rules-example.component.ts`
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { Component, computed, signal } from "@angular/core";
|
|
195
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
196
|
+
import {
|
|
197
|
+
isMaskComplete,
|
|
198
|
+
MaskedTextBoxComponent,
|
|
199
|
+
MaskedTextBoxSuffixTemplateDirective,
|
|
200
|
+
type MaskRules
|
|
201
|
+
} from "@nanahoshi/mona-ui/masked-text-box";
|
|
202
|
+
|
|
203
|
+
// "#" is a mask character, so the backslash makes it the literal the color starts with.
|
|
204
|
+
const COLOR_MASK = "\\#HHHHHH";
|
|
205
|
+
const COLOR_RULES: MaskRules = { H: /[0-9a-f]/i };
|
|
206
|
+
|
|
207
|
+
@Component({
|
|
208
|
+
selector: "app-masked-textbox-custom-rules-example",
|
|
209
|
+
imports: [FormFieldComponent, MaskedTextBoxComponent, MaskedTextBoxSuffixTemplateDirective],
|
|
210
|
+
templateUrl: "./custom-rules-example.component.html"
|
|
211
|
+
})
|
|
212
|
+
export class MaskedTextboxCustomRulesExampleComponent {
|
|
213
|
+
protected readonly color = signal("#7c3aed");
|
|
214
|
+
protected readonly mask = COLOR_MASK;
|
|
215
|
+
protected readonly rules = COLOR_RULES;
|
|
216
|
+
/** The swatch shows the color once all six digits are in. */
|
|
217
|
+
protected readonly swatch = computed(() =>
|
|
218
|
+
isMaskComplete(this.color(), COLOR_MASK, { includeLiterals: true, rules: COLOR_RULES }) ? this.color() : null
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
`custom-rules-example.component.html`
|
|
224
|
+
|
|
225
|
+
```html
|
|
226
|
+
<div class="flex max-w-xs flex-col gap-3">
|
|
227
|
+
<mona-form-field label="Brand color" hint="A hex color: six digits from 0 to 9 and A to F.">
|
|
228
|
+
<mona-masked-text-box class="w-40" [mask]="mask" [rules]="rules" [includeLiterals]="true" [(value)]="color">
|
|
229
|
+
<ng-template monaMaskedTextBoxSuffixTemplate>
|
|
230
|
+
<span
|
|
231
|
+
aria-hidden="true"
|
|
232
|
+
class="me-2 size-5 rounded-sm border border-border forced-color-adjust-none"
|
|
233
|
+
[style.background-color]="swatch()"></span>
|
|
234
|
+
</ng-template>
|
|
235
|
+
</mona-masked-text-box>
|
|
236
|
+
</mona-form-field>
|
|
237
|
+
<p class="text-sm">Value: {{ color() || "empty" }}</p>
|
|
238
|
+
</div>
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Appearance & Styling
|
|
242
|
+
|
|
243
|
+
The masked text box has the sizes and corner roundings of the [text box](textbox.md): `size` is `small`, `medium` (default) or `large`, and `rounded` is `none`, `small`, `medium` (default), `large` or `full`.
|
|
244
|
+
|
|
245
|
+
| Input | What it shows |
|
|
246
|
+
|-------|---------------|
|
|
247
|
+
| `prompt` | The character in each empty slot, `_` by default |
|
|
248
|
+
| `placeholder` | Text in place of the mask while the box is empty and doesn't have focus |
|
|
249
|
+
| `clearButton` | A button that empties the value |
|
|
250
|
+
|
|
251
|
+
The rest of the mask is drawn in the muted text color, and in forced colors in the system's gray text color. The field is always left to right, in a right-to-left page too, since phone numbers and codes read that way.
|
|
252
|
+
|
|
253
|
+
`class` is merged onto the box and `inputClass` onto the input, through `tailwind-merge`. The box fills its container, so set a width that fits the mask, such as `class="w-40"`.
|
|
254
|
+
|
|
255
|
+
## Behavior
|
|
256
|
+
|
|
257
|
+
### Typing and deleting
|
|
258
|
+
|
|
259
|
+
- A character goes into the slot at the caret, or the next one after the literals. A character the slot doesn't take is turned down, and a literal typed where the mask has it, such as a space or a dash, moves past it.
|
|
260
|
+
- Typing over a filled slot replaces it. Slots keep their places, so nothing moves along as you type or delete in the middle.
|
|
261
|
+
- Backspace empties the slot before the caret, past any literals, and Delete the slot after it. Deleting a word empties the group of slots between two literals.
|
|
262
|
+
- Pasted text is fitted in from the caret, skipping what doesn't fit, so `555.123.4567` and `555-123-4567` both fill `(000) 000-0000`.
|
|
263
|
+
- Cut copies the selection as it shows, then empties its slots.
|
|
264
|
+
- Undo and redo go through the box's own history, since the browser's would go back to text the box replaced. A run of typing undoes in one step.
|
|
265
|
+
- Text an input method composes, and text autofill writes, are fitted in once they're done.
|
|
266
|
+
- On touch devices, a mask of only digits brings up the number keyboard. An `inputmode` in `inputAttributes` replaces it.
|
|
267
|
+
|
|
268
|
+
### The value
|
|
269
|
+
|
|
270
|
+
- The value is the characters in the slots, up to the last one filled, with a space for an empty slot before it. With `includeLiterals`, it has the literals between them too: `(55 ) 123-4567` once the third digit is deleted. The literals at the end of a mask, such as ` kg` in `000 kg`, come along once its last slot is filled.
|
|
271
|
+
- A value set from outside that lines up with the mask fills the slots in place. One that doesn't, such as `555-123-4567` without `includeLiterals`, is fitted in as a paste would be and written back as it reads.
|
|
272
|
+
- An empty box's value is `""`. ngModel's first `null` reads as empty, and isn't written back.
|
|
273
|
+
- `focus()` puts the caret at the first empty slot.
|
|
274
|
+
|
|
275
|
+
## Forms Integration
|
|
276
|
+
|
|
277
|
+
The masked text box is a signal forms control: bind it with `[formField]`, and the form writes its disabled, read-only, required, invalid and touched states. `ngModel` and `formControl` work too.
|
|
278
|
+
|
|
279
|
+
The box doesn't add errors to the form. Once touched, it shows as invalid while it's partly filled, but a validator has to say so, to stop the form from submitting and to give a message. `isMaskComplete` takes the value, the mask and the box's `includeLiterals` and `rules`:
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
const PHONE_MASK = "(000) 000-0000";
|
|
283
|
+
|
|
284
|
+
protected readonly contact = form(this.#model, path => {
|
|
285
|
+
validate(path.phone, ({ value }) =>
|
|
286
|
+
value() === "" || isMaskComplete(value(), PHONE_MASK)
|
|
287
|
+
? undefined
|
|
288
|
+
: { kind: "mask", message: "Enter all 10 digits." }
|
|
289
|
+
);
|
|
290
|
+
});
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## Accessibility
|
|
294
|
+
|
|
295
|
+
- The input is a native text input. Name it with `mona-form-field`, a `mona-label` whose `for` points at it, or `aria-label`.
|
|
296
|
+
- Give the format in a hint, with an example, such as "10 digits, such as (555) 123-4567". The rest of the mask is hidden from assistive technology, so the hint is what tells screen reader users the format, and it helps everyone else too.
|
|
297
|
+
- Screen readers read what's typed and the literals up to it, not the prompts after it. A slot emptied in the middle reads as its prompt character.
|
|
298
|
+
- A character a slot turns down is announced politely with what the slot takes, such as "Only a digit fits here".
|
|
299
|
+
- Once touched, a partly filled box has `aria-invalid="true"`, and so does one the form marks invalid. Pair it with a message: the form field shows the validator's.
|
|
300
|
+
- In forced colors, the rest of the mask is drawn in the system's gray text color and the focus outline stays visible.
|
|
301
|
+
- Use a mask only for a format that really is fixed. One that doesn't fit someone's real value, such as a phone number from another country, leaves them no way to enter it.
|
|
302
|
+
|
|
303
|
+
| Key | Action |
|
|
304
|
+
|-----|--------|
|
|
305
|
+
| A character | Fills the slot at the caret, or is turned down |
|
|
306
|
+
| `Backspace` | Empties the slot before the caret |
|
|
307
|
+
| `Delete` | Empties the slot after the caret |
|
|
308
|
+
| `Ctrl` + `Backspace` / `Option` + `Backspace` | Empties the group of slots before the caret |
|
|
309
|
+
| `Ctrl` + `Z` / `Cmd` + `Z` | Undoes the last edit |
|
|
310
|
+
| `Ctrl` + `Y` / `Cmd` + `Shift` + `Z` | Redoes it |
|
|
311
|
+
|
|
312
|
+
The announcement and the clear button's name are in the `maskedTextBox` messages: `characterNotAllowed`, `clear`, `digitOnly`, `digitOrSignOnly`, `letterOnly` and `letterOrDigitOnly`.
|
|
313
|
+
|
|
314
|
+
## API
|
|
315
|
+
|
|
316
|
+
Everything below is imported from `@nanahoshi/mona-ui/masked-text-box`. Each name links to its reference page, with every input, output, property and method.
|
|
317
|
+
|
|
318
|
+
| Name | Kind | Description |
|
|
319
|
+
| --- | --- | --- |
|
|
320
|
+
| [`MaskedTextBoxComponent`](api/masked-text-box.md#maskedtextboxcomponent) | Component | A text box that takes a value in a fixed format, such as a phone number or a postal code. |
|
|
321
|
+
| [`MaskedTextBoxPrefixTemplateDirective`](api/masked-text-box.md#maskedtextboxprefixtemplatedirective) | Directive | Marks an `<ng-template>` as content before the masked text box's input, such as an icon or a country code. |
|
|
322
|
+
| [`MaskedTextBoxSuffixTemplateDirective`](api/masked-text-box.md#maskedtextboxsuffixtemplatedirective) | Directive | Marks an `<ng-template>` as content after the masked text box's input and its clear button, such as a unit or a button. |
|
|
323
|
+
| [`formatMaskedValue`](api/masked-text-box.md#formatmaskedvalue) | Function | Formats a value for display with its mask's literals, such as `"5551234567"` as `"(555) 123-4567"` for the mask `"(000) 000-0000"`. |
|
|
324
|
+
| [`isMaskComplete`](api/masked-text-box.md#ismaskcomplete) | Function | Whether a value fills every required slot of a mask, for a validator. |
|
|
325
|
+
|
|
326
|
+
### Types
|
|
327
|
+
|
|
328
|
+
| Type | Kind | Description |
|
|
329
|
+
| --- | --- | --- |
|
|
330
|
+
| [`MASKED_TEXT_BOX_DEFAULT_MESSAGES`](api/masked-text-box.md#masked-text-box-default-messages) | Constant | |
|
|
331
|
+
| [`MaskOptions`](api/masked-text-box.md#maskoptions) | Interface | How a value is read against a mask, for `isMaskComplete` and `formatMaskedValue`. |
|
|
332
|
+
| [`MaskRules`](api/masked-text-box.md#maskrules) | Type alias | Mask characters of your own, each mapped to a pattern that one character must match, such as `{ H: /[0-9a-f]/i }` for a hexadecimal digit. |
|
|
333
|
+
|
|
334
|
+
**Related types:** [`AttributeConfig`](api/common.md#attributeconfig), [`MonaMaskedTextBoxMessages`](api/i18n.md#monamaskedtextboxmessages)
|
package/docs/multi-select.md
CHANGED
|
@@ -126,6 +126,63 @@ export class MultiSelectCheckboxesExampleComponent {
|
|
|
126
126
|
</div>
|
|
127
127
|
```
|
|
128
128
|
|
|
129
|
+
### Selecting every option at once
|
|
130
|
+
|
|
131
|
+
`showSelectAll` puts a "Select all" option first in the popup. It selects every enabled option the filter leaves, and once they're all selected, deselects them. Its checkbox shows a dash while only some of them are selected. Options that are disabled keep their state, so Legal here stays out.
|
|
132
|
+
|
|
133
|
+
`select-all-example.component.ts`
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { Component, signal } from "@angular/core";
|
|
137
|
+
import { DropdownFilterableDirective } from "@nanahoshi/mona-ui/dropdowns";
|
|
138
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
139
|
+
import { MultiSelectComponent } from "@nanahoshi/mona-ui/multi-select";
|
|
140
|
+
|
|
141
|
+
interface Team {
|
|
142
|
+
readonly archived?: boolean;
|
|
143
|
+
readonly id: string;
|
|
144
|
+
readonly name: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@Component({
|
|
148
|
+
selector: "app-multi-select-select-all-example",
|
|
149
|
+
imports: [DropdownFilterableDirective, FormFieldComponent, MultiSelectComponent],
|
|
150
|
+
templateUrl: "./select-all-example.component.html"
|
|
151
|
+
})
|
|
152
|
+
export class MultiSelectSelectAllExampleComponent {
|
|
153
|
+
protected readonly notified = signal<string[]>(["design"]);
|
|
154
|
+
protected readonly teams: readonly Team[] = [
|
|
155
|
+
{ id: "design", name: "Design" },
|
|
156
|
+
{ id: "engineering", name: "Engineering" },
|
|
157
|
+
{ id: "finance", name: "Finance" },
|
|
158
|
+
{ archived: true, id: "legal", name: "Legal" },
|
|
159
|
+
{ id: "marketing", name: "Marketing" },
|
|
160
|
+
{ id: "sales", name: "Sales" },
|
|
161
|
+
{ id: "support", name: "Support" }
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`select-all-example.component.html`
|
|
167
|
+
|
|
168
|
+
```html
|
|
169
|
+
<div class="flex max-w-sm flex-col gap-2">
|
|
170
|
+
<mona-form-field label="Notify" hint="Legal is archived and can't be notified.">
|
|
171
|
+
<mona-multi-select
|
|
172
|
+
monaDropDownFilterable
|
|
173
|
+
textField="name"
|
|
174
|
+
valueField="id"
|
|
175
|
+
itemDisabled="archived"
|
|
176
|
+
[valuePrimitive]="true"
|
|
177
|
+
[checkboxes]="true"
|
|
178
|
+
[showSelectAll]="true"
|
|
179
|
+
[data]="teams"
|
|
180
|
+
[(value)]="notified" />
|
|
181
|
+
</mona-form-field>
|
|
182
|
+
<span aria-live="polite" class="text-sm">{{ notified().length }} of {{ teams.length }} teams</span>
|
|
183
|
+
</div>
|
|
184
|
+
```
|
|
185
|
+
|
|
129
186
|
### Collapsing tags into a summary
|
|
130
187
|
|
|
131
188
|
Apply `monaMultiSelectSummaryTag` to collapse tags beyond `tagCount` into a single summary chip (default text: "+N items"). A negative `tagCount` (the default) shows every selected item as its own tag and never renders the summary chip. `monaMultiSelectSummaryTagTemplate` replaces the summary chip's text.
|
|
@@ -395,6 +452,13 @@ Set `autoClose` to `true` to close the popup after each selection instead of kee
|
|
|
395
452
|
|
|
396
453
|
With nothing highlighted, such as when the filter matches no option, Enter in the filter box does nothing, and leaves the selection as it is. With `allowCustomValue`, it adds the typed text, unless an option was reached with the arrow keys since the text last changed: then it toggles that option, as it would without custom values. `allowCustomValue` without `monaDropDownFilterable` has nowhere to type, and warns in development.
|
|
397
454
|
|
|
455
|
+
### Select all
|
|
456
|
+
|
|
457
|
+
- "Select all" covers the options the filter leaves, so filtering and then choosing it adds only those, and keeps the options already selected. Choosing it again, once all of those are selected, deselects only those.
|
|
458
|
+
- It has a checkbox whether or not `checkboxes` is set, and it reads as selected once every option it covers is selected.
|
|
459
|
+
- It's left out while the filter leaves no enabled option, and with `autoClose` the popup closes after it as after any option.
|
|
460
|
+
- It counts among the options, in the position screen readers announce. Its text is the multi-select's `selectAll` message.
|
|
461
|
+
|
|
398
462
|
### `showClearButton` clears every selection
|
|
399
463
|
|
|
400
464
|
`showClearButton` renders a single clear button that removes all selected items at once, not one at a time.
|
|
@@ -427,6 +491,8 @@ With nothing highlighted, such as when the filter matches no option, Enter in th
|
|
|
427
491
|
| `Backspace` | Remove the most recently selected tag. |
|
|
428
492
|
| `Escape` / `Tab` | Close the popup. |
|
|
429
493
|
|
|
494
|
+
With `showSelectAll`, "Select all" is the first option in the list, so the arrow keys reach it as they reach any other, wrapping included. `Enter` on it selects or deselects the options it covers.
|
|
495
|
+
|
|
430
496
|
### Focus
|
|
431
497
|
|
|
432
498
|
The host element is the only Tab stop; DOM focus does not move into the popup's option list, and tags are not individually focusable (`tabindex="-1"` on each chip). Arrow-key navigation moves an internal highlighted-option pointer, reflected through `aria-activedescendant` on the host element, instead.
|
|
@@ -916,6 +916,14 @@ const MONA_MESSAGE_PARAMETERS = {
|
|
|
916
916
|
type: "string"
|
|
917
917
|
}]
|
|
918
918
|
},
|
|
919
|
+
maskedTextBox: {
|
|
920
|
+
characterNotAllowed: null,
|
|
921
|
+
clear: null,
|
|
922
|
+
digitOnly: null,
|
|
923
|
+
digitOrSignOnly: null,
|
|
924
|
+
letterOnly: null,
|
|
925
|
+
letterOrDigitOnly: null
|
|
926
|
+
},
|
|
919
927
|
multiSelect: {
|
|
920
928
|
clear: null,
|
|
921
929
|
itemsCount: [{
|
|
@@ -925,7 +933,8 @@ const MONA_MESSAGE_PARAMETERS = {
|
|
|
925
933
|
removeMoreItems: [{
|
|
926
934
|
name: "count",
|
|
927
935
|
type: "number"
|
|
928
|
-
}]
|
|
936
|
+
}],
|
|
937
|
+
selectAll: null
|
|
929
938
|
},
|
|
930
939
|
notification: {
|
|
931
940
|
close: null,
|