-
Notifications
You must be signed in to change notification settings - Fork 307
/
Switch.js
52 lines (48 loc) · 935 Bytes
/
Switch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React from 'react';
import PropTypes from 'prop-types';
import idgen from './idgen';
const Switch = ({ id, offLabel, onLabel, ...props }) => (
<div className="switch">
<label htmlFor={id}>
{offLabel}
<input id={id} type="checkbox" {...props} />
<span className="lever" />
{onLabel}
</label>
</div>
);
Switch.propTypes = {
/**
* override id
* @default idgen()
*/
id: PropTypes.string,
className: PropTypes.string,
/**
* label for off
*/
offLabel: PropTypes.string.isRequired,
/**
* label for on
*/
onLabel: PropTypes.string.isRequired,
/**
* onChange callback
*/
onChange: PropTypes.func,
/**
* disabled input
*/
disabled: PropTypes.bool,
/**
* initialise checkbox checked
*/
checked: PropTypes.bool
};
Switch.defaultProps = {
get id() {
return `Switch-${idgen()}`;
},
onChange: () => {}
};
export default Switch;