UNPKG

@pantheon-systems/design-toolkit-react

Version:
47 lines (44 loc) 1.51 kB
import { faMinus, faCheck } from '@fortawesome/pro-regular-svg-icons'; import PropTypes from 'prop-types'; import { useEffect } from 'react'; import CustomCheckbox from './CustomCheckbox.js'; import { jsx } from 'react/jsx-runtime'; var SelectAllCheckbox = function SelectAllCheckbox(_ref) { var checkState = _ref.checkState, formApi = _ref.formApi, label = _ref.label, onChange = _ref.onChange, selectAllField = _ref.selectAllField; var icon = checkState === 'mixed' ? faMinus : faCheck; useEffect(function () { if (checkState || checkState === 'mixed') { formApi.setValue(selectAllField, true); } else { formApi.setValue(selectAllField, false); } }, [checkState, formApi, selectAllField]); return /*#__PURE__*/jsx(CustomCheckbox, { "aria-checked": checkState, className: "min-h-8" // Make sure even a blank label maintains height , field: selectAllField, icon: icon, onChange: onChange, children: label }); }; SelectAllCheckbox.defaultProps = { checkState: false }; SelectAllCheckbox.propTypes = { checkState: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['mixed'])]), formApi: PropTypes.shape({ setValue: PropTypes.func.isRequired }).isRequired, label: PropTypes.string.isRequired, onChange: PropTypes.func.isRequired, selectAllField: PropTypes.string.isRequired }; var SelectAllCheckbox$1 = SelectAllCheckbox; export { SelectAllCheckbox$1 as default }; //# sourceMappingURL=SelectAllCheckbox.js.map