react-input-switch

2.2.2 • Public • Published

react-input-switch

npm npm Build Status codecov styled with prettier

React toggle switch component

Installation

npm install react-input-switch --save
yarn add react-input-switch

Demo

https://swiftcarrot.dev/react-input-switch/

Custom styles

<Switch
  styles={{
    track: {
      backgroundColor: 'blue'
    },
    trackChecked: {
      backgroundColor: 'red'
    },
    button: {
      backgroundColor: 'yellow'
    },
    buttonChecked: {
      backgroundColor: 'blue'
    }
  }}
/>

Controlled example (with hook)

import React, { useState } from 'react';
import Switch from 'react-input-switch';
 
const App = () => {
  const [value, setValue] = useState(0);
 
  return <Switch value={value} onChange={setValue} />;
};

Custom on/off value

The default on/off value is 1/0 and default value is 1. This component will also render a hidden input (<input type="hidden"/>) with current value and the name prop.

import React, { useState } from 'react';
import Switch from 'react-input-switch';
 
const App = () => {
  const [value, setValue] = useState('yes');
 
  return <Switch on="yes" off="no" value={value} onChange={setValue} />;
};

License

MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.2.21,194latest

Version History

VersionDownloads (Last 7 Days)Published
2.2.21,194
2.2.19
2.2.00
2.1.310
2.1.300
2.1.290
2.1.280
2.1.270
2.1.250
2.1.240
2.1.230
2.1.220
2.1.210
2.1.190
2.1.180
2.1.170
2.1.160
2.1.150
2.1.140
2.1.130
2.1.120
2.1.110
2.1.100
2.1.90
2.1.80
2.1.60
2.1.50
2.1.40
2.1.30
2.1.20
2.1.10
2.1.00
2.0.4-alpha.00
2.0.3-alpha.00
2.0.2-alpha.00
2.0.1-alpha.00
2.0.0-alpha.00
1.2.10
1.2.00
1.1.00
1.0.10
1.0.00

Package Sidebar

Install

npm i react-input-switch

Weekly Downloads

876

Version

2.2.2

License

MIT

Unpacked Size

9.99 kB

Total Files

5

Last publish

Collaborators

  • adjusted