-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathToggle.js
More file actions
63 lines (58 loc) · 1.83 KB
/
Toggle.js
File metadata and controls
63 lines (58 loc) · 1.83 KB
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
53
54
55
56
57
58
59
60
61
62
63
import React, { PropTypes, Component } from 'react';
import classnames from 'classnames';
import FormElement from './FormElement';
export default class Toggle extends Component {
renderToggle({ className, statusOn, statusOff, statusDisabled, disabled, label, ...props }) {
const toggleClassNames = classnames(className, 'slds-checkbox--toggle slds-grid');
return (
<label className={ toggleClassNames }>
<span className='slds-form-element__label slds-m-bottom--none'>{ label }</span>
<input
name='checkbox'
type='checkbox'
aria-describedby='toggle-desc'
{ ...props }
/>
<span
className='slds-checkbox--faux_container'
aria-live='assertive'
>
<span className='slds-checkbox--faux' />
<span className='slds-checkbox--on'>{!disabled && statusOn}</span>
<span className='slds-checkbox--off'>{disabled === true ? statusDisabled : statusOff}</span>
</span>
</label>
);
}
render() {
const { required, error, totalCols, cols, ...props } = this.props;
const formElemProps = { required, error, totalCols, cols };
return (
<FormElement
formElementRef={node => (this.node = node)}
{ ...formElemProps }
>
{ this.renderToggle(props) }
</FormElement>
);
}
}
Toggle.propTypes = {
className: PropTypes.string,
label: PropTypes.string,
required: PropTypes.bool,
error: FormElement.propTypes.error,
totalCols: PropTypes.number,
cols: PropTypes.number,
name: PropTypes.string,
value: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
checked: PropTypes.bool,
defaultChecked: PropTypes.bool,
disabled: PropTypes.bool,
statusOn: PropTypes.string,
statusOff: PropTypes.string,
statusDisabled: PropTypes.string,
};