@xsolla/xui-input-phone 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 +199 -22
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,41 +1,218 @@
1
- # @xsolla/xui-input-phone
1
+ ---
2
+ title: Input Phone
3
+ subtitle: A phone number input with country selector.
4
+ description: A cross-platform React phone input with country dropdown, dial codes, and searchable country list.
5
+ ---
2
6
 
3
- Phone number input with country selector dropdown and searchable country list.
7
+ # Input Phone
8
+
9
+ A cross-platform React phone number input component with integrated country selector. Features a searchable country dropdown with flags and dial codes.
4
10
 
5
11
  ## Installation
6
12
 
7
13
  ```bash
14
+ npm install @xsolla/xui-input-phone
15
+ # or
8
16
  yarn add @xsolla/xui-input-phone
9
17
  ```
10
18
 
11
- ## Usage
19
+ ## Demo
20
+
21
+ ### Basic Phone Input
22
+
23
+ ```tsx
24
+ import * as React from 'react';
25
+ import { InputPhone } from '@xsolla/xui-input-phone';
26
+
27
+ export default function BasicPhoneInput() {
28
+ const [phone, setPhone] = React.useState('');
29
+
30
+ return (
31
+ <InputPhone
32
+ value={phone}
33
+ onChange={(e) => setPhone(e.target.value)}
34
+ placeholder="+1 (000) 000-0000"
35
+ />
36
+ );
37
+ }
38
+ ```
39
+
40
+ ### With Country Selection
12
41
 
13
42
  ```tsx
14
- import { InputPhone, defaultCountries } from '@xsolla/xui-input-phone';
43
+ import * as React from 'react';
44
+ import { InputPhone, Country } from '@xsolla/xui-input-phone';
45
+
46
+ export default function CountryPhoneInput() {
47
+ const [phone, setPhone] = React.useState('');
48
+ const [country, setCountry] = React.useState<Country | undefined>();
49
+
50
+ return (
51
+ <InputPhone
52
+ value={phone}
53
+ onChange={(e) => setPhone(e.target.value)}
54
+ selectedCountry={country}
55
+ onCountryChange={setCountry}
56
+ />
57
+ );
58
+ }
59
+ ```
60
+
61
+ ### With Validation
62
+
63
+ ```tsx
64
+ import * as React from 'react';
65
+ import { InputPhone } from '@xsolla/xui-input-phone';
66
+
67
+ export default function ValidatedPhoneInput() {
68
+ const [phone, setPhone] = React.useState('');
69
+ const isValid = phone.length >= 10;
70
+
71
+ return (
72
+ <InputPhone
73
+ value={phone}
74
+ onChange={(e) => setPhone(e.target.value)}
75
+ checked={isValid}
76
+ extraClear={true}
77
+ onRemove={() => setPhone('')}
78
+ />
79
+ );
80
+ }
81
+ ```
82
+
83
+ ## Anatomy
84
+
85
+ ```jsx
86
+ import { InputPhone } from '@xsolla/xui-input-phone';
15
87
 
16
88
  <InputPhone
17
- value={phone}
18
- onChange={(e) => setPhone(e.target.value)}
19
- selectedCountry={country}
20
- onCountryChange={setCountry}
21
- countries={defaultCountries}
89
+ value={phoneNumber} // Phone number value
90
+ onChange={handleChange} // Change event handler
91
+ selectedCountry={country} // Currently selected country
92
+ onCountryChange={setCountry} // Country selection handler
93
+ countries={customCountries} // Custom countries array
94
+ placeholder="+1 (000) 000-0000" // Placeholder text
95
+ size="md" // Size variant
96
+ disabled={false} // Disabled state
97
+ error={false} // Error state
98
+ errorMessage="Error" // Error message
99
+ extraClear={false} // Show clear button
100
+ onRemove={handleClear} // Clear button handler
101
+ checked={false} // Show validation checkmark
22
102
  />
23
103
  ```
24
104
 
25
- ## Props
105
+ ## Examples
106
+
107
+ ### Error State
108
+
109
+ ```tsx
110
+ import * as React from 'react';
111
+ import { InputPhone } from '@xsolla/xui-input-phone';
112
+
113
+ export default function ErrorPhoneInput() {
114
+ return (
115
+ <InputPhone
116
+ value="123"
117
+ error={true}
118
+ errorMessage="Please enter a valid phone number"
119
+ />
120
+ );
121
+ }
122
+ ```
123
+
124
+ ### Phone Input Sizes
125
+
126
+ ```tsx
127
+ import * as React from 'react';
128
+ import { InputPhone } from '@xsolla/xui-input-phone';
129
+
130
+ export default function PhoneInputSizes() {
131
+ return (
132
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
133
+ <InputPhone size="xs" placeholder="Extra Small" />
134
+ <InputPhone size="sm" placeholder="Small" />
135
+ <InputPhone size="md" placeholder="Medium" />
136
+ <InputPhone size="lg" placeholder="Large" />
137
+ <InputPhone size="xl" placeholder="Extra Large" />
138
+ </div>
139
+ );
140
+ }
141
+ ```
142
+
143
+ ### Custom Countries
144
+
145
+ ```tsx
146
+ import * as React from 'react';
147
+ import { InputPhone, Country } from '@xsolla/xui-input-phone';
148
+
149
+ export default function CustomCountriesPhone() {
150
+ const [phone, setPhone] = React.useState('');
151
+
152
+ const countries: Country[] = [
153
+ { code: 'US', name: 'United States', dialCode: '+1' },
154
+ { code: 'GB', name: 'United Kingdom', dialCode: '+44' },
155
+ { code: 'DE', name: 'Germany', dialCode: '+49' },
156
+ ];
157
+
158
+ return (
159
+ <InputPhone
160
+ value={phone}
161
+ onChange={(e) => setPhone(e.target.value)}
162
+ countries={countries}
163
+ />
164
+ );
165
+ }
166
+ ```
167
+
168
+ ## API Reference
26
169
 
27
170
  ### InputPhone
28
171
 
172
+ **InputPhone Props:**
173
+
29
174
  | Prop | Type | Default | Description |
30
- |------|------|---------|-------------|
31
- | `value` | `string` | | Controlled phone number value |
32
- | `placeholder` | `string` | `'+1 (000) 000-0000'` | Placeholder text |
33
- | `onChange` | `(e: ChangeEvent) => void` | | Change handler |
34
- | `onChangeText` | `(text: string) => void` | | Alternative change handler receiving the string value |
35
- | `size` | `'xl' \| 'lg' \| 'md' \| 'sm' \| 'xs'` | `'md'` | Input size |
36
- | `disabled` | `boolean` | `false` | Disables the input and country selector |
37
- | `errorMessage` | `string` | | Error text displayed below; also sets invalid state |
38
- | `error` | `boolean` | | Sets invalid state without a message |
39
- | `countries` | `Country[]` | All 200+ countries | Countries shown in the dropdown |
40
- | `selectedCountry` | `Country` | | Currently selected country |
41
- | `onCountryChange` | `(country: Country) => void` | | Called when a country is selected |
175
+ | :--- | :--- | :------ | :---------- |
176
+ | value | `string` | - | Phone number value. |
177
+ | onChange | `(e: ChangeEvent) => void` | - | Change event handler. |
178
+ | onChangeText | `(text: string) => void` | - | Text change handler. |
179
+ | countries | `Country[]` | All countries | Available countries for selection. |
180
+ | selectedCountry | `Country` | - | Currently selected country. |
181
+ | onCountryChange | `(country: Country) => void` | - | Country selection handler. |
182
+ | placeholder | `string` | `"+1 (000) 000-0000"` | Placeholder text. |
183
+ | size | `"xl" \| "lg" \| "md" \| "sm" \| "xs"` | `"md"` | Component size. |
184
+ | disabled | `boolean` | `false` | Disabled state. |
185
+ | error | `boolean` | `false` | Error state. |
186
+ | errorMessage | `string` | - | Error message text. |
187
+ | extraClear | `boolean` | `false` | Show clear button. |
188
+ | onRemove | `() => void` | - | Clear button handler. |
189
+ | checked | `boolean` | `false` | Show validation checkmark. |
190
+ | checkedIcon | `ReactNode` | Check icon | Custom checkmark icon. |
191
+ | testID | `string` | - | Test identifier. |
192
+
193
+ **Country Interface:**
194
+
195
+ ```typescript
196
+ interface Country {
197
+ code: string; // ISO 3166-1 alpha-2 (e.g., "US")
198
+ name: string; // Country name
199
+ dialCode: string; // International dial code (e.g., "+1")
200
+ flag?: ReactNode; // Optional flag icon
201
+ }
202
+ ```
203
+
204
+ ## Keyboard Navigation
205
+
206
+ | Key | Action |
207
+ | :-- | :----- |
208
+ | Arrow Down | Open dropdown / Next country |
209
+ | Arrow Up | Previous country |
210
+ | Enter | Select country / Open dropdown |
211
+ | Escape | Close dropdown |
212
+
213
+ ## Accessibility
214
+
215
+ - Country selector uses `role="combobox"`
216
+ - Country list uses `role="listbox"` with `role="option"` items
217
+ - Searchable dropdown with `aria-controls` linking
218
+ - Phone input uses `type="tel"` and `inputMode="tel"`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsolla/xui-input-phone",
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,8 +13,8 @@
13
13
  "test:coverage": "vitest run --coverage"
14
14
  },
15
15
  "dependencies": {
16
- "@xsolla/xui-core": "0.99.0",
17
- "@xsolla/xui-primitives-core": "0.99.0",
16
+ "@xsolla/xui-core": "0.100.0",
17
+ "@xsolla/xui-primitives-core": "0.100.0",
18
18
  "libphonenumber-js": "^1.10.56"
19
19
  },
20
20
  "peerDependencies": {