@fvc/radio 1.0.1 → 1.0.2-next-ec65dfb844e6183b3d7f417eee613cfe5ecfd997
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 +195 -0
- package/package.json +11 -1
package/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# @fvc/radio
|
|
2
|
+
|
|
3
|
+
`@fvc/radio` provides FE-VIS styled radio button primitives on top of Ant Design. It keeps the Ant Design Radio API familiar while applying the design-system token palette used across FE-VIS applications: themed border and dot colors, a disabled state, a block layout option for full-width groups, and a test-friendly `testId` prop.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @fvc/radio
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Peer Dependencies
|
|
12
|
+
|
|
13
|
+
The package expects these dependencies to be available in the consuming application:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bun add react antd
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Import
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { Radio } from '@fvc/radio';
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { Radio } from '@fvc/radio';
|
|
29
|
+
import { useState } from 'react';
|
|
30
|
+
|
|
31
|
+
export function AgreementForm() {
|
|
32
|
+
const [value, setValue] = useState('yes');
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Radio.Group value={value} onChange={(e) => setValue(e.target.value)}>
|
|
36
|
+
<Radio value="yes">Yes</Radio>
|
|
37
|
+
<Radio value="no">No</Radio>
|
|
38
|
+
</Radio.Group>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Common Usage
|
|
44
|
+
|
|
45
|
+
### Standalone Radio
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
<Radio value="a">Option A</Radio>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Controlled Group
|
|
52
|
+
|
|
53
|
+
Wrap multiple `Radio` items in `Radio.Group` to manage a set of mutually exclusive choices.
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
const [value, setValue] = useState('a');
|
|
57
|
+
|
|
58
|
+
<Radio.Group value={value} onChange={(e) => setValue(e.target.value)}>
|
|
59
|
+
<Radio value="a">Option A</Radio>
|
|
60
|
+
<Radio value="b">Option B</Radio>
|
|
61
|
+
<Radio value="c">Option C</Radio>
|
|
62
|
+
</Radio.Group>;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Block Group
|
|
66
|
+
|
|
67
|
+
The `block` prop stretches every radio item to fill the full width of its container.
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
<Radio.Group block value={value} onChange={(e) => setValue(e.target.value)}>
|
|
71
|
+
<Radio value="a">Option A</Radio>
|
|
72
|
+
<Radio value="b">Option B</Radio>
|
|
73
|
+
</Radio.Group>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Disabled
|
|
77
|
+
|
|
78
|
+
Both individual radios and the entire group can be disabled.
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
<Radio disabled value="a">Disabled option</Radio>
|
|
82
|
+
|
|
83
|
+
<Radio.Group disabled value={value}>
|
|
84
|
+
<Radio value="a">Option A</Radio>
|
|
85
|
+
<Radio value="b">Option B</Radio>
|
|
86
|
+
</Radio.Group>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Props
|
|
90
|
+
|
|
91
|
+
### `<Radio>`
|
|
92
|
+
|
|
93
|
+
Extends all [Ant Design `RadioProps`](https://ant-design.antgroup.com/components/radio#api).
|
|
94
|
+
|
|
95
|
+
| Prop | Type | Description |
|
|
96
|
+
| ---------- | ----------- | ------------------------------------------------- |
|
|
97
|
+
| `value` | `any` | The value bound to the radio input. |
|
|
98
|
+
| `checked` | `boolean` | Whether the radio is selected (controlled). |
|
|
99
|
+
| `disabled` | `boolean` | Disables the radio and removes it from tab order. |
|
|
100
|
+
| `onChange` | `function` | Callback fired when the radio selection changes. |
|
|
101
|
+
| `testId` | `string` | Maps to `data-testid` on the inner `<input>`. |
|
|
102
|
+
| `children` | `ReactNode` | Label displayed alongside the radio. |
|
|
103
|
+
|
|
104
|
+
### `<Radio.Group>`
|
|
105
|
+
|
|
106
|
+
Extends all [Ant Design `RadioGroupProps`](https://ant-design.antgroup.com/components/radio#radiogroup).
|
|
107
|
+
|
|
108
|
+
| Prop | Type | Description |
|
|
109
|
+
| -------------- | ---------- | -------------------------------------------------- |
|
|
110
|
+
| `value` | `any` | Currently selected value (controlled). |
|
|
111
|
+
| `defaultValue` | `any` | Initially selected value (uncontrolled). |
|
|
112
|
+
| `disabled` | `boolean` | Disables all radios within the group. |
|
|
113
|
+
| `onChange` | `function` | Callback fired when selection changes. |
|
|
114
|
+
| `block` | `boolean` | Stretches each radio item to full container width. |
|
|
115
|
+
| `className` | `string` | Additional CSS class names on the group wrapper. |
|
|
116
|
+
|
|
117
|
+
## TypeScript
|
|
118
|
+
|
|
119
|
+
The package ships with type definitions. No `@types/` install needed.
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import type { RadioProps, GroupProps } from '@fvc/radio/types';
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Consumer Example
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import { Radio } from '@fvc/radio';
|
|
129
|
+
import { useState } from 'react';
|
|
130
|
+
|
|
131
|
+
export function NotificationSettings({ onChange }) {
|
|
132
|
+
const [frequency, setFrequency] = useState('daily');
|
|
133
|
+
|
|
134
|
+
function handleChange(e) {
|
|
135
|
+
setFrequency(e.target.value);
|
|
136
|
+
onChange(e.target.value);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<Radio.Group block value={frequency} onChange={handleChange}>
|
|
141
|
+
<Radio value="realtime">Real-time</Radio>
|
|
142
|
+
<Radio value="daily">Daily digest</Radio>
|
|
143
|
+
<Radio value="weekly">Weekly summary</Radio>
|
|
144
|
+
<Radio value="never" disabled>
|
|
145
|
+
Never (disabled by admin)
|
|
146
|
+
</Radio>
|
|
147
|
+
</Radio.Group>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Testing
|
|
153
|
+
|
|
154
|
+
Use `testId` when a stable test selector is needed.
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
<Radio testId="agree-radio" value="agree">
|
|
158
|
+
I agree
|
|
159
|
+
</Radio>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
```tsx
|
|
163
|
+
screen.getByTestId('agree-radio');
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## CSS Customisation
|
|
167
|
+
|
|
168
|
+
The component reads the following CSS custom properties from the `@fvc` design token palette. These tokens are provided by `@fvc/utils` — no manual `:root` definition is needed unless you want to override the defaults.
|
|
169
|
+
|
|
170
|
+
| Token | Used for |
|
|
171
|
+
| ------------- | ---------------------------------- |
|
|
172
|
+
| `--blue-500` | Default border color and dot fill |
|
|
173
|
+
| `--blue-300` | Disabled border color and dot fill |
|
|
174
|
+
| `--neutral-0` | Inner circle background |
|
|
175
|
+
|
|
176
|
+
To override, set them in your global styles:
|
|
177
|
+
|
|
178
|
+
```css
|
|
179
|
+
:root {
|
|
180
|
+
--blue-500: #395ca6;
|
|
181
|
+
--blue-300: #cdd1e4;
|
|
182
|
+
--neutral-0: #ffffff;
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
For the full token list see [`src/Radio.scss`](./src/Radio.scss).
|
|
187
|
+
|
|
188
|
+
## Development
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
bun run lint
|
|
192
|
+
bun run type-check
|
|
193
|
+
bun run test
|
|
194
|
+
bun run build
|
|
195
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fvc/radio",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2-next-ec65dfb844e6183b3d7f417eee613cfe5ecfd997",
|
|
4
4
|
"main": "./dist/lib/index.js",
|
|
5
5
|
"types": "./dist/lib/radio/src/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -26,6 +26,16 @@
|
|
|
26
26
|
"type-check": "tsc --noEmit",
|
|
27
27
|
"test": "bun test --preload ../../tests/happydom.ts --preload ../../tests/testing-library.tsx"
|
|
28
28
|
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"react",
|
|
31
|
+
"react-component",
|
|
32
|
+
"fvc",
|
|
33
|
+
"fe-vis-core",
|
|
34
|
+
"ui",
|
|
35
|
+
"radio",
|
|
36
|
+
"design-system",
|
|
37
|
+
"antd"
|
|
38
|
+
],
|
|
29
39
|
"peerDependencies": {
|
|
30
40
|
"react": "^18.0.0",
|
|
31
41
|
"antd": "^5.0.0"
|