2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-03-24 04:39:12 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import Switch from './switch'
|
|
|
|
|
2020-08-18 01:57:35 +01:00
|
|
|
class SettingSwitch extends ImmutablePureComponent {
|
2020-03-24 04:39:12 +00:00
|
|
|
|
2020-05-03 06:22:49 +01:00
|
|
|
updateOnProps = [
|
|
|
|
'prefix',
|
|
|
|
'settings',
|
|
|
|
'settingPath',
|
|
|
|
'description',
|
|
|
|
'label',
|
|
|
|
]
|
|
|
|
|
2020-09-01 20:54:17 +01:00
|
|
|
onChange = (checked) => {
|
|
|
|
this.props.onChange(this.props.settingPath, checked)
|
2020-03-24 04:39:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
prefix,
|
|
|
|
settings,
|
|
|
|
settingPath,
|
|
|
|
label,
|
|
|
|
description
|
|
|
|
} = this.props
|
|
|
|
|
2020-04-09 20:18:14 +01:00
|
|
|
const isArray = Array.isArray(settingPath)
|
|
|
|
const checked = isArray ? settings.getIn(settingPath) : settings.get(settingPath)
|
|
|
|
const idVal = isArray ? settingPath.join('-') : settingPath
|
|
|
|
const id = ['setting-toggle', prefix, idVal].filter(Boolean).join('-')
|
|
|
|
|
2020-03-24 04:39:12 +00:00
|
|
|
return (
|
|
|
|
<Switch
|
|
|
|
description={description}
|
|
|
|
label={label}
|
|
|
|
id={id}
|
2020-04-09 20:18:14 +01:00
|
|
|
checked={checked}
|
2020-03-24 04:39:12 +00:00
|
|
|
onChange={this.onChange}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-18 01:57:35 +01:00
|
|
|
|
|
|
|
SettingSwitch.propTypes = {
|
|
|
|
prefix: PropTypes.string,
|
|
|
|
settings: ImmutablePropTypes.map.isRequired,
|
|
|
|
settingPath: PropTypes.oneOfType([
|
|
|
|
PropTypes.array,
|
|
|
|
PropTypes.string,
|
|
|
|
]).isRequired,
|
|
|
|
description: PropTypes.string,
|
|
|
|
label: PropTypes.string.isRequired,
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SettingSwitch
|