2.2.2 • Published 4 years ago

react-input-switch v2.2.2

Weekly downloads
1,535
License
MIT
Repository
github
Last release
4 years ago

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

2.2.2

4 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.31

5 years ago

2.1.30

5 years ago

2.1.29

5 years ago

2.1.28

5 years ago

2.1.27

5 years ago

2.1.25

5 years ago

2.1.24

5 years ago

2.1.23

5 years ago

2.1.22

5 years ago

2.1.21

5 years ago

2.1.19

5 years ago

2.1.18

5 years ago

2.1.17

5 years ago

2.1.16

5 years ago

2.1.15

5 years ago

2.1.14

5 years ago

2.1.13

5 years ago

2.1.12

5 years ago

2.1.11

5 years ago

2.1.10

5 years ago

2.1.9

5 years ago

2.1.8

5 years ago

2.1.6

5 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.4-alpha.0

5 years ago

2.0.3-alpha.0

5 years ago

2.0.2-alpha.0

5 years ago

2.0.1-alpha.0

5 years ago

2.0.0-alpha.0

5 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago