@xsolla/xui-radio-group 0.148.0 → 0.148.2
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 +259 -0
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# Radio Group
|
|
2
|
+
|
|
3
|
+
A cross-platform React radio group component that manages single selection across multiple radio buttons. Provides context to child Radio components for coordinated selection.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @xsolla/xui-radio-group @xsolla/xui-radio
|
|
9
|
+
# or
|
|
10
|
+
yarn add @xsolla/xui-radio-group @xsolla/xui-radio
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Demo
|
|
14
|
+
|
|
15
|
+
### Basic Radio Group
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import * as React from 'react';
|
|
19
|
+
import { RadioGroup } from '@xsolla/xui-radio-group';
|
|
20
|
+
import { Radio } from '@xsolla/xui-radio';
|
|
21
|
+
|
|
22
|
+
export default function BasicRadioGroup() {
|
|
23
|
+
const [value, setValue] = React.useState('option1');
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<RadioGroup value={value} onChange={setValue}>
|
|
27
|
+
<Radio value="option1" label="Option 1" />
|
|
28
|
+
<Radio value="option2" label="Option 2" />
|
|
29
|
+
<Radio value="option3" label="Option 3" />
|
|
30
|
+
</RadioGroup>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Horizontal Layout
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
import * as React from 'react';
|
|
39
|
+
import { RadioGroup } from '@xsolla/xui-radio-group';
|
|
40
|
+
import { Radio } from '@xsolla/xui-radio';
|
|
41
|
+
|
|
42
|
+
export default function HorizontalRadioGroup() {
|
|
43
|
+
const [size, setSize] = React.useState('md');
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<RadioGroup value={size} onChange={setSize} flexDirection="row" gap={24}>
|
|
47
|
+
<Radio value="sm" label="Small" />
|
|
48
|
+
<Radio value="md" label="Medium" />
|
|
49
|
+
<Radio value="lg" label="Large" />
|
|
50
|
+
</RadioGroup>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Radio Group with Descriptions
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import * as React from 'react';
|
|
59
|
+
import { RadioGroup } from '@xsolla/xui-radio-group';
|
|
60
|
+
import { Radio } from '@xsolla/xui-radio';
|
|
61
|
+
|
|
62
|
+
export default function RadioGroupWithDescriptions() {
|
|
63
|
+
const [plan, setPlan] = React.useState('starter');
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<RadioGroup value={plan} onChange={setPlan} gap={16}>
|
|
67
|
+
<Radio
|
|
68
|
+
value="starter"
|
|
69
|
+
label="Starter"
|
|
70
|
+
description="$9/month - Best for personal projects"
|
|
71
|
+
/>
|
|
72
|
+
<Radio
|
|
73
|
+
value="professional"
|
|
74
|
+
label="Professional"
|
|
75
|
+
description="$29/month - Best for small teams"
|
|
76
|
+
/>
|
|
77
|
+
<Radio
|
|
78
|
+
value="enterprise"
|
|
79
|
+
label="Enterprise"
|
|
80
|
+
description="Custom pricing - For large organizations"
|
|
81
|
+
/>
|
|
82
|
+
</RadioGroup>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Disabled Radio Group
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import * as React from 'react';
|
|
91
|
+
import { RadioGroup } from '@xsolla/xui-radio-group';
|
|
92
|
+
import { Radio } from '@xsolla/xui-radio';
|
|
93
|
+
|
|
94
|
+
export default function DisabledRadioGroup() {
|
|
95
|
+
return (
|
|
96
|
+
<RadioGroup value="option1" disabled>
|
|
97
|
+
<Radio value="option1" label="Option 1" />
|
|
98
|
+
<Radio value="option2" label="Option 2" />
|
|
99
|
+
<Radio value="option3" label="Option 3" />
|
|
100
|
+
</RadioGroup>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Anatomy
|
|
106
|
+
|
|
107
|
+
Import the components and compose them:
|
|
108
|
+
|
|
109
|
+
```jsx
|
|
110
|
+
import { RadioGroup } from '@xsolla/xui-radio-group';
|
|
111
|
+
import { Radio } from '@xsolla/xui-radio';
|
|
112
|
+
|
|
113
|
+
<RadioGroup
|
|
114
|
+
value={selectedValue} // Currently selected value
|
|
115
|
+
onChange={handleChange} // Selection change handler
|
|
116
|
+
size="md" // Size for all child radios
|
|
117
|
+
disabled={false} // Disable all radios
|
|
118
|
+
flexDirection="column" // Layout direction
|
|
119
|
+
gap={12} // Gap between items
|
|
120
|
+
>
|
|
121
|
+
<Radio value="a" label="Option A" />
|
|
122
|
+
<Radio value="b" label="Option B" />
|
|
123
|
+
<Radio value="c" label="Option C" />
|
|
124
|
+
</RadioGroup>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Examples
|
|
128
|
+
|
|
129
|
+
### Form Integration
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
import * as React from 'react';
|
|
133
|
+
import { RadioGroup } from '@xsolla/xui-radio-group';
|
|
134
|
+
import { Radio } from '@xsolla/xui-radio';
|
|
135
|
+
import { Button } from '@xsolla/xui-button';
|
|
136
|
+
|
|
137
|
+
export default function FormRadioGroup() {
|
|
138
|
+
const [shipping, setShipping] = React.useState('');
|
|
139
|
+
const [error, setError] = React.useState('');
|
|
140
|
+
|
|
141
|
+
const handleSubmit = (e: React.FormEvent) => {
|
|
142
|
+
e.preventDefault();
|
|
143
|
+
if (!shipping) {
|
|
144
|
+
setError('Please select a shipping method');
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
console.log('Selected shipping:', shipping);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<form onSubmit={handleSubmit}>
|
|
152
|
+
<h3 id="shipping-label">Select Shipping Method</h3>
|
|
153
|
+
<RadioGroup
|
|
154
|
+
value={shipping}
|
|
155
|
+
onChange={(v) => { setShipping(v); setError(''); }}
|
|
156
|
+
aria-labelledby="shipping-label"
|
|
157
|
+
aria-describedby={error ? 'shipping-error' : undefined}
|
|
158
|
+
>
|
|
159
|
+
<Radio
|
|
160
|
+
value="standard"
|
|
161
|
+
label="Standard Shipping"
|
|
162
|
+
description="5-7 business days - Free"
|
|
163
|
+
/>
|
|
164
|
+
<Radio
|
|
165
|
+
value="express"
|
|
166
|
+
label="Express Shipping"
|
|
167
|
+
description="2-3 business days - $9.99"
|
|
168
|
+
/>
|
|
169
|
+
<Radio
|
|
170
|
+
value="overnight"
|
|
171
|
+
label="Overnight Shipping"
|
|
172
|
+
description="Next business day - $24.99"
|
|
173
|
+
/>
|
|
174
|
+
</RadioGroup>
|
|
175
|
+
{error && <p id="shipping-error" role="alert" style={{ color: 'red' }}>{error}</p>}
|
|
176
|
+
<Button type="submit" style={{ marginTop: 16 }}>Continue</Button>
|
|
177
|
+
</form>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Different Sizes
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
import * as React from 'react';
|
|
186
|
+
import { RadioGroup } from '@xsolla/xui-radio-group';
|
|
187
|
+
import { Radio } from '@xsolla/xui-radio';
|
|
188
|
+
|
|
189
|
+
export default function RadioGroupSizes() {
|
|
190
|
+
const [value, setValue] = React.useState('a');
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<div style={{ display: 'flex', gap: 48 }}>
|
|
194
|
+
<div>
|
|
195
|
+
<h4>Small</h4>
|
|
196
|
+
<RadioGroup value={value} onChange={setValue} size="sm">
|
|
197
|
+
<Radio value="a" label="Option A" />
|
|
198
|
+
<Radio value="b" label="Option B" />
|
|
199
|
+
</RadioGroup>
|
|
200
|
+
</div>
|
|
201
|
+
<div>
|
|
202
|
+
<h4>Large</h4>
|
|
203
|
+
<RadioGroup value={value} onChange={setValue} size="lg">
|
|
204
|
+
<Radio value="a" label="Option A" />
|
|
205
|
+
<Radio value="b" label="Option B" />
|
|
206
|
+
</RadioGroup>
|
|
207
|
+
</div>
|
|
208
|
+
</div>
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## API Reference
|
|
214
|
+
|
|
215
|
+
### RadioGroup
|
|
216
|
+
|
|
217
|
+
Container component that provides selection context to Radio children.
|
|
218
|
+
|
|
219
|
+
**RadioGroup Props:**
|
|
220
|
+
|
|
221
|
+
| Prop | Type | Default | Description |
|
|
222
|
+
| :--- | :--- | :------ | :---------- |
|
|
223
|
+
| children | `ReactNode` | - | **Required.** Radio components to group. |
|
|
224
|
+
| value | `string` | - | Currently selected value. |
|
|
225
|
+
| onChange | `(value: string) => void` | - | Callback when selection changes. |
|
|
226
|
+
| size | `"sm" \| "md" \| "lg" \| "xl"` | `"md"` | Size applied to all child Radio components. |
|
|
227
|
+
| disabled | `boolean` | `false` | Whether all radios are disabled. |
|
|
228
|
+
| flexDirection | `"row" \| "column"` | `"column"` | Layout direction of the group. |
|
|
229
|
+
| gap | `number` | `12` | Gap between radio items in pixels. |
|
|
230
|
+
|
|
231
|
+
### RadioGroup Context
|
|
232
|
+
|
|
233
|
+
RadioGroup provides context to child Radio components:
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
interface RadioGroupContextProps {
|
|
237
|
+
value?: string; // Currently selected value
|
|
238
|
+
onChange?: (value: string) => void; // Selection handler
|
|
239
|
+
size?: "sm" | "md" | "lg" | "xl"; // Size for radios
|
|
240
|
+
disabled?: boolean; // Disabled state
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Child Radio components automatically:
|
|
245
|
+
- Sync their checked state with the group value
|
|
246
|
+
- Call the group's onChange when selected
|
|
247
|
+
- Inherit size and disabled props from the group
|
|
248
|
+
|
|
249
|
+
## Theming
|
|
250
|
+
|
|
251
|
+
RadioGroup uses flexbox layout with theme-based spacing. Child Radio components use the design system theme for colors.
|
|
252
|
+
|
|
253
|
+
## Accessibility
|
|
254
|
+
|
|
255
|
+
- RadioGroup provides proper grouping semantics
|
|
256
|
+
- Only one radio can be selected at a time
|
|
257
|
+
- Arrow keys navigate between options when focused
|
|
258
|
+
- Tab key moves focus to/from the group
|
|
259
|
+
- Disabled state properly communicated to all children
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsolla/xui-radio-group",
|
|
3
|
-
"version": "0.148.
|
|
3
|
+
"version": "0.148.2",
|
|
4
4
|
"main": "./web/index.js",
|
|
5
5
|
"module": "./web/index.mjs",
|
|
6
6
|
"types": "./web/index.d.ts",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"build:native": "PLATFORM=native tsup"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xsolla/xui-core": "0.148.
|
|
14
|
-
"@xsolla/xui-primitives-core": "0.148.
|
|
15
|
-
"@xsolla/xui-radio": "0.148.
|
|
13
|
+
"@xsolla/xui-core": "0.148.2",
|
|
14
|
+
"@xsolla/xui-primitives-core": "0.148.2",
|
|
15
|
+
"@xsolla/xui-radio": "0.148.2"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"react": ">=16.8.0",
|