@su-labs/fields 0.0.0-stage → 22.1.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/CHANGELOG.md +23 -0
- package/LICENSE +21 -0
- package/README.md +171 -2
- package/fesm2022/su-labs-fields.mjs +963 -0
- package/fesm2022/su-labs-fields.mjs.map +1 -0
- package/package.json +54 -3
- package/types/su-labs-fields.d.ts +335 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [22.1.0] - 2026-11-14
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- `su-lib-email-field`: an email input that checks the address the way people mistype it, says what's wrong once the field is left, shows a tick when it looks right, and suggests a common domain for a likely typo (`gmial.com` → `gmail.com`) applied with one tap; `required`, your own `domains` and `messages`, `validityChange`. The check is exported as `suCheckEmail`
|
|
12
|
+
- `su-lib-checkbox`: a real checkbox whose tick draws itself in, with a squash when pressed and a dash when partly checked; `[(checked)]`, `indeterminate`, `disabled`
|
|
13
|
+
- `su-lib-chips`: toggle chips to pick several options or one (`multiple`), each popping a tick in when picked; typed `[(value)]`, disabled options
|
|
14
|
+
- `su-lib-switch`: a real checkbox (`role="switch"`) drawn as a sliding switch, with a stretching knob, a spring and a tick when on; `[(checked)]`, the label before or after it (`labelPosition`), `small` or `medium`, `disabled`, and `busy` (ignores clicks while saving, then shows the saved value); themed with `--su-switch-*` variables
|
|
15
|
+
|
|
16
|
+
## [22.0.0] - 2026-11-11
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- `SuCodeBoxesComponent` (`su-lib-code-boxes`): a short code typed into boxes that fill one by one and turn green in a wave once complete; one real text field underneath, so pasting, phone keyboards and screen readers work
|
|
20
|
+
- `SuStrengthMeterComponent` (`su-lib-strength-meter`): four bars under a new password that fill and change colour as it gets stronger, with its word per step; a `meter` for screen readers
|
|
21
|
+
- `suPasswordStrength()` and `suStrengthLevel()`: the meter's rule, usable on its own
|
|
22
|
+
- `SuAutoGrowDirective` (`textarea[suAutoGrow]`): a text box that grows a line at a time with a soft spring, and shrinks back when emptied
|
|
23
|
+
- `--su-field-*` CSS variables for colours, and no motion for visitors who ask their device for less
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yevheniy Alekseyev <yev.alekseyev@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,172 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Fields
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@su-labs/fields`
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
Small animated form fields for Angular, built on plain inputs so forms, pasting, phone keyboards and screen readers keep working:
|
|
9
|
+
|
|
10
|
+
- **Code boxes**: a short code typed into boxes that fill one by one, then turn green in a wave once it's complete.
|
|
11
|
+
- **Strength meter**: four bars under a new password that fill and change colour as it gets stronger.
|
|
12
|
+
- **Auto grow**: a text box that grows a line at a time with a soft spring.
|
|
13
|
+
|
|
14
|
+
Every animation stops for visitors who ask their device for less motion.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @su-labs/fields
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Code boxes
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { SuCodeBoxesComponent } from '@su-labs/fields';
|
|
26
|
+
|
|
27
|
+
code = signal('');
|
|
28
|
+
isComplete = computed(() => /^[A-Z0-9]{6}$/.test(this.code()));
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<su-lib-code-boxes [(value)]="code" [length]="6" label="Room code" [complete]="isComplete()" />
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
| Input | Type | |
|
|
36
|
+
|---|---|---|
|
|
37
|
+
| `value` | `string` (two-way) | The code typed so far, in capitals without spaces |
|
|
38
|
+
| `length` | `number` | How many boxes |
|
|
39
|
+
| `label` | `string` | The field's name for screen readers |
|
|
40
|
+
| `complete` | `boolean` | The code is whole and valid: the boxes turn green |
|
|
41
|
+
|
|
42
|
+
## Strength meter
|
|
43
|
+
|
|
44
|
+
```html
|
|
45
|
+
<input #password type="password" autocomplete="new-password" />
|
|
46
|
+
<su-lib-strength-meter
|
|
47
|
+
[field]="password"
|
|
48
|
+
label="Password strength"
|
|
49
|
+
[levelNames]="{ weak: 'Weak', fair: 'Fair', good: 'Good', strong: 'Strong' }"
|
|
50
|
+
[minLength]="10"
|
|
51
|
+
/>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The meter follows the field's typing. If your code empties the field, send it an `input` event so the meter sees it.
|
|
55
|
+
|
|
56
|
+
The rule is exported too: `suPasswordStrength(password, minLength)` gives 0 to 4 bars, and `suStrengthLevel(bars)` its step
|
|
57
|
+
(`weak`, `fair`, `good`, `strong`).
|
|
58
|
+
|
|
59
|
+
## Auto grow
|
|
60
|
+
|
|
61
|
+
```html
|
|
62
|
+
<textarea suAutoGrow rows="2"></textarea>
|
|
63
|
+
<textarea [suAutoGrow]="isOn()" rows="2"></textarea>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
It also shrinks back when its form is reset.
|
|
67
|
+
|
|
68
|
+
## Switch
|
|
69
|
+
|
|
70
|
+
A real checkbox (`role="switch"`) drawn as a sliding switch: the knob stretches while pressed, springs across, and a
|
|
71
|
+
tick pops in when it's on. The label goes inside.
|
|
72
|
+
|
|
73
|
+
```html
|
|
74
|
+
<su-lib-switch [(checked)]="notify">Email me about new games</su-lib-switch>
|
|
75
|
+
|
|
76
|
+
<su-lib-switch labelPosition="start" size="small" [checked]="isPublic()" [busy]="saving()" (checkedChange)="save($event)">
|
|
77
|
+
<strong>Show me on the leaderboard</strong>
|
|
78
|
+
<small>Others see your screen name and best scores</small>
|
|
79
|
+
</su-lib-switch>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
| Input / output | Default | Description |
|
|
83
|
+
|---|---|---|
|
|
84
|
+
| `checked` / `checkedChange` | `false` | Whether it's on; `[(checked)]` binds both ways |
|
|
85
|
+
| `labelPosition` | `'end'` | `'end'`: label after the switch; `'start'`: label first, switch at the end of the row |
|
|
86
|
+
| `size` | `'medium'` | `'small'` or `'medium'` |
|
|
87
|
+
| `disabled` | `false` | |
|
|
88
|
+
| `busy` | `false` | While saving: clicks are ignored and `aria-busy` is set; once done it shows `checked` again, so a change that failed to save flips back |
|
|
89
|
+
|
|
90
|
+
| Variable | Default |
|
|
91
|
+
|---|---|
|
|
92
|
+
| `--su-switch-on` / `--su-switch-tick` | `#111` / `#fff` (the knob and the tick when on) |
|
|
93
|
+
| `--su-switch-track-on` | the on colour at 35% |
|
|
94
|
+
| `--su-switch-knob-off` / `--su-switch-track-off` / `--su-switch-border` | grey / a faint tint / a soft line |
|
|
95
|
+
| `--su-switch-width` / `--su-switch-height` | `3rem` / `1.75rem` (`--su-switch-small-width`, `--su-switch-small-height`: `2.125rem` / `1.25rem`) |
|
|
96
|
+
| `--su-switch-label-weight` / `--su-switch-focus-outline` | `500` / `2px solid currentColor` |
|
|
97
|
+
|
|
98
|
+
## Email field
|
|
99
|
+
|
|
100
|
+
An email input that checks the address the way people mistype it: no @, nothing before or after it, no dot in the
|
|
101
|
+
domain, spaces, or a one-letter ending. It stays quiet while you type and says what's wrong once you leave the field;
|
|
102
|
+
a tick shows when the address looks right. For a likely typo in a common domain it offers the fix, applied with one tap:
|
|
103
|
+
`jo@gmial.com` → "Did you mean jo@gmail.com?"
|
|
104
|
+
|
|
105
|
+
```html
|
|
106
|
+
<su-lib-email-field label="Email" required [(value)]="email" (validityChange)="emailOk.set($event)" />
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
| Input / output | Default | Description |
|
|
110
|
+
|---|---|---|
|
|
111
|
+
| `value` | `''` | The address; `[(value)]` binds both ways |
|
|
112
|
+
| `label` | — | The visible label |
|
|
113
|
+
| `placeholder` | — | |
|
|
114
|
+
| `required` | `false` | An empty field counts as a problem |
|
|
115
|
+
| `domains` | common providers | Domains to suggest for a typo, e.g. your company's |
|
|
116
|
+
| `messages` | English | `Partial<SuEmailMessages>`: the problem texts and "Did you mean" |
|
|
117
|
+
| `validityChange` | — | Whether the address is valid, on every change |
|
|
118
|
+
|
|
119
|
+
The check itself is exported: `suCheckEmail(value, domains?)` gives `{ valid, problem, suggestion }`.
|
|
120
|
+
|
|
121
|
+
## Checkbox
|
|
122
|
+
|
|
123
|
+
A real checkbox whose tick draws itself in, with a small squash when pressed and a dash when partly checked.
|
|
124
|
+
|
|
125
|
+
```html
|
|
126
|
+
<su-lib-checkbox [(checked)]="agree">I agree to the terms</su-lib-checkbox>
|
|
127
|
+
<su-lib-checkbox [checked]="all()" [indeterminate]="some()" (checkedChange)="selectAll($event)">Select all</su-lib-checkbox>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Inputs: `checked` / `checkedChange` (`[(checked)]`), `indeterminate`, `disabled`. Size and tick colour:
|
|
131
|
+
`--su-checkbox-size` (`1.25rem`), `--su-checkbox-tick` (`#fff`); the box uses `--su-field-accent` when checked.
|
|
132
|
+
|
|
133
|
+
## Chips
|
|
134
|
+
|
|
135
|
+
Toggle chips to pick several options, or one with `multiple` off. Each is a button (`aria-pressed`) that pops a tick in
|
|
136
|
+
when picked; the value keeps the options' order and type.
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
categories: readonly SuChipOption<Category>[] = [
|
|
140
|
+
{ value: 'tools', label: 'Tools' },
|
|
141
|
+
{ value: 'garden', label: 'Garden' },
|
|
142
|
+
];
|
|
143
|
+
picked = signal<readonly Category[]>([]);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```html
|
|
147
|
+
<su-lib-chips label="Categories" [options]="categories" [(value)]="picked" />
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Inputs: `options` (`{ value, label, disabled? }`), `value` (`[(value)]`), `label` (the group's name for screen readers),
|
|
151
|
+
`multiple` (`true`). Spacing: `--su-chips-gap` (`0.5rem`).
|
|
152
|
+
|
|
153
|
+
## Theming
|
|
154
|
+
|
|
155
|
+
Set these CSS variables (each has a fallback):
|
|
156
|
+
|
|
157
|
+
| Variable | Used for |
|
|
158
|
+
|---|---|
|
|
159
|
+
| `--su-field-surface` | Box background |
|
|
160
|
+
| `--su-field-border` | Box border |
|
|
161
|
+
| `--su-field-filled-border` | Border of a filled box |
|
|
162
|
+
| `--su-field-text` | Letters in the boxes |
|
|
163
|
+
| `--su-field-accent` | The box the next letter goes into |
|
|
164
|
+
| `--su-field-success`, `--su-field-success-bg` | A complete code, a strong password |
|
|
165
|
+
| `--su-field-warning` | A fair password |
|
|
166
|
+
| `--su-field-danger` | A weak password |
|
|
167
|
+
| `--su-field-track` | Empty meter bars |
|
|
168
|
+
| `--su-field-font-mono` | Letters in the boxes |
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
MIT
|