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

react-js-switch

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-js-switch

Switch is a visual toggle between two mutually exclusive states — on and off.

  • 1.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
124
decreased by-10.79%
Maintainers
1
Weekly downloads
 
Created
Source

react-js-switch

  • Switch is a visual toggle between two mutually exclusive states — on and off.

Installation

npm install react-js-switch

Usage

//...

import Switch from 'react-js-switch';

export default function App() {
  const [isSwitchOn, setIsSwitchOn] = useState(true);

  const switch_onChange_handle = () => {
    setIsSwitchOn(!isSwitchOn);
    //...
  };

  return (
    <div>
      //...
      <Switch value={isSwitchOn} onChange={switch_onChange_handle} />
      //...
    </div>
  );
}

Props

value : [Boolean] [optional]

  • Value of the switch, true means 'on', false means 'off'.

initialValue : [Boolean] [optional]

  • Value of the switch on the first render, true means 'on', false means 'off'.
  • Note: this prop will be overwritten by the value prop.

size : [Number] [optional]

  • The size of the switch in pixels.
  • Default Value 40

duration : [Number] [optional]

  • Switch On/Off animation duration in ms.
  • Default Value 250

ease : [String] [optional]

  • Switch On/Off animation timing function.
  • Check easings.net to learn more.
  • Default Value easeOutExpo
  • If you want to provide your own timing-function make sure that the function takes one parameter and returns one value.
function easeInQuad(x) {
  return x * x;
}

color : [String] [optional]

  • Custom color for switch circle button.
  • Default Value #fff

backgroundColor : [String] [optional]

  • Switch container background color when it's on or off.
  • Default Value { on: '#fc3f7f', off: '#f9f9f9' }

borderColor : [String] [optional]

  • Switch container border color when it's on or off.
  • Default Value { on: '#fc3f7f', off: '#e6e6e6' }

disabled : [Boolean] [optional]

  • Disable toggling the switch.
  • Default Value false

onChange : [ (state: Boolean) => void ] [optional]

  • Callback called with the new value when it changes.
  • Takes a parameter represents switch state, this parameter will return null if the switch value linked to a state.

Keywords

FAQs

Package last updated on 20 Nov 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