UNPKG

@talend/react-components

Version:
56 lines 1.7 kB
import { Fragment } from 'react'; import PropTypes from 'prop-types'; import RowLabel from '../RowLabel'; import { Form, SizedIcon } from '@talend/design-system'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const RowCheckbox = ({ dataFeature, description, id, label, locked = false, onChange, checked = false, intermediate = false }) => { const onChangeCheckbox = event => { // Force to pass a checked state in case of intermediate checkbox const checkedState = intermediate ? true : event.target.checked; onChange(checkedState, label); }; const describedby = `${id}-${description}`; return locked ? /*#__PURE__*/_jsxs(Fragment, { children: [/*#__PURE__*/_jsx(SizedIcon, { name: "locker-closed", size: "M" }), /*#__PURE__*/_jsx(RowLabel, { label: label })] }) : /*#__PURE__*/_jsxs(Fragment, { children: [/*#__PURE__*/_jsx(Form.Checkbox, { checked: checked, "data-feature": dataFeature, "aria-describedby": describedby, id: `${id}-checkbox-${label.replace(/\s+/g, '-')}`, label: label, onChange: onChangeCheckbox, indeterminate: intermediate }), /*#__PURE__*/_jsx("div", { id: describedby, className: "sr-only", children: description })] }); }; RowCheckbox.propTypes = { dataFeature: PropTypes.string.isRequired, description: PropTypes.string.isRequired, id: PropTypes.string.isRequired, label: PropTypes.string.isRequired, locked: PropTypes.bool, onChange: PropTypes.func.isRequired, checked: PropTypes.bool, intermediate: PropTypes.bool }; export default RowCheckbox; //# sourceMappingURL=RowCheckbox.component.js.map