@xsolla/xui-switch 0.148.0 → 0.148.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.
Files changed (2) hide show
  1. package/README.md +257 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,257 @@
1
+ # Switch
2
+
3
+ A cross-platform React switch component for toggling between on and off states. Provides a visual alternative to checkboxes for boolean settings.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @xsolla/xui-switch
9
+ # or
10
+ yarn add @xsolla/xui-switch
11
+ ```
12
+
13
+ ## Demo
14
+
15
+ ### Basic Switch
16
+
17
+ ```tsx
18
+ import * as React from 'react';
19
+ import { Switch } from '@xsolla/xui-switch';
20
+
21
+ export default function BasicSwitch() {
22
+ const [enabled, setEnabled] = React.useState(false);
23
+
24
+ return (
25
+ <Switch
26
+ checked={enabled}
27
+ onValueChange={setEnabled}
28
+ label="Enable notifications"
29
+ />
30
+ );
31
+ }
32
+ ```
33
+
34
+ ### Switch with Description
35
+
36
+ ```tsx
37
+ import * as React from 'react';
38
+ import { Switch } from '@xsolla/xui-switch';
39
+
40
+ export default function SwitchWithDescription() {
41
+ const [darkMode, setDarkMode] = React.useState(false);
42
+
43
+ return (
44
+ <Switch
45
+ checked={darkMode}
46
+ onValueChange={setDarkMode}
47
+ label="Dark Mode"
48
+ description="Enable dark theme across the application"
49
+ />
50
+ );
51
+ }
52
+ ```
53
+
54
+ ### Label Position
55
+
56
+ ```tsx
57
+ import * as React from 'react';
58
+ import { Switch } from '@xsolla/xui-switch';
59
+
60
+ export default function SwitchLabelPosition() {
61
+ const [left, setLeft] = React.useState(false);
62
+ const [right, setRight] = React.useState(false);
63
+
64
+ return (
65
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
66
+ <Switch
67
+ label="Label on the right (default)"
68
+ labelPosition="right"
69
+ checked={right}
70
+ onValueChange={setRight}
71
+ />
72
+ <Switch
73
+ label="Label on the left"
74
+ labelPosition="left"
75
+ checked={left}
76
+ onValueChange={setLeft}
77
+ />
78
+ </div>
79
+ );
80
+ }
81
+ ```
82
+
83
+ ### Switch Sizes
84
+
85
+ ```tsx
86
+ import * as React from 'react';
87
+ import { Switch } from '@xsolla/xui-switch';
88
+
89
+ export default function SwitchSizes() {
90
+ return (
91
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
92
+ <Switch size="sm" label="Small switch" checked />
93
+ <Switch size="md" label="Medium switch (default)" checked />
94
+ <Switch size="lg" label="Large switch" checked />
95
+ <Switch size="xl" label="Extra large switch" checked />
96
+ </div>
97
+ );
98
+ }
99
+ ```
100
+
101
+ ## Anatomy
102
+
103
+ Import the component and use it directly:
104
+
105
+ ```jsx
106
+ import { Switch } from '@xsolla/xui-switch';
107
+
108
+ <Switch
109
+ checked={isEnabled} // Whether switch is on
110
+ onValueChange={handleToggle} // Toggle handler
111
+ label="Setting label" // Label text
112
+ labelPosition="right" // "left" | "right" (default: "right")
113
+ description="Help text" // Description below label
114
+ errorLabel="Error text" // Error message
115
+ state="default" // Visual state
116
+ size="md" // Size variant
117
+ />
118
+ ```
119
+
120
+ ## Examples
121
+
122
+ ### Settings Panel
123
+
124
+ ```tsx
125
+ import * as React from 'react';
126
+ import { Switch } from '@xsolla/xui-switch';
127
+
128
+ export default function SettingsPanel() {
129
+ const [settings, setSettings] = React.useState({
130
+ notifications: true,
131
+ sounds: false,
132
+ autoUpdate: true,
133
+ analytics: false,
134
+ });
135
+
136
+ const toggle = (key: string) => (value: boolean) => {
137
+ setSettings((prev) => ({ ...prev, [key]: value }));
138
+ };
139
+
140
+ return (
141
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 20 }}>
142
+ <Switch
143
+ checked={settings.notifications}
144
+ onValueChange={toggle('notifications')}
145
+ label="Push Notifications"
146
+ description="Receive push notifications for important updates"
147
+ />
148
+ <Switch
149
+ checked={settings.sounds}
150
+ onValueChange={toggle('sounds')}
151
+ label="Sound Effects"
152
+ description="Play sounds for actions and alerts"
153
+ />
154
+ <Switch
155
+ checked={settings.autoUpdate}
156
+ onValueChange={toggle('autoUpdate')}
157
+ label="Auto Update"
158
+ description="Automatically download and install updates"
159
+ />
160
+ <Switch
161
+ checked={settings.analytics}
162
+ onValueChange={toggle('analytics')}
163
+ label="Usage Analytics"
164
+ description="Help improve the app by sharing anonymous usage data"
165
+ />
166
+ </div>
167
+ );
168
+ }
169
+ ```
170
+
171
+ ### Error State
172
+
173
+ ```tsx
174
+ import * as React from 'react';
175
+ import { Switch } from '@xsolla/xui-switch';
176
+
177
+ export default function ErrorSwitch() {
178
+ return (
179
+ <Switch
180
+ checked={false}
181
+ state="error"
182
+ label="Required Setting"
183
+ errorLabel="This setting must be enabled to continue"
184
+ />
185
+ );
186
+ }
187
+ ```
188
+
189
+ ### Disabled Switch
190
+
191
+ ```tsx
192
+ import * as React from 'react';
193
+ import { Switch } from '@xsolla/xui-switch';
194
+
195
+ export default function DisabledSwitch() {
196
+ return (
197
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
198
+ <Switch state="disable" label="Disabled off" />
199
+ <Switch state="disable" checked label="Disabled on" />
200
+ </div>
201
+ );
202
+ }
203
+ ```
204
+
205
+ ## API Reference
206
+
207
+ ### Switch
208
+
209
+ A toggle switch component.
210
+
211
+ **Switch Props:**
212
+
213
+ | Prop | Type | Default | Description |
214
+ | :--- | :--- | :------ | :---------- |
215
+ | checked | `boolean` | `false` | Whether the switch is on. |
216
+ | size | `"sm" \| "md" \| "lg" \| "xl"` | `"md"` | Size of the switch. |
217
+ | state | `"default" \| "hover" \| "disable" \| "error"` | `"default"` | Visual state. |
218
+ | label | `string` | - | Label text displayed next to switch. |
219
+ | labelPosition | `"left" \| "right"` | `"right"` | Position of the label relative to the switch. |
220
+ | description | `string` | - | Description text below the label. |
221
+ | errorLabel | `string` | - | Error message when state is "error". |
222
+ | onValueChange | `(value: boolean) => void` | - | Callback when toggled. |
223
+ | ariaLabel | `string` | - | Accessible label for screen readers. |
224
+ | ariaLabelledBy | `string` | - | ID of element that labels this switch. |
225
+
226
+ **Size Configuration:**
227
+
228
+ | Size | Track Width | Track Height | Knob Size |
229
+ | :--- | :---------- | :----------- | :-------- |
230
+ | sm | 32px | 18px | 14px |
231
+ | md | 40px | 22px | 18px |
232
+ | lg | 48px | 26px | 22px |
233
+ | xl | 56px | 30px | 26px |
234
+
235
+ ## Theming
236
+
237
+ Switch uses the design system theme for colors:
238
+
239
+ ```typescript
240
+ // Colors accessed via theme
241
+ theme.colors.control.switch.bgOff // Track background when off
242
+ theme.colors.control.switch.bgOn // Track background when on
243
+ theme.colors.control.switch.knob // Knob color
244
+ theme.colors.control.switch.border // Border color
245
+ theme.colors.content.primary // Label text
246
+ theme.colors.content.secondary // Description text
247
+ theme.colors.content.error // Error text
248
+ ```
249
+
250
+ ## Accessibility
251
+
252
+ - Uses `role="switch"` semantic role
253
+ - `aria-checked` reflects on/off state
254
+ - Keyboard support (Space/Enter to toggle)
255
+ - Focus indicator follows WCAG guidelines
256
+ - Label properly associated with control
257
+ - Disabled state announced to assistive technology
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsolla/xui-switch",
3
- "version": "0.148.0",
3
+ "version": "0.148.1",
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.148.0",
17
- "@xsolla/xui-primitives-core": "0.148.0"
16
+ "@xsolla/xui-core": "0.148.1",
17
+ "@xsolla/xui-primitives-core": "0.148.1"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "react": ">=16.8.0",