Checkbox

A control that allows the user to toggle between checked and not checked.

Installation

Install the following dependencies:

npm install @radix-ui/react-checkbox

Copy and paste the following code into your project.

'use client';
 
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
import clsx from 'clsx';
import { Check } from 'lucide-react';
import { ComponentPropsWithoutRef, ElementRef, forwardRef } from 'react';
import styles from './styles.module.scss';
 
const Checkbox = forwardRef<
    ElementRef<typeof CheckboxPrimitive.Root>,
    ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
    <CheckboxPrimitive.Root ref={ref} className={clsx(styles.checkbox, className)} {...props}>
        <CheckboxPrimitive.Indicator className={clsx(styles.checkbox__indicator)}>
            <Check className={styles.checkbox__icon} />
        </CheckboxPrimitive.Indicator>
    </CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
 
export { Checkbox };

Update the import paths to match your project setup.

Usage

import { Checkbox } from '@/components/ui/checkbox';
<Checkbox />

Examples

With text

You agree to our Terms of Service and Privacy Policy.

Disabled

Form

You can manage your mobile notifications in the mobile settings page.

Select the items you want to display in the sidebar.