@xsolla/xui-radio 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 +184 -19
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,39 +1,204 @@
1
- # @xsolla/xui-radio
1
+ ---
2
+ title: Radio
3
+ subtitle: A radio button for single selection.
4
+ description: A cross-platform React radio button component for selecting one option from a group.
5
+ ---
2
6
 
3
- Accessible radio button with label, description, and error state; integrates with RadioGroup.
7
+ # Radio
8
+
9
+ A cross-platform React radio button component for selecting one option from a group. Works standalone or with RadioGroup for coordinated selection.
4
10
 
5
11
  ## Installation
6
12
 
7
13
  ```bash
14
+ npm install @xsolla/xui-radio
15
+ # or
8
16
  yarn add @xsolla/xui-radio
9
17
  ```
10
18
 
11
- ## Usage
19
+ ## Demo
20
+
21
+ ### Basic Radio
22
+
23
+ ```tsx
24
+ import * as React from 'react';
25
+ import { Radio } from '@xsolla/xui-radio';
26
+
27
+ export default function BasicRadio() {
28
+ const [selected, setSelected] = React.useState('');
29
+
30
+ return (
31
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
32
+ <Radio
33
+ checked={selected === 'option1'}
34
+ onPress={() => setSelected('option1')}
35
+ label="Option 1"
36
+ />
37
+ <Radio
38
+ checked={selected === 'option2'}
39
+ onPress={() => setSelected('option2')}
40
+ label="Option 2"
41
+ />
42
+ <Radio
43
+ checked={selected === 'option3'}
44
+ onPress={() => setSelected('option3')}
45
+ label="Option 3"
46
+ />
47
+ </div>
48
+ );
49
+ }
50
+ ```
51
+
52
+ ### Radio with Description
53
+
54
+ ```tsx
55
+ import * as React from 'react';
56
+ import { Radio } from '@xsolla/xui-radio';
57
+
58
+ export default function RadioWithDescription() {
59
+ const [plan, setPlan] = React.useState('basic');
60
+
61
+ return (
62
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
63
+ <Radio
64
+ checked={plan === 'basic'}
65
+ onPress={() => setPlan('basic')}
66
+ label="Basic Plan"
67
+ description="Best for individuals, includes core features"
68
+ />
69
+ <Radio
70
+ checked={plan === 'pro'}
71
+ onPress={() => setPlan('pro')}
72
+ label="Pro Plan"
73
+ description="Best for teams, includes advanced features"
74
+ />
75
+ <Radio
76
+ checked={plan === 'enterprise'}
77
+ onPress={() => setPlan('enterprise')}
78
+ label="Enterprise Plan"
79
+ description="Custom solutions for large organizations"
80
+ />
81
+ </div>
82
+ );
83
+ }
84
+ ```
85
+
86
+ ### Radio Sizes
12
87
 
13
88
  ```tsx
89
+ import * as React from 'react';
90
+ import { Radio } from '@xsolla/xui-radio';
91
+
92
+ export default function RadioSizes() {
93
+ return (
94
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
95
+ <Radio size="sm" label="Small radio" checked />
96
+ <Radio size="md" label="Medium radio (default)" checked />
97
+ <Radio size="lg" label="Large radio" checked />
98
+ <Radio size="xl" label="Extra large radio" checked />
99
+ </div>
100
+ );
101
+ }
102
+ ```
103
+
104
+ ## Anatomy
105
+
106
+ Import the component and use it directly:
107
+
108
+ ```jsx
14
109
  import { Radio } from '@xsolla/xui-radio';
15
110
 
16
111
  <Radio
17
- value="monthly"
18
- checked={billing === 'monthly'}
19
- label="Monthly billing"
20
- description="Billed every month"
21
- onPress={() => setBilling('monthly')}
112
+ checked={isSelected} // Whether this radio is selected
113
+ onPress={handleSelect} // Click/tap handler
114
+ onValueChange={handleChange} // Value change handler
115
+ value="option1" // Value for RadioGroup context
116
+ label="Option label" // Label text
117
+ description="Help text" // Description below label
118
+ errorLabel="Error text" // Error message
119
+ state="default" // Visual state
120
+ size="md" // Size variant
22
121
  />
23
122
  ```
24
123
 
25
- ## Props
124
+ ## Examples
125
+
126
+ ### Error State
127
+
128
+ ```tsx
129
+ import * as React from 'react';
130
+ import { Radio } from '@xsolla/xui-radio';
131
+
132
+ export default function ErrorRadio() {
133
+ return (
134
+ <Radio
135
+ checked={false}
136
+ state="error"
137
+ label="Select this option"
138
+ errorLabel="Please make a selection"
139
+ />
140
+ );
141
+ }
142
+ ```
143
+
144
+ ### Disabled Radio
145
+
146
+ ```tsx
147
+ import * as React from 'react';
148
+ import { Radio } from '@xsolla/xui-radio';
149
+
150
+ export default function DisabledRadio() {
151
+ return (
152
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
153
+ <Radio state="disable" label="Disabled unchecked" />
154
+ <Radio state="disable" checked label="Disabled checked" />
155
+ </div>
156
+ );
157
+ }
158
+ ```
159
+
160
+ ## API Reference
26
161
 
27
162
  ### Radio
28
163
 
164
+ A single radio button component.
165
+
166
+ **Radio Props:**
167
+
29
168
  | Prop | Type | Default | Description |
30
- |------|------|---------|-------------|
31
- | `checked` | `boolean` | `false` | Whether the radio button is selected |
32
- | `value` | `string` | | Value passed to the parent `RadioGroup` |
33
- | `onPress` | `() => void` | | Called when the radio button is activated |
34
- | `label` | `string` | | Label text displayed next to the button |
35
- | `description` | `string` | | Descriptive text shown below the label |
36
- | `errorLabel` | `string` | | Error message shown when `state` is `"error"` |
37
- | `size` | `"sm" \| "md" \| "lg" \| "xl"` | `"md"` | Size of the control |
38
- | `state` | `"default" \| "hover" \| "disable" \| "error"` | `"default"` | Visual state |
39
- | `disabled` | `boolean` | `false` | Disables the control |
169
+ | :--- | :--- | :------ | :---------- |
170
+ | checked | `boolean` | `false` | Whether the radio button is selected. |
171
+ | value | `string` | - | Value used when within RadioGroup. |
172
+ | size | `"sm" \| "md" \| "lg" \| "xl"` | `"md"` | Size of the radio button. |
173
+ | state | `"default" \| "hover" \| "disable" \| "error"` | `"default"` | Visual state of the radio. |
174
+ | label | `string` | - | Label text displayed next to the radio. |
175
+ | description | `string` | - | Description text below the label. |
176
+ | errorLabel | `string` | - | Error message when state is "error". |
177
+ | onPress | `() => void` | - | Callback when the radio is pressed. |
178
+ | onValueChange | `(value: boolean) => void` | - | Callback when checked state changes. |
179
+ | aria-label | `string` | - | Accessible label for screen readers. |
180
+ | aria-labelledby | `string` | - | ID of element that labels this radio. |
181
+
182
+ ## Theming
183
+
184
+ Radio uses the design system theme for colors:
185
+
186
+ ```typescript
187
+ // Colors accessed via theme
188
+ theme.colors.control.radio.bg // Unchecked background
189
+ theme.colors.control.radio.bgChecked // Checked background
190
+ theme.colors.control.radio.border // Border color
191
+ theme.colors.control.radio.borderChecked // Checked border
192
+ theme.colors.control.radio.dot // Inner dot color
193
+ theme.colors.content.primary // Label text
194
+ theme.colors.content.secondary // Description text
195
+ theme.colors.content.error // Error text
196
+ ```
197
+
198
+ ## Accessibility
199
+
200
+ - Uses `role="radio"` with proper ARIA attributes
201
+ - `aria-checked` reflects selection state
202
+ - Keyboard support (Space to select)
203
+ - Focus indicator follows WCAG guidelines
204
+ - Works with RadioGroup for proper group semantics
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsolla/xui-radio",
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
  },
19
19
  "peerDependencies": {
20
20
  "react": ">=16.8.0",