| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.TextInputGroupMain = 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 text_input_group_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/TextInputGroup/text-input-group")); |
| 8 |
const react_styles_1 = require("@patternfly/react-styles"); |
| 9 |
const TextInputGroup_1 = require("./TextInputGroup"); |
| 10 |
const TextInputGroupIcon_1 = require("./TextInputGroupIcon"); |
| 11 |
const helpers_1 = require("../../helpers"); |
| 12 |
const TextInputGroupMainBase = (_a) => { |
| 13 |
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 = tslib_1.__rest(_a, ["children", "className", "icon", "type", "hint", "onChange", "onFocus", "onBlur", 'aria-label', "value", "placeholder", "innerRef", "name", 'aria-activedescendant', "role", "isExpanded", 'aria-controls', "inputId", "inputProps"]); |
| 14 |
const { isDisabled, validated } = (0, react_1.useContext)(TextInputGroup_1.TextInputGroupContext); |
| 15 |
const ref = (0, react_1.useRef)(null); |
| 16 |
const textInputGroupInputInputRef = innerRef || ref; |
| 17 |
const hasStatusIcon = ['success', 'error', 'warning'].includes(validated); |
| 18 |
const StatusIcon = (() => { |
| 19 |
if (!hasStatusIcon) { |
| 20 |
return undefined; |
| 21 |
} |
| 22 |
if (validated === 'error') { |
| 23 |
return helpers_1.statusIcons.danger; |
| 24 |
} |
| 25 |
if (validated === 'success') { |
| 26 |
return helpers_1.statusIcons.success; |
| 27 |
} |
| 28 |
return helpers_1.statusIcons.warning; |
| 29 |
})(); |
| 30 |
const handleChange = (event) => { |
| 31 |
onChange(event, event.currentTarget.value); |
| 32 |
}; |
| 33 |
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, react_styles_1.css)(text_input_group_1.default.textInputGroupMain, icon && text_input_group_1.default.modifiers.icon, className) }, props, { children: [children, (0, jsx_runtime_1.jsxs)("span", { className: (0, react_styles_1.css)(text_input_group_1.default.textInputGroupText), children: [hint && ((0, jsx_runtime_1.jsx)("input", { className: (0, react_styles_1.css)(text_input_group_1.default.textInputGroupTextInput, text_input_group_1.default.modifiers.hint), type: "text", disabled: true, "aria-hidden": "true", value: hint, id: inputId })), icon && (0, jsx_runtime_1.jsx)(TextInputGroupIcon_1.TextInputGroupIcon, { children: icon }), (0, jsx_runtime_1.jsx)("input", Object.assign({ ref: textInputGroupInputInputRef, type: type, className: (0, react_styles_1.css)(text_input_group_1.default.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 && (0, jsx_runtime_1.jsx)(TextInputGroupIcon_1.TextInputGroupIcon, { isStatus: true, children: (0, jsx_runtime_1.jsx)(StatusIcon, {}) })] })] }))); |
| 34 |
}; |
| 35 |
exports.TextInputGroupMain = (0, react_1.forwardRef)((props, ref) => ((0, jsx_runtime_1.jsx)(TextInputGroupMainBase, Object.assign({ innerRef: ref }, props)))); |
| 36 |
exports.TextInputGroupMain.displayName = 'TextInputGroupMain'; |
| 37 |
//# sourceMappingURL=TextInputGroupMain.js.map |