forked from epicweb-dev/advanced-react-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch.js
More file actions
48 lines (44 loc) · 1.26 KB
/
Copy pathswitch.js
File metadata and controls
48 lines (44 loc) · 1.26 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
import './switch.styles.css'
import React from 'react'
// STOP! You should not have to change anything in this file to
// make it through the workshop. If tests are failing because of
// this switch not having properties set correctly, then the
// problem is probably in your implementation. Tip: Check
// your `render` method or the `getTogglerProps` method
// (if we've gotten to that part)
// this is here to fill in for the onChange handler
// we're not using onChange because it seems to behave
// differently in codesandbox and locally :shrug:
const noop = () => {}
class Switch extends React.Component {
render() {
const {
on,
className = '',
'aria-label': ariaLabel,
onClick,
...props
} = this.props
const btnClassName = [
className,
'toggle-btn',
on ? 'toggle-btn-on' : 'toggle-btn-off',
]
.filter(Boolean)
.join(' ')
return (
<label aria-label={ariaLabel || 'Toggle'} style={{display: 'block'}}>
<input
className="toggle-input"
type="checkbox"
checked={on}
onChange={noop}
onClick={onClick}
data-testid="toggle-input"
/>
<span className={btnClassName} {...props} />
</label>
)
}
}
export {Switch}