Component
Checkbox

Checkbox

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

Installation

Install the following dependencies

npm i @radix-ui/react-checkbox

Copy and paste the following code into your project

components/ui/checkbox/index.tsx
'use client'
 
import * as React from 'react'
import * as CheckboxPrimitive from '@radix-ui/react-checkbox'
import { Check } from 'lucide-react'
import { styled } from '@shadow-panda/styled-system/jsx'
import { cx } from '@shadow-panda/styled-system/css'
import { checkbox, icon } from '@shadow-panda/styled-system/recipes'
 
const BaseCheckbox = React.forwardRef<
  React.ElementRef<typeof CheckboxPrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => {
  const styles = checkbox()
 
  return (
    <CheckboxPrimitive.Root ref={ref} className={cx('peer', styles.root, className)} {...props}>
      <CheckboxPrimitive.Indicator className={styles.indicator}>
        <Check className={icon()} />
      </CheckboxPrimitive.Indicator>
    </CheckboxPrimitive.Root>
  )
})
BaseCheckbox.displayName = CheckboxPrimitive.Root.displayName
 
export const Checkbox = styled(BaseCheckbox)

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.