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

@react-aria/switch

Package Overview
Dependencies
Maintainers
1
Versions
780
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/switch

Spectrum UI components in React

  • 3.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
394K
decreased by-51.87%
Maintainers
1
Weekly downloads
 
Created

What is @react-aria/switch?

@react-aria/switch is a React library that provides accessible switch components. It is part of the React Aria collection, which aims to provide a set of hooks and components that help developers build accessible web applications. The switch component is used to represent a boolean state that can be toggled by the user.

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

Basic Switch

This code demonstrates a basic switch component using the @react-aria/switch package. The switch can be toggled between 'On' and 'Off' states.

import { useSwitch } from '@react-aria/switch';
import { useToggleState } from '@react-stately/toggle';
import { VisuallyHidden } from '@react-aria/visually-hidden';

function Switch(props) {
  let state = useToggleState(props);
  let ref = React.useRef();
  let { inputProps } = useSwitch(props, state, ref);

  return (
    <label>
      <VisuallyHidden>
        <input {...inputProps} ref={ref} />
      </VisuallyHidden>
      <span>{state.isSelected ? 'On' : 'Off'}</span>
    </label>
  );
}

export default function App() {
  return <Switch />;
}

Custom Styled Switch

This code demonstrates a custom styled switch component using the @react-aria/switch package. The switch is styled using CSS to look like a traditional toggle switch.

import { useSwitch } from '@react-aria/switch';
import { useToggleState } from '@react-stately/toggle';
import { VisuallyHidden } from '@react-aria/visually-hidden';
import './Switch.css';

function Switch(props) {
  let state = useToggleState(props);
  let ref = React.useRef();
  let { inputProps } = useSwitch(props, state, ref);

  return (
    <label className="switch">
      <VisuallyHidden>
        <input {...inputProps} ref={ref} />
      </VisuallyHidden>
      <span className="slider"></span>
    </label>
  );
}

export default function App() {
  return <Switch />;
}

Other packages similar to @react-aria/switch

FAQs

Package last updated on 15 Jul 2020

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