UNPKG

@talend/react-components

Version:
98 lines 2.8 kB
import PropTypes from 'prop-types'; import classNames from 'classnames'; import Action from '../../Actions/Action'; import theme from './Header.module.scss'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; function headerClasses(headerError) { return classNames(theme['tc-enumeration-header'], 'tc-enumeration-header', { 'has-error': !!headerError }); } function headerErrorClasses() { return classNames(theme['tc-enumeration-header-error'], 'tc-enumeration-header-error'); } function getAction(action, index, getInternalInputRef) { function onClick(event) { const internalInputRef = getInternalInputRef(); if (action.onClick) { action.onClick(event, { value: internalInputRef.value }); } } return /*#__PURE__*/_jsx(Action, { label: action.label, icon: action.icon, onClick: onClick, disabled: action.disabled, tooltipPlacement: "bottom", inProgress: action.inProgress, hideLabel: true, link: true }, `${index}-enum-header-action`); } function HeaderInput({ headerInput, headerError, onInputChange, id, inputLabel, inputPlaceholder, onAddKeyDown, value, inputRef }) { let internalInputRef = null; function onInputChangeHandler(event) { onInputChange(event, { value: event.target.value }); } function onAddKeyDownHandler(event) { onAddKeyDown(event, { value: event.target.value }); } function getInternalInputRef() { return internalInputRef; } const errorId = `${id}_error`; return /*#__PURE__*/_jsxs("header", { className: headerClasses(headerError), children: [/*#__PURE__*/_jsx("input", { type: "text", "aria-label": inputLabel, "aria-describedby": errorId, id: id, placeholder: inputPlaceholder, ref: input => { internalInputRef = input; if (inputRef) { inputRef(input); } }, onChange: onInputChangeHandler, onKeyDown: onAddKeyDownHandler, value: value, autoFocus: true }), headerError && /*#__PURE__*/_jsx("div", { id: errorId, className: headerErrorClasses(), "aria-live": "assertive", children: headerError }), headerInput.filter(action => !action.disabled).map((action, index) => getAction(action, index, getInternalInputRef.bind(this)))] }); } HeaderInput.propTypes = { id: PropTypes.string.isRequired, headerInput: PropTypes.arrayOf(PropTypes.shape(Action.propTypes)).isRequired, headerError: PropTypes.string, onInputChange: PropTypes.func, inputLabel: PropTypes.string, inputPlaceholder: PropTypes.string, inputRef: PropTypes.func, onAddKeyDown: PropTypes.func, value: PropTypes.string }; export default HeaderInput; //# sourceMappingURL=HeaderInput.component.js.map