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