| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.Radio = 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 radio_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Radio/radio")); |
| 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 Radio extends react_1.Component { |
| 12 |
constructor(props) { |
| 13 |
super(props); |
| 14 |
this.handleChange = (event) => { |
| 15 |
this.props.onChange(event, event.currentTarget.checked); |
| 16 |
}; |
| 17 |
if (!props.label && !props['aria-label']) { |
| 18 |
// eslint-disable-next-line no-console |
| 19 |
console.error('Radio:', 'Radio requires an aria-label to be specified'); |
| 20 |
} |
| 21 |
} |
| 22 |
render() { |
| 23 |
const _a = this.props, { 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, checked, className, inputClassName, defaultChecked, isLabelWrapped, labelPosition = 'end', isChecked, isDisabled, isValid, label, |
| 24 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 25 |
onChange, description, body, ouiaId, ouiaSafe = true, component } = _a, props = tslib_1.__rest(_a, ['aria-label', 'aria-describedby', "checked", "className", "inputClassName", "defaultChecked", "isLabelWrapped", "labelPosition", "isChecked", "isDisabled", "isValid", "label", "onChange", "description", "body", "ouiaId", "ouiaSafe", "component"]); |
| 26 |
if (!props.id) { |
| 27 |
// eslint-disable-next-line no-console |
| 28 |
console.error('Radio:', 'id is required to make input accessible'); |
| 29 |
} |
| 30 |
return ((0, jsx_runtime_1.jsx)(SSRSafeIds_1.SSRSafeIds, { prefix: "pf-radio-description-", ouiaComponentType: "Radio", children: (descriptionId, generatedOuiaId) => { |
| 31 |
let ariaDescribedByValue; |
| 32 |
if (ariaDescribedBy !== undefined) { |
| 33 |
ariaDescribedByValue = ariaDescribedBy === '' ? undefined : ariaDescribedBy; |
| 34 |
} |
| 35 |
else if (description) { |
| 36 |
ariaDescribedByValue = descriptionId; |
| 37 |
} |
| 38 |
const inputRendered = ((0, jsx_runtime_1.jsx)("input", Object.assign({}, props, { className: (0, react_styles_1.css)(radio_1.default.radioInput, inputClassName), type: "radio", onChange: this.handleChange, "aria-invalid": !isValid, "aria-describedby": ariaDescribedByValue, disabled: isDisabled, checked: checked || isChecked }, (checked === undefined && { defaultChecked }), (!label && { 'aria-label': ariaLabel }), (0, helpers_1.getOUIAProps)(Radio.displayName, ouiaId !== undefined ? ouiaId : generatedOuiaId, ouiaSafe)))); |
| 39 |
const wrapWithLabel = (isLabelWrapped && !component) || component === 'label'; |
| 40 |
const Label = wrapWithLabel ? 'span' : 'label'; |
| 41 |
const labelRendered = label ? ((0, jsx_runtime_1.jsx)(Label, { className: (0, react_styles_1.css)(radio_1.default.radioLabel, isDisabled && radio_1.default.modifiers.disabled), htmlFor: !wrapWithLabel ? props.id : undefined, children: label })) : null; |
| 42 |
const WrapperComponent = component !== null && component !== void 0 ? component : (wrapWithLabel ? 'label' : 'div'); |
| 43 |
return ((0, jsx_runtime_1.jsxs)(WrapperComponent, { className: (0, react_styles_1.css)(radio_1.default.radio, !label && radio_1.default.modifiers.standalone, className), htmlFor: wrapWithLabel ? props.id : undefined, children: [labelPosition === 'start' ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [labelRendered, inputRendered] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [inputRendered, labelRendered] })), description && ((0, jsx_runtime_1.jsx)("span", { id: descriptionId, className: (0, react_styles_1.css)(radio_1.default.radioDescription), children: description })), body && (0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(radio_1.default.radioBody), children: body })] })); |
| 44 |
} })); |
| 45 |
} |
| 46 |
} |
| 47 |
exports.Radio = Radio; |
| 48 |
Radio.displayName = 'Radio'; |
| 49 |
Radio.defaultProps = { |
| 50 |
className: '', |
| 51 |
isDisabled: false, |
| 52 |
isValid: true, |
| 53 |
onChange: () => { } |
| 54 |
}; |
| 55 |
//# sourceMappingURL=Radio.js.map |