| 1 |
import { __rest } from "tslib"; |
| 2 |
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; |
| 3 |
import { Component } from 'react'; |
| 4 |
import styles from '@patternfly/react-styles/css/components/Check/check.mjs'; |
| 5 |
import { css } from '@patternfly/react-styles'; |
| 6 |
import { getOUIAProps } from '../../helpers'; |
| 7 |
import { SSRSafeIds } from '../../helpers/SSRSafeIds/SSRSafeIds'; |
| 8 |
class MenuToggleCheckbox extends Component { |
| 9 |
constructor() { |
| 10 |
super(...arguments); |
| 11 |
this.handleChange = (event) => { |
| 12 |
this.props.onChange(event.target.checked, event); |
| 13 |
}; |
| 14 |
this.calculateChecked = () => { |
| 15 |
const { isChecked, defaultChecked } = this.props; |
| 16 |
if (isChecked === null) { |
| 17 |
// return false here and the indeterminate state will be set to true through the ref |
| 18 |
return false; |
| 19 |
} |
| 20 |
else if (isChecked !== undefined) { |
| 21 |
return isChecked; |
| 22 |
} |
| 23 |
return defaultChecked; |
| 24 |
}; |
| 25 |
} |
| 26 |
render() { |
| 27 |
const _a = this.props, { className, isValid, isDisabled, isChecked, children, ouiaId, ouiaSafe, |
| 28 |
/* eslint-disable @typescript-eslint/no-unused-vars */ |
| 29 |
onChange, defaultChecked, id } = _a, props = __rest(_a, ["className", "isValid", "isDisabled", "isChecked", "children", "ouiaId", "ouiaSafe", "onChange", "defaultChecked", "id"]); |
| 30 |
const text = children && (_jsx("span", { className: css(styles.checkLabel, className), "aria-hidden": "true", id: id, children: children })); |
| 31 |
return (_jsx(SSRSafeIds, { prefix: "pf-", ouiaComponentType: MenuToggleCheckbox.displayName, children: (_, generatedOuiaId) => (_jsxs("label", { className: css(styles.check, !children && styles.modifiers.standalone, className), children: [_jsx("input", Object.assign({ className: css(styles.checkInput) }, (this.calculateChecked() !== undefined && { onChange: this.handleChange }), { name: id, type: "checkbox", ref: (elem) => { |
| 32 |
elem && (elem.indeterminate = isChecked === null); |
| 33 |
}, "aria-invalid": !isValid, disabled: isDisabled }, (defaultChecked !== undefined ? { defaultChecked } : { checked: this.calculateChecked() }), getOUIAProps(MenuToggleCheckbox.displayName, ouiaId !== undefined ? ouiaId : generatedOuiaId, ouiaSafe), props)), text] })) })); |
| 34 |
} |
| 35 |
} |
| 36 |
MenuToggleCheckbox.displayName = 'MenuToggleCheckbox'; |
| 37 |
MenuToggleCheckbox.defaultProps = { |
| 38 |
isValid: true, |
| 39 |
isDisabled: false, |
| 40 |
onChange: () => undefined |
| 41 |
}; |
| 42 |
export { MenuToggleCheckbox }; |
| 43 |
//# sourceMappingURL=MenuToggleCheckbox.js.map |