@tangible/ui 0.2.45 → 0.2.47
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/components/PasswordInput/PasswordInput.d.ts +7 -0
- package/components/PasswordInput/PasswordInput.js +64 -0
- package/components/PasswordInput/index.d.ts +3 -0
- package/components/PasswordInput/index.js +2 -0
- package/components/PasswordInput/types.d.ts +45 -0
- package/components/PasswordInput/types.js +6 -0
- package/components/PasswordStrength/PasswordStrength.d.ts +7 -0
- package/components/PasswordStrength/PasswordStrength.js +73 -0
- package/components/PasswordStrength/index.d.ts +3 -0
- package/components/PasswordStrength/index.js +2 -0
- package/components/PasswordStrength/types.d.ts +36 -0
- package/components/PasswordStrength/types.js +4 -0
- package/components/SecretInput/SecretInput.js +10 -33
- package/components/index.d.ts +4 -0
- package/components/index.js +2 -0
- package/figma-tokens.json +1 -1
- package/icons/icons.svg +1 -1
- package/icons/sprite-version.js +1 -1
- package/icons/sprite.php +1 -1
- package/package.json +9 -1
- package/skills/building-with-tui/SKILL.md +11 -3
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +108 -0
- package/styles/all.expanded.unlayered.css +108 -0
- package/styles/all.unlayered.css +1 -1
- package/styles/components/_bundle.scss +7 -1
- package/styles/components/password-input.scss +24 -0
- package/styles/components/password-strength.scss +95 -0
- package/styles/components/secret-input.scss +1 -65
- package/styles/system/_reveal.scss +82 -0
- package/styles/system/index.scss +1 -0
- package/tui-manifest.json +161 -2
- package/utils/reveal/RevealToggle.d.ts +32 -0
- package/utils/reveal/RevealToggle.js +57 -0
- package/utils/reveal/index.d.ts +3 -0
- package/utils/reveal/index.js +4 -0
- package/utils/reveal/useReveal.d.ts +26 -0
- package/utils/reveal/useReveal.js +55 -0
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
@use "./move-handle" as movehandle;
|
|
28
28
|
@use "./notice" as notice;
|
|
29
29
|
@use "./overlap-stack" as overlapstack;
|
|
30
|
+
@use "./password-input" as passwordinput;
|
|
31
|
+
@use "./password-strength" as passwordstrength;
|
|
30
32
|
@use "./pager" as pager;
|
|
31
33
|
@use "./popover" as popover;
|
|
32
34
|
@use "./radio" as radio;
|
|
@@ -65,7 +67,7 @@
|
|
|
65
67
|
// search-input (its panel embeds one). The dependents mechanism below only
|
|
66
68
|
// covers the input core; extend it to full dependency sets if subset builds
|
|
67
69
|
// become a real workflow (Pager has the same latent gap).
|
|
68
|
-
$-input-dependents: (input, field, text-input, textarea, pager, search-input, search-select, secret-input, gradient-picker);
|
|
70
|
+
$-input-dependents: (input, field, text-input, textarea, pager, search-input, search-select, secret-input, password-input, gradient-picker);
|
|
69
71
|
|
|
70
72
|
@function -needs-input($only) {
|
|
71
73
|
@if $only == null {
|
|
@@ -118,6 +120,10 @@ $-input-dependents: (input, field, text-input, textarea, pager, search-input, se
|
|
|
118
120
|
@if -wants($only, notice) { @include notice.styles(); }
|
|
119
121
|
@if -wants($only, overlap-stack) { @include overlapstack.styles(); }
|
|
120
122
|
@if -wants($only, pager) { @include pager.styles(); }
|
|
123
|
+
// password-input wears .tui-input-group (pulled in above) and its reveal
|
|
124
|
+
// button is a system mixin, so it needs nothing else requested.
|
|
125
|
+
@if -wants($only, password-input) { @include passwordinput.styles(); }
|
|
126
|
+
@if -wants($only, password-strength) { @include passwordstrength.styles(); }
|
|
121
127
|
@if -wants($only, popover) { @include popover.styles(); }
|
|
122
128
|
@if -wants($only, radio) { @include radio.styles(); }
|
|
123
129
|
@if -wants($only, rating) { @include rating.styles(); }
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
@use "../system" as sys;
|
|
2
|
+
|
|
3
|
+
/* @tui-tokens
|
|
4
|
+
--tui-password-input-button-radius
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// =============================================================================
|
|
8
|
+
// PasswordInput Styles
|
|
9
|
+
// =============================================================================
|
|
10
|
+
//
|
|
11
|
+
// The field is the shared input group (see TextInput styles). The only bespoke
|
|
12
|
+
// part is the reveal toggle, the system `reveal-button` mixin SecretInput
|
|
13
|
+
// wears too, so the two stay identical.
|
|
14
|
+
//
|
|
15
|
+
// Component API tokens (never defined here, only read via fallback):
|
|
16
|
+
// --tui-password-input-button-radius Reveal button hit-area radius
|
|
17
|
+
//
|
|
18
|
+
// =============================================================================
|
|
19
|
+
|
|
20
|
+
@mixin styles() {
|
|
21
|
+
:where(.#{sys.$prefix}interface) .#{sys.$prefix}password-input__reveal {
|
|
22
|
+
@include sys.reveal-button(--#{sys.$prefix}password-input-button-radius);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
@use "../system" as sys;
|
|
2
|
+
|
|
3
|
+
/* @tui-tokens
|
|
4
|
+
--tui-password-strength-track
|
|
5
|
+
--tui-password-strength-weak
|
|
6
|
+
--tui-password-strength-fair
|
|
7
|
+
--tui-password-strength-strong
|
|
8
|
+
--tui-password-strength-bar-size
|
|
9
|
+
--tui-password-strength-gap
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// =============================================================================
|
|
13
|
+
// PasswordStrength Styles
|
|
14
|
+
// =============================================================================
|
|
15
|
+
//
|
|
16
|
+
// Four bars and a line of text. The bars are decoration: the words carry the
|
|
17
|
+
// score, so colour is never the only signal. `data-score` (0 to 4, absent
|
|
18
|
+
// when there's none) is the styling hook.
|
|
19
|
+
//
|
|
20
|
+
// Component API tokens (never defined here, only read via fallback):
|
|
21
|
+
// --tui-password-strength-track Unlit bar
|
|
22
|
+
// --tui-password-strength-weak Lit bars at scores 0 and 1
|
|
23
|
+
// --tui-password-strength-fair Lit bars at score 2
|
|
24
|
+
// --tui-password-strength-strong Lit bars at scores 3 and 4
|
|
25
|
+
// --tui-password-strength-bar-size Bar thickness
|
|
26
|
+
// --tui-password-strength-gap Between bars
|
|
27
|
+
//
|
|
28
|
+
// =============================================================================
|
|
29
|
+
|
|
30
|
+
@mixin styles() {
|
|
31
|
+
.#{sys.$prefix}interface .#{sys.$prefix}password-strength {
|
|
32
|
+
--_fill: var(--#{sys.$prefix}password-strength-weak, var(--#{sys.$prefix}theme-danger-base));
|
|
33
|
+
|
|
34
|
+
// No margin of its own: where it sits is the consumer's (className), and
|
|
35
|
+
// inside a Field the field's own gap spaces it
|
|
36
|
+
display: flex;
|
|
37
|
+
flex-direction: column;
|
|
38
|
+
gap: var(--#{sys.$prefix}spacing-xxs);
|
|
39
|
+
|
|
40
|
+
// Scores 0 and 1 are weak (the default above), 2 fair, 3 and 4 strong
|
|
41
|
+
&[data-score="2"] {
|
|
42
|
+
--_fill: var(--#{sys.$prefix}password-strength-fair, var(--#{sys.$prefix}theme-warning-base));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&[data-score="3"],
|
|
46
|
+
&[data-score="4"] {
|
|
47
|
+
--_fill: var(--#{sys.$prefix}password-strength-strong, var(--#{sys.$prefix}theme-success-base));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.#{sys.$prefix}interface .#{sys.$prefix}password-strength__bars {
|
|
52
|
+
display: grid;
|
|
53
|
+
grid-template-columns: repeat(4, minmax(0, 1fr));
|
|
54
|
+
gap: var(--#{sys.$prefix}password-strength-gap, var(--#{sys.$prefix}spacing-xxs));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.#{sys.$prefix}interface .#{sys.$prefix}password-strength__bar {
|
|
58
|
+
block-size: var(--#{sys.$prefix}password-strength-bar-size, var(--#{sys.$prefix}spacing-xxs));
|
|
59
|
+
border-radius: var(--#{sys.$prefix}radius-full, 9999px);
|
|
60
|
+
background: var(--#{sys.$prefix}password-strength-track, var(--#{sys.$prefix}color-fill));
|
|
61
|
+
transition: background-color var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing);
|
|
62
|
+
|
|
63
|
+
&[data-lit="true"] {
|
|
64
|
+
background: var(--_fill);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Backgrounds vanish under forced colours: draw the bars in system colours
|
|
68
|
+
@media (forced-colors: active) {
|
|
69
|
+
forced-color-adjust: none;
|
|
70
|
+
background: Canvas;
|
|
71
|
+
border: var(--#{sys.$prefix}border-width) solid GrayText;
|
|
72
|
+
|
|
73
|
+
&[data-lit="true"] {
|
|
74
|
+
background: CanvasText;
|
|
75
|
+
border-color: CanvasText;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.#{sys.$prefix}interface .#{sys.$prefix}password-strength__text {
|
|
81
|
+
margin: 0;
|
|
82
|
+
color: var(--#{sys.$prefix}color-fg-secondary);
|
|
83
|
+
font-size: var(--#{sys.$prefix}typography-size-sm);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.#{sys.$prefix}interface .#{sys.$prefix}password-strength__score {
|
|
87
|
+
color: var(--#{sys.$prefix}color-fg);
|
|
88
|
+
font-weight: var(--#{sys.$prefix}typography-weight-semibold);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Its own line under the score
|
|
92
|
+
.#{sys.$prefix}interface .#{sys.$prefix}password-strength__feedback {
|
|
93
|
+
display: block;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -87,70 +87,6 @@
|
|
|
87
87
|
|
|
88
88
|
// Reveal toggle. Mirrors SearchInput's owned in-field buttons.
|
|
89
89
|
:where(.#{sys.$prefix}interface) .#{sys.$prefix}secret-input__reveal {
|
|
90
|
-
|
|
91
|
-
align-items: center;
|
|
92
|
-
justify-content: center;
|
|
93
|
-
flex: none;
|
|
94
|
-
// Hit-area floor: em-relative padding alone lands ~21px at size="sm"
|
|
95
|
-
// (14px control font), under the 24x24 WCAG 2.5.8 minimum. The glyph still
|
|
96
|
-
// sizes with the control text inside the padded box.
|
|
97
|
-
min-inline-size: 1.5rem;
|
|
98
|
-
min-block-size: 1.5rem;
|
|
99
|
-
padding: 0.1875em;
|
|
100
|
-
// ...but a 24px box plus the group's own padding-block overflows the sm
|
|
101
|
-
// control height (24 + 8 + 2 = 34 against a 32px floor), which is exactly
|
|
102
|
-
// the "a sm Button and a sm field in the same row won't line up" bug. Let
|
|
103
|
-
// the target eat the group's padding instead of adding to it: the hit area
|
|
104
|
-
// stays 24px, the control stays on the ladder. (SearchInput's identical
|
|
105
|
-
// buttons still have the 34px version — tracked as a follow-up.)
|
|
106
|
-
margin-block: calc(-1 * var(--_py, var(--#{sys.$prefix}spacing-xxs)));
|
|
107
|
-
border: 0;
|
|
108
|
-
border-radius: var(--#{sys.$prefix}secret-input-button-radius, var(--#{sys.$prefix}radius-full, 999px));
|
|
109
|
-
background: transparent;
|
|
110
|
-
color: var(--#{sys.$prefix}color-fg-secondary);
|
|
111
|
-
cursor: pointer;
|
|
112
|
-
line-height: 0;
|
|
113
|
-
transition-duration: var(--#{sys.$prefix}motion-duration);
|
|
114
|
-
transition-timing-function: var(--#{sys.$prefix}motion-timing);
|
|
115
|
-
transition-property: color, background-color, outline-color;
|
|
116
|
-
|
|
117
|
-
.#{sys.$prefix}icon {
|
|
118
|
-
font-size: 1.125em;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
@media (hover: hover) {
|
|
122
|
-
&:hover {
|
|
123
|
-
color: var(--#{sys.$prefix}color-fg);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
&:focus-visible {
|
|
128
|
-
color: var(--#{sys.$prefix}color-fg);
|
|
129
|
-
outline: var(--#{sys.$prefix}focus-ring-width) solid var(--#{sys.$prefix}focus-ring-color);
|
|
130
|
-
outline-offset: var(--#{sys.$prefix}focus-ring-offset);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Revealed is a state worth seeing at a glance — the field is showing a
|
|
134
|
-
// secret in the clear. Keyed off data-revealed rather than aria-pressed:
|
|
135
|
-
// the button communicates state through its accessible NAME (see the
|
|
136
|
-
// component), so there is no aria-pressed to hang styling on.
|
|
137
|
-
&[data-revealed="true"] {
|
|
138
|
-
background-color: var(--#{sys.$prefix}color-fill-subtle);
|
|
139
|
-
color: var(--#{sys.$prefix}color-fg);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Forced-colors: a transparent button is invisible without a system colour.
|
|
143
|
-
@media (forced-colors: active) {
|
|
144
|
-
color: ButtonText;
|
|
145
|
-
|
|
146
|
-
&[data-revealed="true"] {
|
|
147
|
-
background-color: Highlight;
|
|
148
|
-
color: HighlightText;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
&:focus-visible {
|
|
152
|
-
outline-color: Highlight;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
90
|
+
@include sys.reveal-button(--#{sys.$prefix}secret-input-button-radius);
|
|
155
91
|
}
|
|
156
92
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
@use "constants" as sys;
|
|
2
|
+
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// Reveal button — the show/hide toggle in a masked field's suffix
|
|
5
|
+
// =============================================================================
|
|
6
|
+
//
|
|
7
|
+
// Worn by SecretInput (`tui-secret-input__reveal`) and PasswordInput
|
|
8
|
+
// (`tui-password-input__reveal`), so the two can't drift. Its React half is
|
|
9
|
+
// src/utils/reveal (RevealToggle + useReveal).
|
|
10
|
+
//
|
|
11
|
+
//
|
|
12
|
+
// - Include it on a button inside a `.tui-input-group` suffix: its
|
|
13
|
+
// `margin-block` reads the group's private `--_py` (from control-sizing).
|
|
14
|
+
// - `$radius-token` is the host's own radius knob, as an unquoted custom
|
|
15
|
+
// property name: `@include sys.reveal-button(--#{sys.$prefix}password-input-button-radius);`
|
|
16
|
+
@mixin reveal-button($radius-token) {
|
|
17
|
+
display: inline-flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
flex: none;
|
|
21
|
+
// Hit-area floor: em-relative padding alone lands ~21px at size="sm"
|
|
22
|
+
// (14px control font), under the 24x24 WCAG 2.5.8 minimum. The glyph still
|
|
23
|
+
// sizes with the control text inside the padded box.
|
|
24
|
+
min-inline-size: 1.5rem;
|
|
25
|
+
min-block-size: 1.5rem;
|
|
26
|
+
padding: 0.1875em;
|
|
27
|
+
// ...but a 24px box plus the group's own padding-block overflows the sm
|
|
28
|
+
// control height (24 + 8 + 2 = 34 against a 32px floor), which is exactly
|
|
29
|
+
// the "a sm Button and a sm field in the same row won't line up" bug. Let
|
|
30
|
+
// the target eat the group's padding instead of adding to it: the hit area
|
|
31
|
+
// stays 24px, the control stays on the ladder. (SearchInput's identical
|
|
32
|
+
// buttons still have the 34px version — tracked as a follow-up.)
|
|
33
|
+
margin-block: calc(-1 * var(--_py, var(--#{sys.$prefix}spacing-xxs)));
|
|
34
|
+
border: 0;
|
|
35
|
+
border-radius: var(#{$radius-token}, var(--#{sys.$prefix}radius-full, 999px));
|
|
36
|
+
background: transparent;
|
|
37
|
+
color: var(--#{sys.$prefix}color-fg-secondary);
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
line-height: 0;
|
|
40
|
+
transition-duration: var(--#{sys.$prefix}motion-duration);
|
|
41
|
+
transition-timing-function: var(--#{sys.$prefix}motion-timing);
|
|
42
|
+
transition-property: color, background-color, outline-color;
|
|
43
|
+
|
|
44
|
+
.#{sys.$prefix}icon {
|
|
45
|
+
font-size: 1.125em;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@media (hover: hover) {
|
|
49
|
+
&:hover {
|
|
50
|
+
color: var(--#{sys.$prefix}color-fg);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&:focus-visible {
|
|
55
|
+
color: var(--#{sys.$prefix}color-fg);
|
|
56
|
+
outline: var(--#{sys.$prefix}focus-ring-width) solid var(--#{sys.$prefix}focus-ring-color);
|
|
57
|
+
outline-offset: var(--#{sys.$prefix}focus-ring-offset);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Revealed is a state worth seeing at a glance — the field is showing a
|
|
61
|
+
// secret in the clear. Keyed off data-revealed rather than aria-pressed:
|
|
62
|
+
// the button communicates state through its accessible NAME (see the
|
|
63
|
+
// component), so there is no aria-pressed to hang styling on.
|
|
64
|
+
&[data-revealed="true"] {
|
|
65
|
+
background-color: var(--#{sys.$prefix}color-fill-subtle);
|
|
66
|
+
color: var(--#{sys.$prefix}color-fg);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Forced-colors: a transparent button is invisible without a system colour.
|
|
70
|
+
@media (forced-colors: active) {
|
|
71
|
+
color: ButtonText;
|
|
72
|
+
|
|
73
|
+
&[data-revealed="true"] {
|
|
74
|
+
background-color: Highlight;
|
|
75
|
+
color: HighlightText;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
&:focus-visible {
|
|
79
|
+
outline-color: Highlight;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
package/styles/system/index.scss
CHANGED
package/tui-manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
3
|
-
"generated": "2026-11-
|
|
2
|
+
"version": "0.2.47",
|
|
3
|
+
"generated": "2026-11-22T22:31:06.685Z",
|
|
4
4
|
"components": {
|
|
5
5
|
"Accordion": {
|
|
6
6
|
"props": {
|
|
@@ -2783,6 +2783,165 @@
|
|
|
2783
2783
|
"use": null,
|
|
2784
2784
|
"notFor": null
|
|
2785
2785
|
},
|
|
2786
|
+
"PasswordInput": {
|
|
2787
|
+
"props": {
|
|
2788
|
+
"size": {
|
|
2789
|
+
"type": "\"sm\" | \"md\" | \"lg\"",
|
|
2790
|
+
"required": false,
|
|
2791
|
+
"defaultValue": "'md'",
|
|
2792
|
+
"description": "Control size."
|
|
2793
|
+
},
|
|
2794
|
+
"disabled": {
|
|
2795
|
+
"type": "boolean",
|
|
2796
|
+
"required": false
|
|
2797
|
+
},
|
|
2798
|
+
"onChange": {
|
|
2799
|
+
"type": "ChangeEventHandler<HTMLInputElement>",
|
|
2800
|
+
"required": false
|
|
2801
|
+
},
|
|
2802
|
+
"className": {
|
|
2803
|
+
"type": "string",
|
|
2804
|
+
"required": false,
|
|
2805
|
+
"description": "Additional class name applied to the root wrapper element."
|
|
2806
|
+
},
|
|
2807
|
+
"id": {
|
|
2808
|
+
"type": "string",
|
|
2809
|
+
"required": false
|
|
2810
|
+
},
|
|
2811
|
+
"style": {
|
|
2812
|
+
"type": "CSSProperties",
|
|
2813
|
+
"required": false
|
|
2814
|
+
},
|
|
2815
|
+
"title": {
|
|
2816
|
+
"type": "string",
|
|
2817
|
+
"required": false
|
|
2818
|
+
},
|
|
2819
|
+
"role": {
|
|
2820
|
+
"type": "AriaRole",
|
|
2821
|
+
"required": false
|
|
2822
|
+
},
|
|
2823
|
+
"rel": {
|
|
2824
|
+
"type": "string",
|
|
2825
|
+
"required": false
|
|
2826
|
+
},
|
|
2827
|
+
"onClick": {
|
|
2828
|
+
"type": "MouseEventHandler<HTMLInputElement>",
|
|
2829
|
+
"required": false
|
|
2830
|
+
},
|
|
2831
|
+
"inputClassName": {
|
|
2832
|
+
"type": "string",
|
|
2833
|
+
"required": false,
|
|
2834
|
+
"description": "Class name applied directly to the `<input>` element.\nUse for utilities like `tui-input-reset` (removes browser-native search\ndecoration, clear buttons, and spinners) that must target the input itself."
|
|
2835
|
+
},
|
|
2836
|
+
"purpose": {
|
|
2837
|
+
"type": "\"current\" | \"new\"",
|
|
2838
|
+
"required": true,
|
|
2839
|
+
"description": "`current` to sign in or confirm who you are; `new` to choose a password\n(sign up, reset, change). Sets `autocomplete` to `current-password` or\n`new-password`."
|
|
2840
|
+
},
|
|
2841
|
+
"revealed": {
|
|
2842
|
+
"type": "boolean",
|
|
2843
|
+
"required": false,
|
|
2844
|
+
"description": "Controlled: whether the password shows as text"
|
|
2845
|
+
},
|
|
2846
|
+
"defaultRevealed": {
|
|
2847
|
+
"type": "boolean",
|
|
2848
|
+
"required": false,
|
|
2849
|
+
"defaultValue": "false",
|
|
2850
|
+
"description": "Uncontrolled: start shown."
|
|
2851
|
+
}
|
|
2852
|
+
},
|
|
2853
|
+
"cssTokens": [
|
|
2854
|
+
"--tui-password-input-button-radius"
|
|
2855
|
+
],
|
|
2856
|
+
"story": {
|
|
2857
|
+
"title": "Forms/PasswordInput",
|
|
2858
|
+
"tags": [
|
|
2859
|
+
"autodocs",
|
|
2860
|
+
"stable"
|
|
2861
|
+
]
|
|
2862
|
+
},
|
|
2863
|
+
"subcomponents": null,
|
|
2864
|
+
"description": null,
|
|
2865
|
+
"gotchas": null,
|
|
2866
|
+
"examples": null,
|
|
2867
|
+
"related": null,
|
|
2868
|
+
"use": null,
|
|
2869
|
+
"notFor": null
|
|
2870
|
+
},
|
|
2871
|
+
"PasswordStrength": {
|
|
2872
|
+
"props": {
|
|
2873
|
+
"className": {
|
|
2874
|
+
"type": "string",
|
|
2875
|
+
"required": false
|
|
2876
|
+
},
|
|
2877
|
+
"id": {
|
|
2878
|
+
"type": "string",
|
|
2879
|
+
"required": false
|
|
2880
|
+
},
|
|
2881
|
+
"style": {
|
|
2882
|
+
"type": "CSSProperties",
|
|
2883
|
+
"required": false
|
|
2884
|
+
},
|
|
2885
|
+
"title": {
|
|
2886
|
+
"type": "string",
|
|
2887
|
+
"required": false
|
|
2888
|
+
},
|
|
2889
|
+
"role": {
|
|
2890
|
+
"type": "AriaRole",
|
|
2891
|
+
"required": false
|
|
2892
|
+
},
|
|
2893
|
+
"rel": {
|
|
2894
|
+
"type": "string",
|
|
2895
|
+
"required": false
|
|
2896
|
+
},
|
|
2897
|
+
"onChange": {
|
|
2898
|
+
"type": "FormEventHandler<HTMLDivElement>",
|
|
2899
|
+
"required": false
|
|
2900
|
+
},
|
|
2901
|
+
"onClick": {
|
|
2902
|
+
"type": "MouseEventHandler<HTMLDivElement>",
|
|
2903
|
+
"required": false
|
|
2904
|
+
},
|
|
2905
|
+
"score": {
|
|
2906
|
+
"type": "0 | 1 | 2 | 3 | 4",
|
|
2907
|
+
"required": false,
|
|
2908
|
+
"description": "The estimate, 0 to 4. Leave it out while the field is empty, or while an\nestimator is still loading: the meter then shows no score and says\nnothing. Anything but a whole number from 0 to 4 counts as no score."
|
|
2909
|
+
},
|
|
2910
|
+
"feedback": {
|
|
2911
|
+
"type": "string",
|
|
2912
|
+
"required": false,
|
|
2913
|
+
"description": "What would make it stronger: \"Add another word or two.\""
|
|
2914
|
+
},
|
|
2915
|
+
"announce": {
|
|
2916
|
+
"type": "boolean",
|
|
2917
|
+
"required": false,
|
|
2918
|
+
"defaultValue": "true",
|
|
2919
|
+
"description": "Say the score through a polite live region a second after it settles on\na new value. Only the score: the hint is read with the field. Off, both\nare still read with the field, through `aria-describedby` on the input.\nRender the meter from the first paint, even with no score, so the region\nexists before it has anything to say."
|
|
2920
|
+
}
|
|
2921
|
+
},
|
|
2922
|
+
"cssTokens": [
|
|
2923
|
+
"--tui-password-strength-track",
|
|
2924
|
+
"--tui-password-strength-weak",
|
|
2925
|
+
"--tui-password-strength-fair",
|
|
2926
|
+
"--tui-password-strength-strong",
|
|
2927
|
+
"--tui-password-strength-bar-size",
|
|
2928
|
+
"--tui-password-strength-gap"
|
|
2929
|
+
],
|
|
2930
|
+
"story": {
|
|
2931
|
+
"title": "Forms/PasswordStrength",
|
|
2932
|
+
"tags": [
|
|
2933
|
+
"autodocs",
|
|
2934
|
+
"stable"
|
|
2935
|
+
]
|
|
2936
|
+
},
|
|
2937
|
+
"subcomponents": null,
|
|
2938
|
+
"description": null,
|
|
2939
|
+
"gotchas": null,
|
|
2940
|
+
"examples": null,
|
|
2941
|
+
"related": null,
|
|
2942
|
+
"use": null,
|
|
2943
|
+
"notFor": null
|
|
2944
|
+
},
|
|
2786
2945
|
"Popover": {
|
|
2787
2946
|
"props": {
|
|
2788
2947
|
"open": {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
export interface RevealToggleProps {
|
|
3
|
+
revealed: boolean;
|
|
4
|
+
onToggle: () => void;
|
|
5
|
+
/** The name while masked: "Show password" */
|
|
6
|
+
revealLabel: string;
|
|
7
|
+
/** The name while shown: "Hide password" */
|
|
8
|
+
hideLabel: string;
|
|
9
|
+
/** From useReveal: said once per change */
|
|
10
|
+
announcement: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** The host's own class for the button, e.g. `tui-secret-input__reveal` */
|
|
13
|
+
className: string;
|
|
14
|
+
inputRef: RefObject<HTMLInputElement | null>;
|
|
15
|
+
/** The host's root class, for "is focus still inside the field?" */
|
|
16
|
+
rootClassName: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The show/hide button in a masked field's suffix, shared by SecretInput and
|
|
20
|
+
* PasswordInput. @internal
|
|
21
|
+
*
|
|
22
|
+
* The name flips rather than staying constant with aria-pressed. For "is my
|
|
23
|
+
* secret on screen right now", a name is announced reliably by every AT where
|
|
24
|
+
* aria-pressed is not (VoiceOver with Safari especially), and stays
|
|
25
|
+
* unambiguous on AT that ignores the state. Deliberately not both: a flipping
|
|
26
|
+
* name plus aria-pressed reads as "Hide password, pressed".
|
|
27
|
+
*
|
|
28
|
+
* Pointerdown is prevented so focus stays in the field. That means a mouse
|
|
29
|
+
* click never focuses the button, so neither its name nor its state is read;
|
|
30
|
+
* the polite status region says what changed instead.
|
|
31
|
+
*/
|
|
32
|
+
export declare function RevealToggle({ revealed, onToggle, revealLabel, hideLabel, announcement, disabled, className, inputRef, rootClassName, }: RevealToggleProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLayoutEffect, useRef } from 'react';
|
|
3
|
+
import { Icon } from '../../components/Icon/index.js';
|
|
4
|
+
import { View as ViewIcon, ViewOff as ViewOffIcon } from '../../icons/system/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* The show/hide button in a masked field's suffix, shared by SecretInput and
|
|
7
|
+
* PasswordInput. @internal
|
|
8
|
+
*
|
|
9
|
+
* The name flips rather than staying constant with aria-pressed. For "is my
|
|
10
|
+
* secret on screen right now", a name is announced reliably by every AT where
|
|
11
|
+
* aria-pressed is not (VoiceOver with Safari especially), and stays
|
|
12
|
+
* unambiguous on AT that ignores the state. Deliberately not both: a flipping
|
|
13
|
+
* name plus aria-pressed reads as "Hide password, pressed".
|
|
14
|
+
*
|
|
15
|
+
* Pointerdown is prevented so focus stays in the field. That means a mouse
|
|
16
|
+
* click never focuses the button, so neither its name nor its state is read;
|
|
17
|
+
* the polite status region says what changed instead.
|
|
18
|
+
*/
|
|
19
|
+
export function RevealToggle({ revealed, onToggle, revealLabel, hideLabel, announcement, disabled, className, inputRef, rootClassName, }) {
|
|
20
|
+
// Swapping `type` resets the caret to the start in Chromium, so someone
|
|
21
|
+
// checking a character mid-password would carry on typing at the front.
|
|
22
|
+
// Keep the selection across the swap, while the field has focus.
|
|
23
|
+
const selection = useRef(null);
|
|
24
|
+
useLayoutEffect(() => {
|
|
25
|
+
const input = inputRef.current;
|
|
26
|
+
const saved = selection.current;
|
|
27
|
+
selection.current = null;
|
|
28
|
+
if (!input || !saved || input.ownerDocument.activeElement !== input)
|
|
29
|
+
return;
|
|
30
|
+
try {
|
|
31
|
+
// Chromium resets the selection when it rebuilds the field for the new
|
|
32
|
+
// type, at the next layout, which is after this effect. Force that
|
|
33
|
+
// layout now, so the restore lands after the reset, not before it.
|
|
34
|
+
void input.offsetWidth;
|
|
35
|
+
input.setSelectionRange(saved[0], saved[1], saved[2] ?? undefined);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Some input types refuse selection ranges; the caret just stays put
|
|
39
|
+
}
|
|
40
|
+
}, [revealed, inputRef]);
|
|
41
|
+
const handleClick = () => {
|
|
42
|
+
const field = inputRef.current;
|
|
43
|
+
if (field && field.ownerDocument.activeElement === field) {
|
|
44
|
+
selection.current = [field.selectionStart, field.selectionEnd, field.selectionDirection];
|
|
45
|
+
}
|
|
46
|
+
onToggle();
|
|
47
|
+
// Pointer activation leaves focus wherever it was, including on <body> if
|
|
48
|
+
// nothing was focused, which strands the user at the top of the document.
|
|
49
|
+
// Recover only in that case: on keyboard activation focus is already on
|
|
50
|
+
// the button, and stealing it would break the toggle.
|
|
51
|
+
const input = inputRef.current;
|
|
52
|
+
const active = input?.ownerDocument.activeElement;
|
|
53
|
+
if (input && !active?.closest(`.${rootClassName}`))
|
|
54
|
+
input.focus();
|
|
55
|
+
};
|
|
56
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: className, "aria-label": revealed ? hideLabel : revealLabel, "data-revealed": revealed ? 'true' : undefined, disabled: disabled, onClick: handleClick, onPointerDown: (e) => e.preventDefault(), children: _jsx(Icon, { name: revealed ? ViewOffIcon : ViewIcon }) }), _jsx("span", { role: "status", className: "tui-visually-hidden", children: announcement })] }));
|
|
57
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Masked-or-shown state for a field with a reveal toggle (SecretInput,
|
|
3
|
+
* PasswordInput). @internal
|
|
4
|
+
*
|
|
5
|
+
* Controlled or not, decided once at mount like the rest of the family: a
|
|
6
|
+
* component that flips between the two mid-life pollutes its own state.
|
|
7
|
+
*
|
|
8
|
+
* `announcement` is what the toggle's status region says. It's empty until
|
|
9
|
+
* the first change (nothing on mount), and it's cleared again after a few
|
|
10
|
+
* seconds and on any change made without announcing. Otherwise the region
|
|
11
|
+
* keeps saying "Password shown." over a masked field, and the next show
|
|
12
|
+
* sets the same text, which is no change, so it's never announced.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useReveal({ revealed: revealedProp, defaultRevealed, onRevealChange, shown, hidden, }: {
|
|
15
|
+
revealed?: boolean;
|
|
16
|
+
defaultRevealed?: boolean;
|
|
17
|
+
onRevealChange?: (revealed: boolean) => void;
|
|
18
|
+
shown: string;
|
|
19
|
+
hidden: string;
|
|
20
|
+
}): {
|
|
21
|
+
revealed: boolean;
|
|
22
|
+
setRevealed: (next: boolean, { announce }?: {
|
|
23
|
+
announce?: boolean;
|
|
24
|
+
}) => void;
|
|
25
|
+
announcement: string;
|
|
26
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
/** How long a status message stays before it's cleared, as Toast's announcers do */
|
|
3
|
+
const CLEAR_AFTER_MS = 3000;
|
|
4
|
+
/**
|
|
5
|
+
* Masked-or-shown state for a field with a reveal toggle (SecretInput,
|
|
6
|
+
* PasswordInput). @internal
|
|
7
|
+
*
|
|
8
|
+
* Controlled or not, decided once at mount like the rest of the family: a
|
|
9
|
+
* component that flips between the two mid-life pollutes its own state.
|
|
10
|
+
*
|
|
11
|
+
* `announcement` is what the toggle's status region says. It's empty until
|
|
12
|
+
* the first change (nothing on mount), and it's cleared again after a few
|
|
13
|
+
* seconds and on any change made without announcing. Otherwise the region
|
|
14
|
+
* keeps saying "Password shown." over a masked field, and the next show
|
|
15
|
+
* sets the same text, which is no change, so it's never announced.
|
|
16
|
+
*/
|
|
17
|
+
export function useReveal({ revealed: revealedProp, defaultRevealed = false, onRevealChange, shown, hidden, }) {
|
|
18
|
+
const [revealedState, setRevealedState] = useState(defaultRevealed);
|
|
19
|
+
const [isControlled] = useState(revealedProp !== undefined);
|
|
20
|
+
const revealed = isControlled ? !!revealedProp : revealedState;
|
|
21
|
+
const [announcement, setAnnouncement] = useState('');
|
|
22
|
+
const clearTimer = useRef(undefined);
|
|
23
|
+
useEffect(() => () => clearTimeout(clearTimer.current), []);
|
|
24
|
+
// A controlled parent that moves `revealed` itself (or refuses a toggle)
|
|
25
|
+
// makes any message stale: say nothing rather than the wrong thing.
|
|
26
|
+
const announcedFor = useRef(null);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (announcedFor.current !== null && announcedFor.current !== revealed) {
|
|
29
|
+
announcedFor.current = null;
|
|
30
|
+
setAnnouncement('');
|
|
31
|
+
}
|
|
32
|
+
}, [revealed]);
|
|
33
|
+
/** `announce: false` for a change the person didn't ask for (re-masking on submit) */
|
|
34
|
+
const setRevealed = (next, { announce = true } = {}) => {
|
|
35
|
+
if (next === revealed)
|
|
36
|
+
return;
|
|
37
|
+
if (!isControlled)
|
|
38
|
+
setRevealedState(next);
|
|
39
|
+
clearTimeout(clearTimer.current);
|
|
40
|
+
if (announce) {
|
|
41
|
+
announcedFor.current = next;
|
|
42
|
+
setAnnouncement(next ? shown : hidden);
|
|
43
|
+
clearTimer.current = setTimeout(() => {
|
|
44
|
+
announcedFor.current = null;
|
|
45
|
+
setAnnouncement('');
|
|
46
|
+
}, CLEAR_AFTER_MS);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
announcedFor.current = null;
|
|
50
|
+
setAnnouncement('');
|
|
51
|
+
}
|
|
52
|
+
onRevealChange?.(next);
|
|
53
|
+
};
|
|
54
|
+
return { revealed, setRevealed, announcement };
|
|
55
|
+
}
|