import React, { useEffect, useImperativeHandle } from 'react'; import Icon, { IconProps, IconTagType } from '@uiw/react-icon'; import { IProps, HTMLInputProps } from '@uiw/utils'; import './style/input.less'; export * from './InputNumber'; export { default as InputNumber } from './InputNumber'; export interface InputProps extends IProps, Omit { preIcon?: IconProps['type']; addonAfter?: React.ReactNode; size?: 'large' | 'default' | 'small'; inputStyle?: React.CSSProperties; } export default React.forwardRef((props, ref) => { const { prefixCls = 'w-input', className, style, size = 'default', type = 'text', preIcon = null, addonAfter, inputStyle, ...otherProps } = props; const inputRef = React.useRef(null); const addonRef = React.useRef(null); useImperativeHandle(ref, () => inputRef.current); const cls = [ prefixCls, className, size ? `${prefixCls}-${size}` : null, addonAfter ? `${prefixCls}-addon` : null, props.disabled ? 'disabled' : null, ] .filter(Boolean) .join(' ') .trim(); useEffect(() => { computedInputPadding(); }); function computedInputPadding() { if (addonRef.current && inputRef.current) { const input = window && window.getComputedStyle(addonRef.current, null); inputRef.current.style.paddingRight = `${ addonRef.current.clientWidth + parseInt(input.right as string, 10) * 2 }px`; } } return (
{addonAfter && ( {addonAfter} )}
); });