2021-07-28 22:15:52 +09:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import './Toggle.scss';
|
|
|
|
|
2021-12-31 21:08:25 +09:00
|
|
|
function Toggle({ isActive, onToggle, disabled }) {
|
|
|
|
const className = `toggle${isActive ? ' toggle--active' : ''}`;
|
|
|
|
if (onToggle === null) return <span className={className} />;
|
2021-07-28 22:15:52 +09:00
|
|
|
return (
|
|
|
|
// eslint-disable-next-line jsx-a11y/control-has-associated-label
|
|
|
|
<button
|
|
|
|
onClick={() => onToggle(!isActive)}
|
2021-12-31 21:08:25 +09:00
|
|
|
className={className}
|
2021-07-28 22:15:52 +09:00
|
|
|
type="button"
|
2021-12-31 21:08:25 +09:00
|
|
|
disabled={disabled}
|
2021-07-28 22:15:52 +09:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Toggle.defaultProps = {
|
|
|
|
isActive: false,
|
2021-12-31 21:08:25 +09:00
|
|
|
disabled: false,
|
|
|
|
onToggle: null,
|
2021-07-28 22:15:52 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
Toggle.propTypes = {
|
|
|
|
isActive: PropTypes.bool,
|
2021-12-31 21:08:25 +09:00
|
|
|
onToggle: PropTypes.func,
|
|
|
|
disabled: PropTypes.bool,
|
2021-07-28 22:15:52 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Toggle;
|