Checkboxes allow users to complete tasks that involve making choices such as selecting options. Can be styled as a switch, a visual toggle between two mutually exclusive states — on and off.
You should have the chayns-components
package installed. If that is not the
case already, run
yarn add chayns-components
or
npm i chayns-components
After the chayns-components
package is installed, you can import the component
and use it with React:
import React from 'react'
import { Checkbox } from 'chayns-components';
// ...
<Checkbox {...} />
The Checkbox
-component takes the following props:
Name | Type | Default | Required |
---|---|---|---|
style | { [key: string]: string | number } |
||
className | string |
||
labelStyle | { [key: string]: string | number } |
||
labelClassName | string |
||
label | ReactNode | Array<ReactNode> |
||
children | ReactNode | Array<ReactNode> |
||
onChange | function |
||
toggleButton | boolean |
false |
|
checked | boolean |
||
defaultChecked | boolean |
||
disabled | boolean |
false |
|
dangerouslySetLabel | { __html: string } |
||
stopPropagation | boolean |
false |
|
id | number | string |
style?: { [key: string]: string | number }
A React style object that will be applied to the CheckBox element.
className?: string
A classname string that will be applied to the CheckBox element.
labelStyle?: { [key: string]: string | number }
A React style object that will be applied to the label element.
labelClassName?: string
A classname string that will be applied to the label element.
label?: ReactNode | Array<ReactNode>
A label that will be shown next to the CheckBox.
children?: ReactNode | Array<ReactNode>
A label that will be shown next to the CheckBox.
onChange?: function
This will be called when the state of the CheckBox changes.
toggleButton?: boolean
Changes the rendering to a switch-/toggle-style.
checked?: boolean
Wether the CheckBox is checked. Makes it a controlled input.
defaultChecked?: boolean
Wether the CheckBox is checked by default. Do not use it with the
checked
-prop.
disabled?: boolean
Disables any interactions with the CheckBox and changes the style to a disabled look.
dangerouslySetLabel?: { __html: string }
Set the contents of the label with a raw HTML string.
stopPropagation?: boolean
Wether to stop propagation of click events.
id?: number | string
The HTML id of the input element.