@xsolla/xui-checkbox 0.141.0 → 0.147.1

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 DELETED
@@ -1,292 +0,0 @@
1
- # Checkbox
2
-
3
- A cross-platform React checkbox component with label, description, indeterminate state, and validation support. Works on both React (web) and React Native.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @xsolla/xui-checkbox
9
- # or
10
- yarn add @xsolla/xui-checkbox
11
- ```
12
-
13
- ## Demo
14
-
15
- ### Basic Checkbox
16
-
17
- ```tsx
18
- import * as React from 'react';
19
- import { Checkbox } from '@xsolla/xui-checkbox';
20
-
21
- export default function BasicCheckbox() {
22
- const [checked, setChecked] = React.useState(false);
23
-
24
- return (
25
- <Checkbox
26
- checked={checked}
27
- onChange={(e) => setChecked(e.target.checked)}
28
- >
29
- Accept terms and conditions
30
- </Checkbox>
31
- );
32
- }
33
- ```
34
-
35
- ### Checkbox with Description
36
-
37
- ```tsx
38
- import * as React from 'react';
39
- import { Checkbox } from '@xsolla/xui-checkbox';
40
-
41
- export default function CheckboxWithDescription() {
42
- const [checked, setChecked] = React.useState(false);
43
-
44
- return (
45
- <Checkbox
46
- checked={checked}
47
- onChange={(e) => setChecked(e.target.checked)}
48
- description="You will receive notifications about updates and promotions"
49
- >
50
- Subscribe to newsletter
51
- </Checkbox>
52
- );
53
- }
54
- ```
55
-
56
- ### Checkbox Sizes
57
-
58
- ```tsx
59
- import * as React from 'react';
60
- import { Checkbox } from '@xsolla/xui-checkbox';
61
-
62
- export default function CheckboxSizes() {
63
- return (
64
- <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
65
- <Checkbox size="sm">Small checkbox</Checkbox>
66
- <Checkbox size="md">Medium checkbox (default)</Checkbox>
67
- <Checkbox size="lg">Large checkbox</Checkbox>
68
- <Checkbox size="xl">Extra large checkbox</Checkbox>
69
- </div>
70
- );
71
- }
72
- ```
73
-
74
- ### Indeterminate State
75
-
76
- ```tsx
77
- import * as React from 'react';
78
- import { Checkbox } from '@xsolla/xui-checkbox';
79
-
80
- export default function IndeterminateCheckbox() {
81
- const [items, setItems] = React.useState([
82
- { id: 1, label: 'Item 1', checked: true },
83
- { id: 2, label: 'Item 2', checked: false },
84
- { id: 3, label: 'Item 3', checked: true },
85
- ]);
86
-
87
- const allChecked = items.every((item) => item.checked);
88
- const someChecked = items.some((item) => item.checked);
89
-
90
- const handleSelectAll = () => {
91
- setItems(items.map((item) => ({ ...item, checked: !allChecked })));
92
- };
93
-
94
- return (
95
- <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
96
- <Checkbox
97
- checked={allChecked}
98
- indeterminate={someChecked && !allChecked}
99
- onChange={handleSelectAll}
100
- >
101
- Select all
102
- </Checkbox>
103
- <div style={{ marginLeft: 24, display: 'flex', flexDirection: 'column', gap: 8 }}>
104
- {items.map((item) => (
105
- <Checkbox
106
- key={item.id}
107
- checked={item.checked}
108
- onChange={(e) => {
109
- setItems(items.map((i) =>
110
- i.id === item.id ? { ...i, checked: e.target.checked } : i
111
- ));
112
- }}
113
- >
114
- {item.label}
115
- </Checkbox>
116
- ))}
117
- </div>
118
- </div>
119
- );
120
- }
121
- ```
122
-
123
- ## Anatomy
124
-
125
- Import the component and use it directly:
126
-
127
- ```jsx
128
- import { Checkbox } from '@xsolla/xui-checkbox';
129
-
130
- <Checkbox
131
- checked={checked} // Controlled checked state
132
- onChange={handleChange} // Change handler
133
- indeterminate={false} // Indeterminate/mixed state
134
- size="md" // Size variant
135
- description="Help text" // Description below label
136
- errorMessage="Error text" // Error message
137
- disabled={false} // Disabled state
138
- >
139
- Label text
140
- </Checkbox>
141
- ```
142
-
143
- ## Examples
144
-
145
- ### Error State
146
-
147
- ```tsx
148
- import * as React from 'react';
149
- import { Checkbox } from '@xsolla/xui-checkbox';
150
-
151
- export default function ErrorCheckbox() {
152
- return (
153
- <Checkbox
154
- checked={false}
155
- errorMessage="You must accept the terms to continue"
156
- >
157
- I accept the terms and conditions
158
- </Checkbox>
159
- );
160
- }
161
- ```
162
-
163
- ### Disabled Checkbox
164
-
165
- ```tsx
166
- import * as React from 'react';
167
- import { Checkbox } from '@xsolla/xui-checkbox';
168
-
169
- export default function DisabledCheckbox() {
170
- return (
171
- <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
172
- <Checkbox disabled>Disabled unchecked</Checkbox>
173
- <Checkbox disabled checked>Disabled checked</Checkbox>
174
- </div>
175
- );
176
- }
177
- ```
178
-
179
- ### Form Integration
180
-
181
- ```tsx
182
- import * as React from 'react';
183
- import { Checkbox } from '@xsolla/xui-checkbox';
184
- import { Button } from '@xsolla/xui-button';
185
-
186
- export default function FormCheckbox() {
187
- const [preferences, setPreferences] = React.useState({
188
- marketing: false,
189
- updates: true,
190
- newsletter: false,
191
- });
192
-
193
- const handleChange = (key: string) => (e: { target: { checked: boolean } }) => {
194
- setPreferences((prev) => ({ ...prev, [key]: e.target.checked }));
195
- };
196
-
197
- return (
198
- <form onSubmit={(e) => { e.preventDefault(); console.log(preferences); }}>
199
- <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
200
- <Checkbox
201
- name="marketing"
202
- checked={preferences.marketing}
203
- onChange={handleChange('marketing')}
204
- >
205
- Receive marketing emails
206
- </Checkbox>
207
- <Checkbox
208
- name="updates"
209
- checked={preferences.updates}
210
- onChange={handleChange('updates')}
211
- >
212
- Receive product updates
213
- </Checkbox>
214
- <Checkbox
215
- name="newsletter"
216
- checked={preferences.newsletter}
217
- onChange={handleChange('newsletter')}
218
- >
219
- Subscribe to newsletter
220
- </Checkbox>
221
- <Button type="submit">Save Preferences</Button>
222
- </div>
223
- </form>
224
- );
225
- }
226
- ```
227
-
228
- ## API Reference
229
-
230
- ### Checkbox
231
-
232
- The main checkbox component with label support.
233
-
234
- **Checkbox Props:**
235
-
236
- | Prop | Type | Default | Description |
237
- | :--- | :--- | :------ | :---------- |
238
- | children | `ReactNode` | - | Label content displayed next to the checkbox. |
239
- | checked | `boolean` | `false` | Whether the checkbox is checked. |
240
- | indeterminate | `boolean` | `false` | Whether to show indeterminate (mixed) state. |
241
- | size | `"sm" \| "md" \| "lg" \| "xl"` | `"md"` | Size of the checkbox. |
242
- | disabled | `boolean` | `false` | Whether the checkbox is disabled. |
243
- | description | `string` | - | Description text displayed below the label. |
244
- | errorMessage | `string` | - | Error message displayed below (shows error styling). |
245
- | error | `boolean` | `false` | Show error styling without message. |
246
- | name | `string` | - | HTML name attribute for form submission. |
247
- | value | `string` | - | HTML value attribute for form submission. |
248
- | onChange | `(e: { target: { checked: boolean; name?: string; value?: string } }) => void` | - | Change event handler. |
249
- | id | `string` | - | HTML id attribute. |
250
- | aria-label | `string` | - | Accessible label for screen readers. |
251
-
252
- **Checkbox Ref Methods:**
253
-
254
- | Method | Description |
255
- | :----- | :---------- |
256
- | `focus()` | Programmatically focus the checkbox. |
257
- | `blur()` | Programmatically blur the checkbox. |
258
-
259
- **Size Configuration:**
260
-
261
- | Size | Checkbox | Icon | Font Size | Line Height |
262
- | :--- | :------- | :--- | :-------- | :---------- |
263
- | sm | 16px | 12px | 14px | 16px |
264
- | md | 18px | 14px | 16px | 18px |
265
- | lg | 20px | 16px | 18px | 20px |
266
- | xl | 22px | 18px | 18px | 22px |
267
-
268
- ## Theming
269
-
270
- Checkbox uses the design system theme for colors:
271
-
272
- ```typescript
273
- // Colors accessed via theme
274
- theme.colors.control.checkbox.bg // Unchecked background
275
- theme.colors.control.checkbox.bgChecked // Checked background
276
- theme.colors.control.checkbox.border // Border color
277
- theme.colors.control.checkbox.borderChecked // Checked border
278
- theme.colors.control.checkbox.check // Checkmark color
279
- theme.colors.content.primary // Label text
280
- theme.colors.content.secondary // Description text
281
- theme.colors.content.error // Error text
282
- ```
283
-
284
- ## Accessibility
285
-
286
- - Uses semantic checkbox input with proper labeling
287
- - Supports keyboard navigation (Tab to focus, Space/Enter to toggle)
288
- - `aria-checked` reflects current state including "mixed" for indeterminate
289
- - `aria-invalid` set when in error state
290
- - `aria-describedby` links to error/description text
291
- - Focus indicator follows WCAG guidelines
292
- - Disabled state properly announced to assistive technology