Debian Codegraph @

node/@patternfly/react-core/dist/esm/components/TextInputGroup/TextInputGroupMain.js

raw
1 import { __rest } from "tslib";
2 import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3 import { forwardRef, useContext, useRef } from 'react';
4 import styles from '@patternfly/react-styles/css/components/TextInputGroup/text-input-group.mjs';
5 import { css } from '@patternfly/react-styles';
6 import { TextInputGroupContext } from './TextInputGroup';
7 import { TextInputGroupIcon } from './TextInputGroupIcon';
8 import { statusIcons } from '../../helpers';
9 const TextInputGroupMainBase = (_a) => {
10 var { children, className, icon, type = 'text', hint, onChange = () => undefined, onFocus, onBlur, 'aria-label': ariaLabel = 'Type to filter', value: inputValue, placeholder: inputPlaceHolder, innerRef, name, 'aria-activedescendant': ariaActivedescendant, role, isExpanded, 'aria-controls': ariaControls, inputId, inputProps } = _a, props = __rest(_a, ["children", "className", "icon", "type", "hint", "onChange", "onFocus", "onBlur", 'aria-label', "value", "placeholder", "innerRef", "name", 'aria-activedescendant', "role", "isExpanded", 'aria-controls', "inputId", "inputProps"]);
11 const { isDisabled, validated } = useContext(TextInputGroupContext);
12 const ref = useRef(null);
13 const textInputGroupInputInputRef = innerRef || ref;
14 const hasStatusIcon = ['success', 'error', 'warning'].includes(validated);
15 const StatusIcon = (() => {
16 if (!hasStatusIcon) {
17 return undefined;
18 }
19 if (validated === 'error') {
20 return statusIcons.danger;
21 }
22 if (validated === 'success') {
23 return statusIcons.success;
24 }
25 return statusIcons.warning;
26 })();
27 const handleChange = (event) => {
28 onChange(event, event.currentTarget.value);
29 };
30 return (_jsxs("div", Object.assign({ className: css(styles.textInputGroupMain, icon && styles.modifiers.icon, className) }, props, { children: [children, _jsxs("span", { className: css(styles.textInputGroupText), children: [hint && (_jsx("input", { className: css(styles.textInputGroupTextInput, styles.modifiers.hint), type: "text", disabled: true, "aria-hidden": "true", value: hint, id: inputId })), icon && _jsx(TextInputGroupIcon, { children: icon }), _jsx("input", Object.assign({ ref: textInputGroupInputInputRef, type: type, className: css(styles.textInputGroupTextInput), "aria-label": ariaLabel, disabled: isDisabled, onChange: handleChange, onFocus: onFocus, onBlur: onBlur, value: inputValue || '', placeholder: inputPlaceHolder, name: name, "aria-activedescendant": ariaActivedescendant, id: inputId }, (role && { role }), (isExpanded !== undefined && { 'aria-expanded': isExpanded }), (ariaControls && { 'aria-controls': ariaControls }), inputProps)), hasStatusIcon && _jsx(TextInputGroupIcon, { isStatus: true, children: _jsx(StatusIcon, {}) })] })] })));
31 };
32 export const TextInputGroupMain = forwardRef((props, ref) => (_jsx(TextInputGroupMainBase, Object.assign({ innerRef: ref }, props))));
33 TextInputGroupMain.displayName = 'TextInputGroupMain';
34 //# sourceMappingURL=TextInputGroupMain.js.map