@xsolla/xui-input-pin 0.99.0 → 0.100.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.
Files changed (2) hide show
  1. package/README.md +213 -21
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,41 +1,233 @@
1
- # @xsolla/xui-input-pin
1
+ ---
2
+ title: Input Pin
3
+ subtitle: A PIN/OTP code input with individual cells.
4
+ description: A cross-platform React PIN input component with auto-advance, paste support, and flexible width options.
5
+ ---
2
6
 
3
- PIN / OTP input rendered as a row of individual character cells.
7
+ # Input Pin
8
+
9
+ A cross-platform React PIN/OTP input component with individual cells for each digit. Features auto-advance between cells, paste support, and completion callbacks.
4
10
 
5
11
  ## Installation
6
12
 
7
13
  ```bash
14
+ npm install @xsolla/xui-input-pin
15
+ # or
8
16
  yarn add @xsolla/xui-input-pin
9
17
  ```
10
18
 
11
- ## Usage
19
+ ## Demo
20
+
21
+ ### Basic PIN Input
22
+
23
+ ```tsx
24
+ import * as React from 'react';
25
+ import { InputPin } from '@xsolla/xui-input-pin';
26
+
27
+ export default function BasicPinInput() {
28
+ const handleComplete = ({ value, isComplete }) => {
29
+ if (isComplete) {
30
+ console.log('PIN entered:', value);
31
+ }
32
+ };
33
+
34
+ return (
35
+ <InputPin
36
+ codeLength={4}
37
+ onComplete={handleComplete}
38
+ />
39
+ );
40
+ }
41
+ ```
42
+
43
+ ### Six-Digit Code
44
+
45
+ ```tsx
46
+ import * as React from 'react';
47
+ import { InputPin } from '@xsolla/xui-input-pin';
48
+
49
+ export default function SixDigitPin() {
50
+ return (
51
+ <InputPin
52
+ codeLength={6}
53
+ label="Enter verification code"
54
+ onComplete={({ value }) => console.log('Code:', value)}
55
+ />
56
+ );
57
+ }
58
+ ```
59
+
60
+ ### Controlled PIN Input
61
+
62
+ ```tsx
63
+ import * as React from 'react';
64
+ import { InputPin } from '@xsolla/xui-input-pin';
65
+
66
+ export default function ControlledPinInput() {
67
+ const [pin, setPin] = React.useState('');
68
+
69
+ return (
70
+ <div>
71
+ <InputPin
72
+ value={pin}
73
+ codeLength={4}
74
+ onChange={({ value }) => setPin(value)}
75
+ />
76
+ <p>Current value: {pin}</p>
77
+ </div>
78
+ );
79
+ }
80
+ ```
81
+
82
+ ### Secure Entry
12
83
 
13
84
  ```tsx
85
+ import * as React from 'react';
86
+ import { InputPin } from '@xsolla/xui-input-pin';
87
+
88
+ export default function SecurePinInput() {
89
+ return (
90
+ <InputPin
91
+ codeLength={4}
92
+ secureTextEntry={true}
93
+ label="Enter your PIN"
94
+ />
95
+ );
96
+ }
97
+ ```
98
+
99
+ ## Anatomy
100
+
101
+ ```jsx
14
102
  import { InputPin } from '@xsolla/xui-input-pin';
15
103
 
16
104
  <InputPin
17
- codeLength={6}
18
- value={pin}
19
- onChange={({ value }) => setPin(value)}
20
- onComplete={({ value }) => verify(value)}
105
+ value={pinValue} // Controlled value
106
+ onChange={handleChange} // Change handler with {value, isComplete}
107
+ onComplete={handleComplete} // Called when all digits entered
108
+ codeLength={4} // Number of digits
109
+ size="md" // Size variant
110
+ label="Label" // Label above input
111
+ secureTextEntry={false} // Hide entered digits
112
+ showPlaceholderDots={true} // Show dot placeholders
113
+ flexibleWidth={false} // Expand cells to fill width
114
+ disabled={false} // Disabled state
115
+ error={false} // Error state
116
+ errorMessage="Error" // Error message text
21
117
  />
22
118
  ```
23
119
 
24
- ## Props
120
+ ## Examples
121
+
122
+ ### Full Width
123
+
124
+ ```tsx
125
+ import * as React from 'react';
126
+ import { InputPin } from '@xsolla/xui-input-pin';
127
+
128
+ export default function FullWidthPin() {
129
+ return (
130
+ <div style={{ width: 300 }}>
131
+ <InputPin
132
+ codeLength={6}
133
+ flexibleWidth={true}
134
+ label="Verification Code"
135
+ />
136
+ </div>
137
+ );
138
+ }
139
+ ```
140
+
141
+ ### With Error
142
+
143
+ ```tsx
144
+ import * as React from 'react';
145
+ import { InputPin } from '@xsolla/xui-input-pin';
146
+
147
+ export default function ErrorPinInput() {
148
+ return (
149
+ <InputPin
150
+ codeLength={4}
151
+ error={true}
152
+ errorMessage="Invalid PIN. Please try again."
153
+ label="Enter PIN"
154
+ />
155
+ );
156
+ }
157
+ ```
158
+
159
+ ### PIN Input Sizes
160
+
161
+ ```tsx
162
+ import * as React from 'react';
163
+ import { InputPin } from '@xsolla/xui-input-pin';
164
+
165
+ export default function PinInputSizes() {
166
+ return (
167
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 24 }}>
168
+ <InputPin size="xs" codeLength={4} />
169
+ <InputPin size="sm" codeLength={4} />
170
+ <InputPin size="md" codeLength={4} />
171
+ <InputPin size="lg" codeLength={4} />
172
+ <InputPin size="xl" codeLength={4} />
173
+ </div>
174
+ );
175
+ }
176
+ ```
177
+
178
+ ## API Reference
25
179
 
26
180
  ### InputPin
27
181
 
182
+ **InputPin Props:**
183
+
28
184
  | Prop | Type | Default | Description |
29
- |------|------|---------|-------------|
30
- | `value` | `string` | `''` | Controlled value |
31
- | `codeLength` | `number` | `4` | Number of PIN cells |
32
- | `onChange` | `(props: OnInputPinCompleteProps) => void` | | Called on every keystroke with `{ value, isComplete }` |
33
- | `onComplete` | `(props: OnInputPinCompleteProps) => void` | | Called when all cells are filled |
34
- | `size` | `'xl' \| 'lg' \| 'md' \| 'sm' \| 'xs'` | `'md'` | Cell size |
35
- | `disabled` | `boolean` | | Disables all cells |
36
- | `error` | `boolean` | | Sets the error state on all cells |
37
- | `label` | `string` | | Label displayed above the cells |
38
- | `errorMessage` | `string` | | Error text displayed below the cells |
39
- | `secureTextEntry` | `boolean` | `false` | Masks each character |
40
- | `showPlaceholderDots` | `boolean` | `true` | Shows `•` in empty unfocused cells |
41
- | `flexibleWidth` | `boolean` | `false` | Expands cells to fill the container width |
185
+ | :--- | :--- | :------ | :---------- |
186
+ | value | `string` | `""` | Current PIN value. |
187
+ | onChange | `(props: OnInputPinCompleteProps) => void` | - | Called on every change. |
188
+ | onComplete | `(props: OnInputPinCompleteProps) => void` | - | Called when all digits entered. |
189
+ | codeLength | `number` | `4` | Number of PIN digits. |
190
+ | size | `"xl" \| "lg" \| "md" \| "sm" \| "xs"` | `"md"` | Component size. |
191
+ | label | `string` | - | Label above input. |
192
+ | secureTextEntry | `boolean` | `false` | Hide entered digits. |
193
+ | showPlaceholderDots | `boolean` | `true` | Show dot placeholders. |
194
+ | flexibleWidth | `boolean` | `false` | Expand cells to fill container. |
195
+ | disabled | `boolean` | `false` | Disabled state. |
196
+ | error | `boolean` | `false` | Error state. |
197
+ | errorMessage | `string` | - | Error message text. |
198
+ | testID | `string` | - | Test identifier. |
199
+ | aria-label | `string` | - | Accessible label for screen readers. |
200
+
201
+ **OnInputPinCompleteProps:**
202
+
203
+ ```typescript
204
+ interface OnInputPinCompleteProps {
205
+ isComplete: boolean; // Whether all digits are filled
206
+ value: string; // Current PIN value
207
+ }
208
+ ```
209
+
210
+ ## Keyboard Navigation
211
+
212
+ | Key | Action |
213
+ | :-- | :----- |
214
+ | 0-9, A-Z | Enter character and advance |
215
+ | Backspace | Clear current cell and move back |
216
+ | Arrow Left | Move to previous cell |
217
+ | Arrow Right | Move to next cell |
218
+ | Ctrl/Cmd + V | Paste and auto-fill cells |
219
+
220
+ ## Behavior
221
+
222
+ - Auto-advances to next cell after input
223
+ - Supports paste to fill multiple cells
224
+ - Backspace clears current or moves to previous
225
+ - Only alphanumeric characters are accepted
226
+ - Uses `inputMode="numeric"` for mobile keyboards
227
+
228
+ ## Accessibility
229
+
230
+ - Each cell has `aria-label` indicating digit position
231
+ - `role="group"` on container with `aria-labelledby`
232
+ - `aria-invalid` when in error state
233
+ - Error messages linked via `aria-describedby`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsolla/xui-input-pin",
3
- "version": "0.99.0",
3
+ "version": "0.100.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-button": "0.99.0",
17
- "@xsolla/xui-core": "0.99.0",
18
- "@xsolla/xui-primitives-core": "0.99.0"
16
+ "@xsolla/xui-button": "0.100.0",
17
+ "@xsolla/xui-core": "0.100.0",
18
+ "@xsolla/xui-primitives-core": "0.100.0"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "react": ">=16.8.0",