cinny/src/app/atoms/button/Toggle.jsx

32 lines
710 B
React
Raw Normal View History

2021-07-28 22:15:52 +09:00
import React from 'react';
import PropTypes from 'prop-types';
import './Toggle.scss';
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)}
className={className}
2021-07-28 22:15:52 +09:00
type="button"
disabled={disabled}
2021-07-28 22:15:52 +09:00
/>
);
}
Toggle.defaultProps = {
isActive: false,
disabled: false,
onToggle: null,
2021-07-28 22:15:52 +09:00
};
Toggle.propTypes = {
isActive: PropTypes.bool,
onToggle: PropTypes.func,
disabled: PropTypes.bool,
2021-07-28 22:15:52 +09:00
};
export default Toggle;