2023-05-22 14:32:45 +02:00
import { Canvas, Meta, Story, ArgTypes } from '@storybook/blocks';
2023-04-20 14:58:06 +02:00
import { Radio } from "./index";
2023-05-22 11:39:11 +02:00
import * as Stories from './index.stories';
2023-04-20 14:58:06 +02:00
2023-05-22 11:39:11 +02:00
<Meta of={Stories}/>
2023-04-20 14:58:06 +02:00
# Radio
Cunningham provides a versatile Radio component that can be used in a variety of ways. The radio component is a form element that allows the user to select one option from a set of options.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.Group} sourceState="shown"/>
2023-04-20 14:58:06 +02:00
## Label
The `label` props is optional, but you can use it to provide a description of the radio.
**Without label**
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.Default} sourceState="shown"/>
2023-04-20 14:58:06 +02:00
**With label**
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.WithLabel} sourceState="shown"/>
2023-04-20 14:58:06 +02:00
## Value
You can set the value of the radio with the `checked` attribute.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.Default}/>
<Canvas of={Stories.Checked}/>
2023-04-20 14:58:06 +02:00
## Texts
As the component uses [Field](?path=/story/components-forms-field-doc--page), you can use the `text` props to provide a description of the radio.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.WithText} sourceState="shown"/>
2023-04-20 14:58:06 +02:00
## Disabled
As a regular radio, you can disable it by using the `disabled` props.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.Disabled} sourceState="shown"/>
2023-04-20 14:58:06 +02:00
## States
You can use the following props to change the state of the Input component by using the `state` props.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.WithText} sourceState="shown"/>
<Canvas of={Stories.Success} sourceState="shown"/>
<Canvas of={Stories.Error} sourceState="shown"/>
2023-04-20 14:58:06 +02:00
## Group
Here is how you can leverage the `RadioGroup` component to create a group of radio buttons.
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.Group} sourceState="shown"/>
2023-04-20 14:58:06 +02:00
You can also define `state`, `text` props on the group component
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.GroupError} sourceState="shown"/>
<Canvas of={Stories.GroupSuccess} sourceState="shown"/>
2023-04-20 14:58:06 +02:00
2023-07-26 17:48:22 +02:00
## Usage with react-hook-form
You can use this radio with [react-hook-form](https://react-hook-form.com/docs)
2024-03-14 17:17:30 +01:00
<Canvas of={Stories.ReactHookForm} sourceState="shown"/>
2023-07-26 17:48:22 +02:00
2023-05-22 14:32:45 +02:00
### Props
<ArgTypes of={Radio} />
2023-04-20 14:58:06 +02:00
## Design tokens
Here are available custom design tokens.
| Token | Description |
|--------------- |----------------------------- |
| border-color | Border color of the radio |
| accent-color | Color of the checkmark |
The design tokens `font-size`, `font-weight`, `color`, `width`, `height` are shared with [Checkbox](?path=/story/components-forms-checkbox-doc--page)
See also [Field](?path=/story/components-forms-field-doc--page)
##
<img src="components/Forms/Radio/resources/dd_1.svg"/>
##
<img src="components/Forms/Radio/resources/dd_2.svg"/>
##
2024-03-14 17:17:30 +01:00
<img src="components/Forms/Radio/resources/dd_3.svg"/>