A control for a binary or indeterminate choice. The Checkbox component extends Base UI's Checkbox. Checkbox.Indicator renders a check icon, or a minus icon when the checkbox is indeterminate.
Here is the component implementation code that you can copy to your project:
// https://devie-ui.com/components/checkbox
// https://base-ui.com/react/components/checkbox
import { Checkbox as BaseCheckbox } from "@base-ui/react/checkbox";
import clsx from "clsx";
import { Check, Minus } from "lucide-react";
import styles from "./Checkbox.module.scss";
function Root({ className, ...props }: Checkbox.Root.Props) {
return (
<BaseCheckbox.Root className={clsx(styles.root, className)} {...props} />
);
}
function Indicator({
className,
children,
...props
}: Checkbox.Indicator.Props) {
return (
<BaseCheckbox.Indicator
className={clsx(styles.indicator, className)}
{...props}
>
{children || (
<>
<Check
className={clsx(styles.icon, styles.checkIcon)}
strokeWidth={2.5}
/>
<Minus
className={clsx(styles.icon, styles.indeterminateIcon)}
strokeWidth={2.5}
/>
</>
)}
</BaseCheckbox.Indicator>
);
}
const Checkbox = {
Root,
Indicator,
};
namespace Checkbox {
export namespace Root {
export type Props = Omit<BaseCheckbox.Root.Props, "className"> & {
className?: string;
};
export type State = BaseCheckbox.Root.State;
export type ChangeEventDetails = BaseCheckbox.Root.ChangeEventDetails;
}
export namespace Indicator {
export type Props = Omit<BaseCheckbox.Indicator.Props, "className"> & {
className?: string;
};
}
}
export default Checkbox;Wrap Checkbox.Root and its text in a label element so the text toggles the checkbox.
Place the checkbox inside Field.Label within a Field. The name on Field.Root submits the value with the Form.
Set defaultChecked, indeterminate, or disabled on Checkbox.Root. For a select-all checkbox, use the CheckboxGroup parent checkbox.