cinny/src/app/atoms/button/Toggle.jsx
Ajay Bura a0399b7f5e Add disabled attribute in Checkbox, Toggle and RadioButton
Signed-off-by: Ajay Bura <ajbura@gmail.com>
2021-12-31 17:38:25 +05:30

31 lines
710 B
JavaScript

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} />;
return (
// eslint-disable-next-line jsx-a11y/control-has-associated-label
<button
onClick={() => onToggle(!isActive)}
className={className}
type="button"
disabled={disabled}
/>
);
}
Toggle.defaultProps = {
isActive: false,
disabled: false,
onToggle: null,
};
Toggle.propTypes = {
isActive: PropTypes.bool,
onToggle: PropTypes.func,
disabled: PropTypes.bool,
};
export default Toggle;