UNPKG

@carbon/react

Version:

React components for the Carbon Design System

125 lines (117 loc) 4.33 kB
/** * Copyright IBM Corp. 2016, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js'); var PropTypes = require('prop-types'); var React = require('react'); var cx = require('classnames'); var TextInput = require('../TextInput/TextInput.js'); require('../TextInput/TextInput.Skeleton.js'); require('../TextInput/ControlledPasswordInput.js'); var PasswordInput = require('../TextInput/PasswordInput.js'); var usePrefix = require('../../internal/usePrefix.js'); var FormContext = require('../FluidForm/FormContext.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); var React__default = /*#__PURE__*/_interopDefaultLegacy(React); var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx); const FluidTextInput = /*#__PURE__*/React__default["default"].forwardRef(function FluidTextInput({ className, isPassword, ...other }, ref) { const prefix = usePrefix.usePrefix(); const classNames = cx__default["default"](className, { [`${prefix}--text-input--fluid`]: !isPassword }); return /*#__PURE__*/React__default["default"].createElement(FormContext.FormContext.Provider, { value: { isFluid: true } }, isPassword ? /*#__PURE__*/React__default["default"].createElement(PasswordInput["default"], _rollupPluginBabelHelpers["extends"]({ className: classNames, ref: ref }, other)) : /*#__PURE__*/React__default["default"].createElement(TextInput["default"], _rollupPluginBabelHelpers["extends"]({ className: classNames, ref: ref }, other))); }); FluidTextInput.propTypes = { /** * Specify an optional className to be applied to the outer FluidForm wrapper */ className: PropTypes__default["default"].string, /** * Optionally provide the default value of the `<input>` */ defaultValue: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].number]), /** * Specify whether the `<input>` should be disabled */ disabled: PropTypes__default["default"].bool, /** * Specify a custom `id` for the `<input>` */ id: PropTypes__default["default"].string.isRequired, /** * Specify whether the control is currently invalid */ invalid: PropTypes__default["default"].bool, /** * Provide the text that is displayed when the control is in an invalid state */ invalidText: PropTypes__default["default"].node, /** * Specify whether the control is a password input */ isPassword: PropTypes__default["default"].bool, /** * Max character count allowed for the textInput. This is needed in order for enableCounter to display */ maxCount: PropTypes__default["default"].number, /** * Specify whether to display the character counter */ enableCounter: PropTypes__default["default"].bool, /** * Provide the text that will be read by a screen reader when visiting this * control */ labelText: PropTypes__default["default"].node.isRequired, /** * Optionally provide an `onChange` handler that is called whenever `<input>` * is updated */ onChange: PropTypes__default["default"].func, /** * Optionally provide an `onClick` handler that is called whenever the * `<input>` is clicked */ onClick: PropTypes__default["default"].func, /** * Specify the placeholder attribute for the `<input>` */ placeholder: PropTypes__default["default"].string, /** * Specify the value of the `<input>` */ value: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].number]), /** * Specify whether the control is currently in warning state */ warn: PropTypes__default["default"].bool, /** * Provide the text that is displayed when the control is in warning state */ warnText: PropTypes__default["default"].node, /** * Whether or not the component is readonly */ readOnly: PropTypes__default["default"].bool }; exports["default"] = FluidTextInput;