@hawk-ui/radio
v4.4.1
Published
hawk-ui: Basic Radio Component
Downloads
311
Maintainers
Readme
Installation
To install a component run
$ npm install @hawk-ui/radio --save
Please import CSS styles via
@import '/path__to__node_modules/@hawk-ui/radio/dist/index.min.css
Usage
Without Required
import Radio from '@hawk-ui/radio';
initialState = {
fruits: [
{ key: 1, label: 'apple', value: 'apple' },
{ key: 1, label: 'mango', value: 'mango' },
{ key: 1, label: 'banana', value: 'banana' },
{ key: 1, label: 'orange', value: 'orange' },
{ key: 1, label: 'pineapple', value: 'pineapple' },
],
selectedItem: '',
};
<Radio
options={state.fruits}
selectedItem={state.selectedItem}
onChange={(event) => {
setState({
selectedItem: event.target.value
});
}}
/>
With Required
import Radio from '@hawk-ui/radio';
initialState = {
fruits: [
{ key: 1, label: 'apple', value: 'apple' },
{ key: 1, label: 'mango', value: 'mango' },
{ key: 1, label: 'banana', value: 'banana' },
{ key: 1, label: 'orange', value: 'orange' },
{ key: 1, label: 'pineapple', value: 'pineapple' },
],
selectedItem: '',
};
<Radio
label="Select Fruit"
options={state.fruits}
selectedItem={state.selectedItem}
onChange={(event) => {
setState({
selectedItem: event.target.value
});
}}
isRequired
isError
errorMessage="This field is a compulsory field."
/>
Without object
import Radio from '@hawk-ui/radio';
initialState = {
isChecked: false,
};
<Radio
label="Select Radio"
title="Title"
value="title"
isChecked={state.isChecked}
onChange={(event) => {
setState({
isChecked: !state.isChecked,
});
}}
htmlAttributes={{
disabled: true,
}}
/>