Socket
Socket
Sign inDemoInstall

@radix-ui/react-checkbox

Package Overview
Dependencies
18
Maintainers
6
Versions
180
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @radix-ui/react-checkbox


Version published
Weekly downloads
1.1M
increased by10.73%
Maintainers
6
Install size
500 kB
Created
Weekly downloads
 

Package description

What is @radix-ui/react-checkbox?

@radix-ui/react-checkbox is a React component library that provides accessible and customizable checkbox components. It is part of the Radix UI suite, which focuses on providing unstyled, accessible components that can be easily styled to fit any design system.

What are @radix-ui/react-checkbox's main functionalities?

Basic Checkbox

This code demonstrates a basic checkbox component using @radix-ui/react-checkbox. The Checkbox.Root component is the main container, and Checkbox.Indicator is used to display the checkmark or other indicator.

import * as Checkbox from '@radix-ui/react-checkbox';

function BasicCheckbox() {
  return (
    <Checkbox.Root>
      <Checkbox.Indicator />
    </Checkbox.Root>
  );
}

Custom Styling

This example shows how to apply custom styles to the checkbox component. By adding className properties, you can style the checkbox and its indicator using CSS.

import * as Checkbox from '@radix-ui/react-checkbox';
import './styles.css';

function CustomStyledCheckbox() {
  return (
    <Checkbox.Root className="custom-checkbox">
      <Checkbox.Indicator className="custom-indicator" />
    </Checkbox.Root>
  );
}

Controlled Checkbox

This code demonstrates a controlled checkbox component where the checked state is managed by React's useState hook. The onCheckedChange event handler updates the state when the checkbox is toggled.

import * as Checkbox from '@radix-ui/react-checkbox';
import { useState } from 'react';

function ControlledCheckbox() {
  const [checked, setChecked] = useState(false);

  return (
    <Checkbox.Root checked={checked} onCheckedChange={setChecked}>
      <Checkbox.Indicator />
    </Checkbox.Root>
  );
}

Other packages similar to @radix-ui/react-checkbox

Readme

Source

react-checkbox

Installation

$ yarn add @radix-ui/react-checkbox
# or
$ npm install @radix-ui/react-checkbox

Usage

View docs here.

FAQs

Last updated on 10 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc