UNPKG

3.51 kBJavaScriptView Raw
1import { __rest } from "tslib";
2import * as React from 'react';
3import styles from '@patternfly/react-styles/css/components/Form/form';
4import { ASTERISK } from '../../helpers/htmlConstants';
5import { css } from '@patternfly/react-styles';
6import { ValidatedOptions } from '../../helpers/constants';
7export const FormGroup = (_a) => {
8 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 = __rest(_a, ["children", "className", "label", "labelInfo", "labelIcon", "isRequired", "validated", "isInline", "hasNoPaddingTop", "isStack", "helperText", "isHelperTextBeforeField", "helperTextInvalid", "helperTextIcon", "helperTextInvalidIcon", "fieldId"]);
9 const validHelperText = typeof helperText !== 'string' ? (helperText) : (React.createElement("div", { className: css(styles.formHelperText, validated === ValidatedOptions.success && styles.modifiers.success, validated === ValidatedOptions.warning && styles.modifiers.warning), id: `${fieldId}-helper`, "aria-live": "polite" },
10 helperTextIcon && React.createElement("span", { className: css(styles.formHelperTextIcon) }, helperTextIcon),
11 helperText));
12 const inValidHelperText = typeof helperTextInvalid !== 'string' ? (helperTextInvalid) : (React.createElement("div", { className: css(styles.formHelperText, styles.modifiers.error), id: `${fieldId}-helper`, "aria-live": "polite" },
13 helperTextInvalidIcon && React.createElement("span", { className: css(styles.formHelperTextIcon) }, helperTextInvalidIcon),
14 helperTextInvalid));
15 const showValidHelperTxt = (validationType) => validationType !== ValidatedOptions.error && helperText ? validHelperText : '';
16 const helperTextToDisplay = validated === ValidatedOptions.error && helperTextInvalid ? inValidHelperText : showValidHelperTxt(validated);
17 const labelContent = (React.createElement(React.Fragment, null,
18 React.createElement("label", { className: css(styles.formLabel), htmlFor: fieldId },
19 React.createElement("span", { className: css(styles.formLabelText) }, label),
20 isRequired && (React.createElement("span", { className: css(styles.formLabelRequired), "aria-hidden": "true" },
21 ' ',
22 ASTERISK))),
23 ' ',
24 React.isValidElement(labelIcon) && labelIcon));
25 return (React.createElement("div", Object.assign({}, props, { className: css(styles.formGroup, className) }),
26 label && (React.createElement("div", { className: css(styles.formGroupLabel, labelInfo && styles.modifiers.info, hasNoPaddingTop && styles.modifiers.noPaddingTop) },
27 labelInfo && (React.createElement(React.Fragment, null,
28 React.createElement("div", { className: css(styles.formGroupLabelMain) }, labelContent),
29 React.createElement("div", { className: css(styles.formGroupLabelInfo) }, labelInfo))),
30 !labelInfo && labelContent)),
31 React.createElement("div", { className: css(styles.formGroupControl, isInline && styles.modifiers.inline, isStack && styles.modifiers.stack) },
32 isHelperTextBeforeField && helperTextToDisplay,
33 children,
34 !isHelperTextBeforeField && helperTextToDisplay)));
35};
36FormGroup.displayName = 'FormGroup';
37//# sourceMappingURL=FormGroup.js.map
\No newline at end of file