2021-03-08 12:40:34 -05:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 10:38:10 -04:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2023-02-03 14:52:07 -05:00
|
|
|
import classNames from 'classnames';
|
2021-03-08 12:40:34 -05:00
|
|
|
|
2023-05-28 10:38:10 -04:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
|
|
|
|
|
2023-05-28 08:18:23 -04:00
|
|
|
export default class PillBarButton extends PureComponent {
|
2021-03-08 12:40:34 -05:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
prefix: PropTypes.string,
|
|
|
|
settings: ImmutablePropTypes.map.isRequired,
|
|
|
|
settingPath: PropTypes.array.isRequired,
|
|
|
|
label: PropTypes.node.isRequired,
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
disabled: PropTypes.bool,
|
2023-02-03 14:52:07 -05:00
|
|
|
};
|
2021-03-08 12:40:34 -05:00
|
|
|
|
|
|
|
onChange = () => {
|
|
|
|
const { settings, settingPath } = this.props;
|
|
|
|
this.props.onChange(settingPath, !settings.getIn(settingPath));
|
2023-02-03 14:52:07 -05:00
|
|
|
};
|
2021-03-08 12:40:34 -05:00
|
|
|
|
|
|
|
render () {
|
|
|
|
const { prefix, settings, settingPath, label, disabled } = this.props;
|
|
|
|
const id = ['setting-pillbar-button', prefix, ...settingPath].filter(Boolean).join('-');
|
|
|
|
const active = settings.getIn(settingPath);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
key={id}
|
|
|
|
id={id}
|
|
|
|
className={classNames('pillbar-button', { active })}
|
|
|
|
disabled={disabled}
|
|
|
|
onClick={this.onChange}
|
|
|
|
aria-pressed={active}
|
|
|
|
>
|
|
|
|
{label}
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|