-
Notifications
You must be signed in to change notification settings - Fork 516
Expand file tree
/
Copy pathSwitch.js
More file actions
55 lines (52 loc) · 1.5 KB
/
Switch.js
File metadata and controls
55 lines (52 loc) · 1.5 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
// import propTypes from 'prop-types';
import React, { PureComponent } from 'react'
import RCSwitch from 'rc-switch'
import Icon from './Icon'
export default class Switch extends PureComponent {
static displayName = 'Switch'
static propTypes = {}
render() {
const { checked, darkMode, offMarkup, onChange, onMarkup } = this.props
if (E2E) {
return (
<div style={{ display: 'inline-block', height: '28px' }}>
<button
role='switch'
type='button'
style={{
color: 'black',
pointerEvents: 'all',
position: 'relative',
}}
className={checked ? 'switch-checked' : 'switch-unchecked'}
{...this.props}
onClick={() => {
onChange(!this.props.checked)
}}
>
{checked ? offMarkup || 'On' : onMarkup || 'Off'}
</button>
</div>
)
}
if (darkMode) {
return (
<button
role='switch'
type='button'
className={`rc-switch flex-row justify-content-center gap-3 ${
checked ? 'rc-switch-checked' : 'rc-switch-unchecked'
}`}
{...this.props}
onClick={() => {
onChange(!checked)
}}
>
<Icon name='sun' fill={checked ? '#656D7B' : '#1A2634'} />
<Icon name='moon' fill={checked ? '#FFFFFF' : '#9DA4AE'} />
</button>
)
}
return <RCSwitch {...this.props} />
}
}