1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.FormGroup = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const React = tslib_1.__importStar(require("react"));
|
6 | const form_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Form/form"));
|
7 | const htmlConstants_1 = require("../../helpers/htmlConstants");
|
8 | const react_styles_1 = require("@patternfly/react-styles");
|
9 | const constants_1 = require("../../helpers/constants");
|
10 | const FormGroup = (_a) => {
|
11 | var { children = null, className = '', label, labelInfo, labelIcon, isRequired = false, validated = 'default', isInline = false, hasNoPaddingTop = false, isStack = false, helperText, isHelperTextBeforeField = false, helperTextInvalid, helperTextIcon, helperTextInvalidIcon, fieldId } = _a, props = tslib_1.__rest(_a, ["children", "className", "label", "labelInfo", "labelIcon", "isRequired", "validated", "isInline", "hasNoPaddingTop", "isStack", "helperText", "isHelperTextBeforeField", "helperTextInvalid", "helperTextIcon", "helperTextInvalidIcon", "fieldId"]);
|
12 | const validHelperText = typeof helperText !== 'string' ? (helperText) : (React.createElement("div", { className: react_styles_1.css(form_1.default.formHelperText, validated === constants_1.ValidatedOptions.success && form_1.default.modifiers.success, validated === constants_1.ValidatedOptions.warning && form_1.default.modifiers.warning), id: `${fieldId}-helper`, "aria-live": "polite" },
|
13 | helperTextIcon && React.createElement("span", { className: react_styles_1.css(form_1.default.formHelperTextIcon) }, helperTextIcon),
|
14 | helperText));
|
15 | const inValidHelperText = typeof helperTextInvalid !== 'string' ? (helperTextInvalid) : (React.createElement("div", { className: react_styles_1.css(form_1.default.formHelperText, form_1.default.modifiers.error), id: `${fieldId}-helper`, "aria-live": "polite" },
|
16 | helperTextInvalidIcon && React.createElement("span", { className: react_styles_1.css(form_1.default.formHelperTextIcon) }, helperTextInvalidIcon),
|
17 | helperTextInvalid));
|
18 | const showValidHelperTxt = (validationType) => validationType !== constants_1.ValidatedOptions.error && helperText ? validHelperText : '';
|
19 | const helperTextToDisplay = validated === constants_1.ValidatedOptions.error && helperTextInvalid ? inValidHelperText : showValidHelperTxt(validated);
|
20 | const labelContent = (React.createElement(React.Fragment, null,
|
21 | React.createElement("label", { className: react_styles_1.css(form_1.default.formLabel), htmlFor: fieldId },
|
22 | React.createElement("span", { className: react_styles_1.css(form_1.default.formLabelText) }, label),
|
23 | isRequired && (React.createElement("span", { className: react_styles_1.css(form_1.default.formLabelRequired), "aria-hidden": "true" },
|
24 | ' ',
|
25 | htmlConstants_1.ASTERISK))),
|
26 | ' ',
|
27 | React.isValidElement(labelIcon) && labelIcon));
|
28 | return (React.createElement("div", Object.assign({}, props, { className: react_styles_1.css(form_1.default.formGroup, className) }),
|
29 | label && (React.createElement("div", { className: react_styles_1.css(form_1.default.formGroupLabel, labelInfo && form_1.default.modifiers.info, hasNoPaddingTop && form_1.default.modifiers.noPaddingTop) },
|
30 | labelInfo && (React.createElement(React.Fragment, null,
|
31 | React.createElement("div", { className: react_styles_1.css(form_1.default.formGroupLabelMain) }, labelContent),
|
32 | React.createElement("div", { className: react_styles_1.css(form_1.default.formGroupLabelInfo) }, labelInfo))),
|
33 | !labelInfo && labelContent)),
|
34 | React.createElement("div", { className: react_styles_1.css(form_1.default.formGroupControl, isInline && form_1.default.modifiers.inline, isStack && form_1.default.modifiers.stack) },
|
35 | isHelperTextBeforeField && helperTextToDisplay,
|
36 | children,
|
37 | !isHelperTextBeforeField && helperTextToDisplay)));
|
38 | };
|
39 | exports.FormGroup = FormGroup;
|
40 | exports.FormGroup.displayName = 'FormGroup';
|
41 |
|
\ | No newline at end of file |