UNPKG

4.12 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.FormGroup = void 0;
4const tslib_1 = require("tslib");
5const React = tslib_1.__importStar(require("react"));
6const form_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Form/form"));
7const htmlConstants_1 = require("../../helpers/htmlConstants");
8const react_styles_1 = require("@patternfly/react-styles");
9const constants_1 = require("../../helpers/constants");
10const 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};
39exports.FormGroup = FormGroup;
40exports.FormGroup.displayName = 'FormGroup';
41//# sourceMappingURL=FormGroup.js.map
\No newline at end of file