Files
blitzkit/packages/website/src/components/Checkbox/index.tsx
T

42 lines
978 B
TypeScript
Raw Normal View History

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";
import { composeRadixComponents } from "../../ui/compose";
2026-10-12 00:04:47 -05:00
import styles from "./index.module.css";
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}>
<_.Root
2026-10-12 00:04:47 -05:00
id={id}
checked={checked}
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>
);
}