Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@radix-ui/react-switch

Package Overview
Dependencies
Maintainers
8
Versions
166
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-switch

  • 0.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5M
increased by5.72%
Maintainers
8
Weekly downloads
 
Created

What is @radix-ui/react-switch?

@radix-ui/react-switch is a React component library that provides accessible and customizable switch components. These switches can be used to toggle between two states, such as on and off, and are designed to be highly customizable and accessible out of the box.

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

Basic Switch

This code demonstrates a basic switch component using @radix-ui/react-switch. The Switch.Root component is the container, and the Switch.Thumb component represents the draggable part of the switch.

import * as Switch from '@radix-ui/react-switch';

function BasicSwitch() {
  return (
    <Switch.Root>
      <Switch.Thumb />
    </Switch.Root>
  );
}

Customizable Switch

This code shows how to customize the appearance of the switch by applying custom CSS classes. The 'custom-switch' and 'custom-thumb' classes can be defined in an external CSS file to style the switch and its thumb.

import * as Switch from '@radix-ui/react-switch';
import './switch.css';

function CustomSwitch() {
  return (
    <Switch.Root className="custom-switch">
      <Switch.Thumb className="custom-thumb" />
    </Switch.Root>
  );
}

Controlled Switch

This example demonstrates a controlled switch component where the switch's state is managed by a React useState hook. The 'checked' prop is used to control the switch's state, and the 'onCheckedChange' prop is used to update the state.

import * as Switch from '@radix-ui/react-switch';
import { useState } from 'react';

function ControlledSwitch() {
  const [isChecked, setIsChecked] = useState(false);

  return (
    <Switch.Root checked={isChecked} onCheckedChange={setIsChecked}>
      <Switch.Thumb />
    </Switch.Root>
  );
}

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

FAQs

Package last updated on 10 Dec 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc