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