2026-11-14 01:17:38 -06:00
|
|
|
import { CheckIcon } from "@radix-ui/react-icons";
|
|
|
|
|
import { Checkbox as _Checkbox } from "radix-ui";
|
2026-10-12 00:04:47 -05:00
|
|
|
import { useId, type ReactNode } from "react";
|
|
|
|
|
import { Text } from "../Text";
|
2026-11-14 01:17:38 -06:00
|
|
|
import { composeRadixComponents } from "../../ui/compose";
|
2026-10-12 00:04:47 -05:00
|
|
|
import styles from "./index.module.css";
|
|
|
|
|
|
2026-11-14 01:17:38 -06:00
|
|
|
const _ = composeRadixComponents(_Checkbox, styles);
|
|
|
|
|
|
2026-10-12 00:04:47 -05:00
|
|
|
export interface CheckboxProps {
|
|
|
|
|
checked: boolean;
|
|
|
|
|
onCheckedChange(checked: boolean): void;
|
|
|
|
|
children?: ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function Checkbox({
|
|
|
|
|
checked,
|
|
|
|
|
onCheckedChange,
|
|
|
|
|
children,
|
|
|
|
|
}: CheckboxProps) {
|
|
|
|
|
const id = useId();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={styles.checkbox}>
|
2026-11-14 01:17:38 -06:00
|
|
|
<_.Root
|
2026-10-12 00:04:47 -05:00
|
|
|
id={id}
|
|
|
|
|
checked={checked}
|
2026-11-14 01:17:38 -06:00
|
|
|
onCheckedChange={(value) => onCheckedChange(value === true)}
|
|
|
|
|
>
|
|
|
|
|
<_.Indicator>
|
|
|
|
|
<CheckIcon />
|
|
|
|
|
</_.Indicator>
|
|
|
|
|
</_.Root>
|
2026-10-12 00:04:47 -05:00
|
|
|
|
|
|
|
|
{children && (
|
|
|
|
|
<label htmlFor={id}>
|
|
|
|
|
<Text lowContrast>{children}</Text>
|
|
|
|
|
</label>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|