Skip to content

Instantly share code, notes, and snippets.

@alexmkio
Created November 18, 2025 21:28
Show Gist options
  • Select an option

  • Save alexmkio/4c27eea61fd052f049dc014b3215e956 to your computer and use it in GitHub Desktop.

Select an option

Save alexmkio/4c27eea61fd052f049dc014b3215e956 to your computer and use it in GitHub Desktop.
import * as RadixCheckbox from '@radix-ui/react-checkbox';
import { useId } from 'react';
import CheckmarkIcon from '@components/icons/Checkmark';
import styles from './Checkbox.module.scss';
type CheckboxProps = {
label?: string;
id?: string;
} & RadixCheckbox.CheckboxProps;
const Checkbox = (props: CheckboxProps) => {
const generatedId = useId();
const { label, id = `checkbox-${generatedId}`, checked, onCheckedChange, required = false, disabled = false, name, value } = props;
return (
<div className={styles.container}>
<RadixCheckbox.Root
className={styles.root}
checked={checked}
onCheckedChange={onCheckedChange}
id={id}
required={required}
disabled={disabled}
name={name}
value={value}
>
<RadixCheckbox.Indicator className={styles.indicator}>
{disabled ? <CheckmarkIcon className={styles.disabledIcon} /> : <CheckmarkIcon />}
</RadixCheckbox.Indicator>
</RadixCheckbox.Root>
{label && (
<label className={styles.label} htmlFor={id}>
{label}
</label>
)}
</div>
);
};
export default Checkbox;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment