@carbon/react
Version:
React components for the Carbon Design System
115 lines (111 loc) • 3.3 kB
JavaScript
/**
* 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.
*/
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import PropTypes from 'prop-types';
import React from 'react';
import cx from 'classnames';
import TextInput from '../TextInput/TextInput.js';
import '../TextInput/TextInput.Skeleton.js';
import '../TextInput/ControlledPasswordInput.js';
import PasswordInput from '../TextInput/PasswordInput.js';
import { usePrefix } from '../../internal/usePrefix.js';
import { FormContext } from '../FluidForm/FormContext.js';
const FluidTextInput = /*#__PURE__*/React.forwardRef(function FluidTextInput({
className,
isPassword,
...other
}, ref) {
const prefix = usePrefix();
const classNames = cx(className, {
[`${prefix}--text-input--fluid`]: !isPassword
});
return /*#__PURE__*/React.createElement(FormContext.Provider, {
value: {
isFluid: true
}
}, isPassword ? /*#__PURE__*/React.createElement(PasswordInput, _extends({
className: classNames,
ref: ref
}, other)) : /*#__PURE__*/React.createElement(TextInput, _extends({
className: classNames,
ref: ref
}, other)));
});
FluidTextInput.propTypes = {
/**
* Specify an optional className to be applied to the outer FluidForm wrapper
*/
className: PropTypes.string,
/**
* Optionally provide the default value of the `<input>`
*/
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Specify whether the `<input>` should be disabled
*/
disabled: PropTypes.bool,
/**
* Specify a custom `id` for the `<input>`
*/
id: PropTypes.string.isRequired,
/**
* Specify whether the control is currently invalid
*/
invalid: PropTypes.bool,
/**
* Provide the text that is displayed when the control is in an invalid state
*/
invalidText: PropTypes.node,
/**
* Specify whether the control is a password input
*/
isPassword: PropTypes.bool,
/**
* Max character count allowed for the textInput. This is needed in order for enableCounter to display
*/
maxCount: PropTypes.number,
/**
* Specify whether to display the character counter
*/
enableCounter: PropTypes.bool,
/**
* Provide the text that will be read by a screen reader when visiting this
* control
*/
labelText: PropTypes.node.isRequired,
/**
* Optionally provide an `onChange` handler that is called whenever `<input>`
* is updated
*/
onChange: PropTypes.func,
/**
* Optionally provide an `onClick` handler that is called whenever the
* `<input>` is clicked
*/
onClick: PropTypes.func,
/**
* Specify the placeholder attribute for the `<input>`
*/
placeholder: PropTypes.string,
/**
* Specify the value of the `<input>`
*/
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Specify whether the control is currently in warning state
*/
warn: PropTypes.bool,
/**
* Provide the text that is displayed when the control is in warning state
*/
warnText: PropTypes.node,
/**
* Whether or not the component is readonly
*/
readOnly: PropTypes.bool
};
export { FluidTextInput as default };