Checkbox
import Checkbox from "@intility/bifrost-react/Checkbox";
Basic Checkbox
<Checkbox label="Basic checkbox" />
<Checkbox label="Basic checkbox" />
Controlled state
You can bind a checkbox to a boolean state using the checked
prop and update
your state every time the onChange
event is triggered.
Indeterminate Checkbox
When the checked state is unknown use the indeterminate
prop.
<Checkbox indeterminate label="Indeterminate checkbox" />
<Checkbox indeterminate label="Indeterminate checkbox" />
This can be useful for a group or hierarchy of checkboxes:
Radio buttons
Set the Checkbox type
to 'radio'
and group by name
for mutually exclusive
radio buttons.
<Checkbox type='radio' name='radioDemo' label='NRK P1' />
<Checkbox type='radio' name='radioDemo' label='P4' />
<Checkbox type='radio' name='radioDemo' label='NRJ' />
<Checkbox type='radio' name='radioDemo' label='Radio Norge' />
<Checkbox type='radio' name='radioDemo' label='NRK P1' />
<Checkbox type='radio' name='radioDemo' label='P4' />
<Checkbox type='radio' name='radioDemo' label='NRJ' />
<Checkbox type='radio' name='radioDemo' label='Radio Norge' />
<Radio>
component docsSwitch toggle
A Checkbox with type
set to 'switch'
functions exactly the same a normal
checkbox, and only differs in styling.
For convenience, <Switch>
is provided as an alias for
<Checkbox type="switch">
.
<Checkbox type="switch" label="Switch toggle" />
<Checkbox type="switch" label="Switch toggle" />
<Switch>
component docsButton style
Use button
prop to display as a button. This works for checkboxes of type
'radio'
and 'switch'
as well.
<Checkbox button label='Checkbox with button prop' />
<Checkbox button type='radio' label='Radio button with button prop' />
<Checkbox button type='switch' label='Switch toggle with button prop' />
<Checkbox button label='Checkbox with button prop' />
<Checkbox button type='radio' label='Radio button with button prop' />
<Checkbox button type='switch' label='Switch toggle with button prop' />
Small button size
Use the small
prop (along with button
) for a smaller button size.
<Checkbox small button label='Small checkbox' />
<Checkbox small button label='Small radio' type='radio' />
<Checkbox small button label='Small switch' type='switch' />
<Checkbox small button label='Small checkbox' />
<Checkbox small button label='Small radio' type='radio' />
<Checkbox small button label='Small switch' type='switch' />
Custom label (like icon)
The label
prop accepts JSX content, useful if you want to supply an icon.
<Checkbox
type="switch"
button
label={
<>
<Icon icon={faUser} color="var(--bfc-base-c-2)" />
Include myself as a signee
</>
}
/>
<Checkbox
type="switch"
button
label={
<>
<Icon icon={faUser} color="var(--bfc-base-c-2)" />
Include myself as a signee
</>
}
/>
Disabled
Use disabled
prop to disable the control.
<Checkbox disabled label="Disabled checkbox" />
<Checkbox disabled label="Disabled checkbox" />
Hide label
Use hideLabel
to hide the label. Usually you shouldn't do this!
The label
prop is still required for accessibility (screen readers will be
able to read the hidden label as long as you pass a string)
<Checkbox label="Would you consider this an awesome person?" hideLabel />
<Checkbox label="Would you consider this an awesome person?" hideLabel />
Can be useful in a table where they are labelled by the table header, also works
with switch
and radio
type: