import clsx from 'clsx'; import React from 'react'; import { defineMessages, useIntl } from 'react-intl'; import Icon from '../icon/icon'; import SvgIcon from '../icon/svg-icon'; import Tooltip from '../tooltip/tooltip'; const messages = defineMessages({ showPassword: { id: 'input.password.show_password', defaultMessage: 'Show password' }, hidePassword: { id: 'input.password.hide_password', defaultMessage: 'Hide password' }, }); /** Possible theme names for an Input. */ type InputThemes = 'normal' | 'search' interface IInput extends Pick, 'maxLength' | 'onChange' | 'onBlur' | 'type' | 'autoComplete' | 'autoCorrect' | 'autoCapitalize' | 'required' | 'disabled' | 'onClick' | 'readOnly' | 'min' | 'pattern' | 'onKeyDown' | 'onKeyUp' | 'onFocus' | 'style' | 'id'> { /** Put the cursor into the input on mount. */ autoFocus?: boolean /** The initial text in the input. */ defaultValue?: string /** Extra class names for the element. */ className?: string /** Extra class names for the outer
element. */ outerClassName?: string /** URL to the svg icon. Cannot be used with prepend. */ icon?: string /** Internal input name. */ name?: string /** Text to display before a value is entered. */ placeholder?: string /** Text in the input. */ value?: string | number /** Change event handler for the input. */ onChange?: (event: React.ChangeEvent) => void /** An element to display as prefix to input. Cannot be used with icon. */ prepend?: React.ReactElement /** An element to display as suffix to input. Cannot be used with password type. */ append?: React.ReactElement /** Theme to style the input with. */ theme?: InputThemes } /** Form input element. */ const Input = React.forwardRef( (props, ref) => { const intl = useIntl(); const { type = 'text', icon, className, outerClassName, append, prepend, theme = 'normal', ...filteredProps } = props; const [revealed, setRevealed] = React.useState(false); const isPassword = type === 'password'; const togglePassword = React.useCallback(() => { setRevealed((prev) => !prev); }, []); return (
{icon ? (
) : null} {prepend ? (
{prepend}
) : null} {append ? (
{append}
) : null} {isPassword ? (
) : null}
); }, ); export { Input as default, InputThemes, };