@xsolla/xui-input-password 0.99.0 → 0.101.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 +213 -24
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,44 +1,233 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Input Password
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A cross-platform React password input component with visibility toggle, validation checkmark, and clear functionality.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
+
npm install @xsolla/xui-input-password
|
|
9
|
+
# or
|
|
8
10
|
yarn add @xsolla/xui-input-password
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
##
|
|
13
|
+
## Demo
|
|
14
|
+
|
|
15
|
+
### Basic Password Input
|
|
12
16
|
|
|
13
17
|
```tsx
|
|
18
|
+
import * as React from 'react';
|
|
19
|
+
import { InputPassword } from '@xsolla/xui-input-password';
|
|
20
|
+
|
|
21
|
+
export default function BasicPassword() {
|
|
22
|
+
const [password, setPassword] = React.useState('');
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<InputPassword
|
|
26
|
+
value={password}
|
|
27
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
28
|
+
placeholder="Enter password"
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### With Visibility Toggle
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import * as React from 'react';
|
|
38
|
+
import { InputPassword } from '@xsolla/xui-input-password';
|
|
39
|
+
|
|
40
|
+
export default function VisibilityToggle() {
|
|
41
|
+
const [password, setPassword] = React.useState('');
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<InputPassword
|
|
45
|
+
value={password}
|
|
46
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
47
|
+
extraSee={true}
|
|
48
|
+
placeholder="Enter password"
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### With Validation
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import * as React from 'react';
|
|
58
|
+
import { InputPassword } from '@xsolla/xui-input-password';
|
|
59
|
+
|
|
60
|
+
export default function PasswordValidation() {
|
|
61
|
+
const [password, setPassword] = React.useState('');
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<InputPassword
|
|
65
|
+
value={password}
|
|
66
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
67
|
+
extraSee={true}
|
|
68
|
+
extraCheckup={(pass) => pass.length >= 8}
|
|
69
|
+
label="Password"
|
|
70
|
+
helperText="At least 8 characters"
|
|
71
|
+
placeholder="Enter password"
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### With Error State
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import * as React from 'react';
|
|
81
|
+
import { InputPassword } from '@xsolla/xui-input-password';
|
|
82
|
+
|
|
83
|
+
export default function PasswordError() {
|
|
84
|
+
const [password, setPassword] = React.useState('');
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<InputPassword
|
|
88
|
+
value={password}
|
|
89
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
90
|
+
extraSee={true}
|
|
91
|
+
error={password.length > 0 && password.length < 8}
|
|
92
|
+
errorMessage="Password must be at least 8 characters"
|
|
93
|
+
label="Password"
|
|
94
|
+
placeholder="Enter password"
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Anatomy
|
|
101
|
+
|
|
102
|
+
```jsx
|
|
14
103
|
import { InputPassword } from '@xsolla/xui-input-password';
|
|
15
104
|
|
|
16
105
|
<InputPassword
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
106
|
+
value={password} // Controlled value
|
|
107
|
+
onChange={handleChange} // Change handler (event)
|
|
108
|
+
onChangeText={handleText} // Change handler (string)
|
|
109
|
+
extraSee={true} // Show visibility toggle
|
|
110
|
+
extraClear={true} // Show clear button
|
|
111
|
+
extraCheckup={validateFn} // Validation function
|
|
112
|
+
label="Label" // Label above input
|
|
113
|
+
helperText="Help text" // Helper text below
|
|
114
|
+
error={boolean} // Error state
|
|
115
|
+
errorMessage="Error" // Error message
|
|
116
|
+
size="md" // Size variant
|
|
117
|
+
disabled={false} // Disabled state
|
|
24
118
|
/>
|
|
25
119
|
```
|
|
26
120
|
|
|
27
|
-
##
|
|
121
|
+
## Examples
|
|
122
|
+
|
|
123
|
+
### Full Featured Password
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
import * as React from 'react';
|
|
127
|
+
import { InputPassword } from '@xsolla/xui-input-password';
|
|
128
|
+
|
|
129
|
+
export default function FullPassword() {
|
|
130
|
+
const [password, setPassword] = React.useState('');
|
|
131
|
+
const [error, setError] = React.useState('');
|
|
132
|
+
|
|
133
|
+
const validatePassword = (pass: string) => {
|
|
134
|
+
if (pass.length < 8) return false;
|
|
135
|
+
if (!/[A-Z]/.test(pass)) return false;
|
|
136
|
+
if (!/[0-9]/.test(pass)) return false;
|
|
137
|
+
return true;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
141
|
+
const value = e.target.value;
|
|
142
|
+
setPassword(value);
|
|
143
|
+
if (value && !validatePassword(value)) {
|
|
144
|
+
setError('Password must be 8+ chars with uppercase and number');
|
|
145
|
+
} else {
|
|
146
|
+
setError('');
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<InputPassword
|
|
152
|
+
value={password}
|
|
153
|
+
onChange={handleChange}
|
|
154
|
+
extraSee={true}
|
|
155
|
+
extraClear={true}
|
|
156
|
+
extraCheckup={validatePassword}
|
|
157
|
+
onRemove={() => setPassword('')}
|
|
158
|
+
label="Password"
|
|
159
|
+
helperText="8+ characters, uppercase, and number required"
|
|
160
|
+
error={!!error}
|
|
161
|
+
errorMessage={error}
|
|
162
|
+
placeholder="Create a strong password"
|
|
163
|
+
/>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Password Sizes
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
import * as React from 'react';
|
|
172
|
+
import { InputPassword } from '@xsolla/xui-input-password';
|
|
173
|
+
|
|
174
|
+
export default function PasswordSizes() {
|
|
175
|
+
return (
|
|
176
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
|
|
177
|
+
<InputPassword size="xs" placeholder="Extra Small" extraSee />
|
|
178
|
+
<InputPassword size="sm" placeholder="Small" extraSee />
|
|
179
|
+
<InputPassword size="md" placeholder="Medium" extraSee />
|
|
180
|
+
<InputPassword size="lg" placeholder="Large" extraSee />
|
|
181
|
+
<InputPassword size="xl" placeholder="Extra Large" extraSee />
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## API Reference
|
|
28
188
|
|
|
29
189
|
### InputPassword
|
|
30
190
|
|
|
191
|
+
**InputPassword Props:**
|
|
192
|
+
|
|
31
193
|
| Prop | Type | Default | Description |
|
|
32
|
-
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
194
|
+
| :--- | :--- | :------ | :---------- |
|
|
195
|
+
| value | `string` | - | Controlled input value. |
|
|
196
|
+
| onChange | `(e: ChangeEvent) => void` | - | Change event handler. |
|
|
197
|
+
| onChangeText | `(text: string) => void` | - | Text change handler. |
|
|
198
|
+
| extraSee | `boolean` | `false` | Show visibility toggle button. |
|
|
199
|
+
| extraClear | `boolean` | `false` | Show clear button. |
|
|
200
|
+
| extraCheckup | `(pass: string) => boolean` | - | Validation function. |
|
|
201
|
+
| initialVisible | `boolean` | `false` | Initial password visibility. |
|
|
202
|
+
| size | `"xl" \| "lg" \| "md" \| "sm" \| "xs"` | `"md"` | Component size. |
|
|
203
|
+
| label | `string` | - | Label above input. |
|
|
204
|
+
| helperText | `string` | - | Helper text below input. |
|
|
205
|
+
| error | `boolean` | `false` | Error state. |
|
|
206
|
+
| errorMessage | `string` | - | Error message. |
|
|
207
|
+
| disabled | `boolean` | `false` | Disabled state. |
|
|
208
|
+
| placeholder | `string` | - | Placeholder text. |
|
|
209
|
+
| name | `string` | - | Input name attribute. |
|
|
210
|
+
| onRemove | `() => void` | - | Clear button handler. |
|
|
211
|
+
| aria-label | `string` | - | Accessible label. |
|
|
212
|
+
| testID | `string` | - | Test identifier. |
|
|
213
|
+
|
|
214
|
+
## Behavior
|
|
215
|
+
|
|
216
|
+
- **Visibility Toggle**: The eye icon reflects the current state of the password:
|
|
217
|
+
- Open eye (👁️) = Password is currently **visible** (type="text")
|
|
218
|
+
- Closed eye (🙈) = Password is currently **hidden** (type="password")
|
|
219
|
+
- This follows modern design system conventions (Material, Apple, Atlassian, Polaris)
|
|
220
|
+
- Checkmark appears when `extraCheckup` returns true
|
|
221
|
+
- Clear button appears when input has value and `extraClear` is true
|
|
222
|
+
- Error state shows red border and error message
|
|
223
|
+
|
|
224
|
+
## Accessibility
|
|
225
|
+
|
|
226
|
+
- Uses `type="password"` or `type="text"` based on visibility
|
|
227
|
+
- Visibility toggle button has appropriate `aria-label`:
|
|
228
|
+
- "Show password" when password is hidden
|
|
229
|
+
- "Hide password" when password is visible
|
|
230
|
+
- Toggle button uses `aria-pressed` to indicate current state
|
|
231
|
+
- Error messages linked via `aria-describedby` for screen reader context
|
|
232
|
+
- Labels properly linked via `aria-labelledby` when provided
|
|
233
|
+
- Error messages use `role="alert"` for immediate announcement
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsolla/xui-input-password",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.101.0",
|
|
4
4
|
"main": "./web/index.js",
|
|
5
5
|
"module": "./web/index.mjs",
|
|
6
6
|
"types": "./web/index.d.ts",
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"test:coverage": "vitest run --coverage"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@xsolla/xui-core": "0.
|
|
17
|
-
"@xsolla/xui-icons": "0.
|
|
18
|
-
"@xsolla/xui-primitives-core": "0.
|
|
16
|
+
"@xsolla/xui-core": "0.101.0",
|
|
17
|
+
"@xsolla/xui-icons": "0.101.0",
|
|
18
|
+
"@xsolla/xui-primitives-core": "0.101.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": ">=16.8.0",
|