react-js-switch
TypeScript icon, indicating that this package has built-in type declarations

1.1.6 • Public • Published

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.

Package Sidebar

Install

npm i react-js-switch

Weekly Downloads

165

Version

1.1.6

License

ISC

Unpacked Size

18 kB

Total Files

4

Last publish

Collaborators

  • alabsi91