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

@radix-ui/react-toggle

Package Overview
Dependencies
Maintainers
6
Versions
156
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-toggle

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2M
decreased by-54.4%
Maintainers
6
Weekly downloads
 
Created

What is @radix-ui/react-toggle?

@radix-ui/react-toggle is a React component library that provides accessible and customizable toggle buttons. 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-toggle's main functionalities?

Basic Toggle Button

This code demonstrates a basic toggle button using the @radix-ui/react-toggle package. The Toggle.Root component is the container, and the Toggle.Thumb component represents the toggle switch.

import * as Toggle from '@radix-ui/react-toggle';

function App() {
  return (
    <Toggle.Root>
      <Toggle.Thumb />
    </Toggle.Root>
  );
}

export default App;

Controlled Toggle Button

This code demonstrates a controlled toggle button where the toggle state is managed by a React useState hook. The pressed prop is used to control the toggle state, and the onPressedChange prop is used to update the state.

import * as Toggle from '@radix-ui/react-toggle';
import { useState } from 'react';

function App() {
  const [isToggled, setIsToggled] = useState(false);

  return (
    <Toggle.Root pressed={isToggled} onPressedChange={setIsToggled}>
      <Toggle.Thumb />
    </Toggle.Root>
  );
}

export default App;

Custom Styled Toggle Button

This code demonstrates how to apply custom styles to the toggle button using CSS classes. The className prop is used to add custom styles to the Toggle.Root and Toggle.Thumb components.

import * as Toggle from '@radix-ui/react-toggle';
import './App.css';

function App() {
  return (
    <Toggle.Root className="custom-toggle">
      <Toggle.Thumb className="custom-thumb" />
    </Toggle.Root>
  );
}

export default App;

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

FAQs

Package last updated on 19 Jun 2024

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