Skip to main content

Checkbox / CheckboxGroup

Checkbox

An Individual checkbox component.

Usage

import { Checkbox } from "@fedibtc/ui";
import { useState } from "react";

function MyComponent() {
const [checked, setChecked] = useState(false);

return (
<Checkbox
checked={checked}
onChange={setChecked}
label="I am a single Checkbox"
/>
);
}

Props

NameTypeDescription
checkedbooleanWhether the checkbox is checked.
defaultCheckedbooleanWhether the checkbox is checked by default. Applies only when uncontrolled.
disabledbooleanWhether the checkbox is disabled.
labelReact.ReactNodeA label to display next to the checkbox.
labelTextPropsReact.ComponentProps<typeof Text>Additional props to apply to the label text.
onChange(checked: boolean) => voidA function that is called when the checkbox is changed.

CheckboxGroup

A group of checkboxes.

Usage

import { CheckboxGroup } from "@fedibtc/ui";
import { useState } from "react";

function MyComponent() {
const [checkboxGroupValues, setCheckboxGroupValues] = useState(["one"]);

const groupOptions = [
{
label: "Group option one",
value: "one",
},
{
label: "Group option two",
value: "two",
},
{
label: "Group option three",
value: "three",
disabled: true,
},
];

return (
<CheckboxGroup
options={groupOptions}
values={checkboxGroupValues}
onChange={setCheckboxGroupValues}
/>
);
}

Props

NameTypeDescription
optionsCheckboxOption[]An array of checkbox options.
valuesstring[]An array of values of type T that are checked.
disabledbooleanWhether the group is disabled.
onChange(values: string[]) => voidA function that is called when one or more options are changed.