Skip to main content

Checkbox

Quick start

Here's a quick start guide to get started with the Checkbox component, Checkboxes are for selecting one or several options in a list.

Importing Component

import { Checkbox, CheckboxGroup } from "@hover-design/react";

Code Snippets and Examples

Simple Checkbox
import { Checkbox, CheckboxGroup } from "@hover-design/react";

const Demo = () => {
const [checkboxVal, setCheckboxVal] = useState({
honeypot: false,
rover: false,
weaver: false
});

return (
<div>
<label>
<Checkbox
name="antColony"
value="honeypot"
checked={checkboxVal.honeypot}
onChange={() =>
setCheckboxVal({
...checkboxVal,
honeypot: !checkboxVal.honeypot
})
}
/>
Honeypot
</label>
<label>
<Checkbox
name="antColony"
value="rover"
checked={checkboxVal.rover}
onChange={() =>
setCheckboxVal({
...checkboxVal,
rover: !checkboxVal.rover
})
}
/>
Rover
</label>
<label>
<Checkbox
name="antColony"
value="weaver"
checked={checkboxVal.weaver}
onChange={() =>
setCheckboxVal({
...checkboxVal,
weaver: !checkboxVal.weaver
})
}
/>
Weaver
</label>
</div>
);
};
Checkbox States
<div>
<label>
<Checkbox /> Unselected Checkbox
</label>
<label>
<Checkbox checked /> Selected Checkbox
</label>
<label>
<Checkbox indeterminate /> Indeterminate Checkbox
</label>
<label>
<Checkbox isDisabled /> Disabled Checkbox
</label>
<label>
<Checkbox isDisabled checked /> Disabled Selected Checkbox
</label>
<label>
<Checkbox isDisabled indeterminate /> Disabled Indeterminate Checkbox
</label>
</div>
Checkbox Group
<CheckboxGroup orientation="vertical" spacing="xl">
<label>
<Checkbox name="antColony" value="honeypot" checked />
Honeypot
</label>
<label>
<Checkbox name="antColony" value="rover" />
Rover
</label>
<label>
<Checkbox name="antColony" value="weaver" isDisabled />
Weaver
</label>
</CheckboxGroup>
Checkbox with styles
<div>
<Checkbox
checked
checkboxSize="xs"
selectedStyles={{
borderColor: "rgb(102, 168, 15)",
backgroundColor: "rgb(102, 168, 15)"
}}
/>
<Checkbox checkboxSize="sm" checked />
<Checkbox
checked
checkboxSize="md"
selectedStyles={{
borderColor: "rgb(224, 49, 49)",
backgroundColor: "rgb(224, 49, 49)"
}}
/>
<Checkbox
indeterminate
checkboxSize="md"
indeterminateStyles={{
borderColor: "rgb(240, 140, 0)",
backgroundColor: "rgb(240, 140, 0)"
}}
/>
<Checkbox
checkboxSize="sm"
isDisabled
borderRadius="md"
disabledStyles={{
borderColor: "rgb(255, 255, 255)",
backgroundColor: "rgb(0, 0, 0)"
}}
/>
<Checkbox
indeterminate
checkboxSize="xs"
borderRadius="xl"
indeterminateStyles={{
borderColor: "rgb(156, 54, 181)",
backgroundColor: "rgb(156, 54, 181)"
}}
/>
</div>

Checkbox Props Reference

KeytypeOptional?
valuestring;Yes
namestring;Yes
idstring;Yes
indeterminateboolean;Yes
isDisabledbooleanYes
checkboxSizexs sm md lg xl stringYes
borderRadiusxs sm md lg xl stringYes
baseStylesbaseStyles objectYes
disabledStylesdisabledStyles objectYes
selectedStylesselectedStyles objectYes
indeterminateStylesindeterminateStyles objectYes
Customizing Checkbox Base, Selected, Indeterminate and Disabled Styles.

You can customize the base, selected, indeterminate and disabled styles of the checkbox by passing in the baseStyles, selectedStyles, indeterminateStyles and disabledStyles props. Refer this Spec for this:

baseStyles

PropertyDescriptionDefault
backgroundColorBackground of Checkboxrgb(250, 250, 250)
borderColorBorder Colorrgb(204, 204, 204)

selectedStyles

PropertyDescriptionDefault
colorSelected Checkbox Colorrgb(250, 250, 250)
backgroundColorSelected Checkbox BackgroundColorrgb(25, 113, 194)
borderColorSelected Border Colorrgb(25, 113, 194)

indeterminateStyles

PropertyDescriptionDefault
colorDisabled Checkbox Colorrgb(250, 250, 250)
backgroundColorDisabled Checkbox BackgroundColorrgb(25, 113, 194)
borderColorDisabled Checkbox Border Colorrgb(25, 113, 194)

disabledStyles

PropertyDescriptionDefault
backgroundColorDisabled Checkbox BackgroundColorrgb(227, 227, 227)
borderColorDisabled Checkbox Border Colorrgb(204, 204, 204)

CheckboxGroup Props Reference

KeytypeOptional?
childrenReact.ReactNodeNo
spacingxs sm md lg xl stringYes
orientationverticle horizontalYes
refRefObject<HTMLButtonElement>;Yes