@talend/react-components
Version:
Set of react components.
58 lines • 1.48 kB
JavaScript
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { omit } from "lodash";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export default function Checkbox({
id,
className,
label,
intermediate,
...props
}) {
let dataFeature;
let dataChecked = 0;
if (!props.disabled && props['data-feature']) {
dataFeature = props['data-feature'];
dataFeature += props.checked ? '.disable' : '.enable';
}
if (intermediate) {
dataChecked = 1;
} else if (props.checked) {
dataChecked = 2;
}
return /*#__PURE__*/_jsx("div", {
className: classNames('checkbox tc-checkbox', {
disabled: props.disabled
}, className),
children: /*#__PURE__*/_jsxs("label", {
htmlFor: id,
"data-feature": dataFeature,
children: [/*#__PURE__*/_jsx("input", {
type: "checkbox",
id: id,
"data-checked": dataChecked,
...omit(props, 'data-feature')
}), /*#__PURE__*/_jsx("span", {
children: label
})]
})
});
}
Checkbox.displayName = 'Checkbox';
Checkbox.defaultProps = {
disabled: false,
checked: false,
intermediate: false,
label: ''
};
Checkbox.propTypes = {
id: PropTypes.string.isRequired,
label: PropTypes.node,
checked: PropTypes.bool,
autoFocus: PropTypes.bool,
disabled: PropTypes.bool,
intermediate: PropTypes.bool,
className: PropTypes.string,
'data-feature': PropTypes.string
};
//# sourceMappingURL=Checkbox.js.map