UNPKG

@elastic/eui

Version:

Elastic UI Component Library

81 lines (80 loc) 3.28 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.EuiFieldText = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _react = _interopRequireDefault(require("react")); var _classnames = _interopRequireDefault(require("classnames")); var _form_control_layout = require("../form_control_layout"); var _validatable_control = require("../validatable_control"); var _num_icons = require("../form_control_layout/_num_icons"); var _eui_form_context = require("../eui_form_context"); var _react2 = require("@emotion/react"); var _excluded = ["id", "name", "placeholder", "value", "className", "icon", "isInvalid", "inputRef", "fullWidth", "isLoading", "compressed", "prepend", "append", "readOnly", "controlOnly"]; /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ var EuiFieldText = function EuiFieldText(props) { var _useFormContext = (0, _eui_form_context.useFormContext)(), defaultFullWidth = _useFormContext.defaultFullWidth; var id = props.id, name = props.name, placeholder = props.placeholder, value = props.value, className = props.className, icon = props.icon, isInvalid = props.isInvalid, inputRef = props.inputRef, _props$fullWidth = props.fullWidth, fullWidth = _props$fullWidth === void 0 ? defaultFullWidth : _props$fullWidth, isLoading = props.isLoading, compressed = props.compressed, prepend = props.prepend, append = props.append, readOnly = props.readOnly, controlOnly = props.controlOnly, rest = (0, _objectWithoutProperties2.default)(props, _excluded); var numIconsClass = controlOnly ? false : (0, _num_icons.getFormControlClassNameForIconCount)({ isInvalid: isInvalid, isLoading: isLoading }); var classes = (0, _classnames.default)('euiFieldText', className, numIconsClass, { 'euiFieldText--withIcon': icon, 'euiFieldText--fullWidth': fullWidth, 'euiFieldText--compressed': compressed, 'euiFieldText--inGroup': prepend || append, 'euiFieldText-isLoading': isLoading }); var control = (0, _react2.jsx)(_validatable_control.EuiValidatableControl, { isInvalid: isInvalid }, (0, _react2.jsx)("input", (0, _extends2.default)({ type: "text", id: id, name: name, placeholder: placeholder, className: classes, value: value, ref: inputRef, readOnly: readOnly }, rest))); if (controlOnly) return control; return (0, _react2.jsx)(_form_control_layout.EuiFormControlLayout, { icon: icon, fullWidth: fullWidth, isLoading: isLoading, isInvalid: isInvalid, compressed: compressed, readOnly: readOnly, prepend: prepend, append: append, inputId: id }, control); }; exports.EuiFieldText = EuiFieldText;