| | |
| | | import { RiCloseCircleFill, RiErrorWarningLine, RiSearchLine } from '@remixicon/react' |
| | | import { type VariantProps, cva } from 'class-variance-authority' |
| | | import cn from '@/utils/classnames' |
| | | import { noop } from 'lodash-es' |
| | | |
| | | export const inputVariants = cva( |
| | | '', |
| | |
| | | wrapperClassName?: string |
| | | styleCss?: CSSProperties |
| | | unit?: string |
| | | } & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'> & VariantProps<typeof inputVariants> |
| | | } & React.InputHTMLAttributes<HTMLInputElement> & VariantProps<typeof inputVariants> |
| | | |
| | | const Input = ({ |
| | | size, |
| | |
| | | styleCss, |
| | | value, |
| | | placeholder, |
| | | onChange = noop, |
| | | onChange, |
| | | unit, |
| | | ...props |
| | | }: InputProps) => { |
| | | const { t } = useTranslation() |
| | | return ( |
| | | <div className={cn('relative w-full', wrapperClassName)}> |
| | | {showLeftIcon && <RiSearchLine className={cn('absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-components-input-text-placeholder')} />} |
| | | {showLeftIcon && <RiSearchLine className={cn('absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-components-input-text-placeholder')} />} |
| | | <input |
| | | style={styleCss} |
| | | className={cn( |
| | | 'w-full appearance-none border border-transparent bg-components-input-bg-normal py-[7px] text-components-input-text-filled caret-primary-600 outline-none placeholder:text-components-input-text-placeholder hover:border-components-input-border-hover hover:bg-components-input-bg-hover focus:border-components-input-border-active focus:bg-components-input-bg-active focus:shadow-xs', |
| | | 'w-full py-[7px] bg-components-input-bg-normal border border-transparent text-components-input-text-filled hover:bg-components-input-bg-hover hover:border-components-input-border-hover focus:bg-components-input-bg-active focus:border-components-input-border-active focus:shadow-xs placeholder:text-components-input-text-placeholder appearance-none outline-none caret-primary-600', |
| | | inputVariants({ size }), |
| | | showLeftIcon && 'pl-[26px]', |
| | | showLeftIcon && size === 'large' && 'pl-7', |
| | |
| | | showClearIcon && value && size === 'large' && 'pr-7', |
| | | destructive && 'pr-[26px]', |
| | | destructive && size === 'large' && 'pr-7', |
| | | disabled && 'cursor-not-allowed border-transparent bg-components-input-bg-disabled text-components-input-text-filled-disabled hover:border-transparent hover:bg-components-input-bg-disabled', |
| | | destructive && 'border-components-input-border-destructive bg-components-input-bg-destructive text-components-input-text-filled hover:border-components-input-border-destructive hover:bg-components-input-bg-destructive focus:border-components-input-border-destructive focus:bg-components-input-bg-destructive', |
| | | disabled && 'bg-components-input-bg-disabled border-transparent text-components-input-text-filled-disabled cursor-not-allowed hover:bg-components-input-bg-disabled hover:border-transparent', |
| | | destructive && 'bg-components-input-bg-destructive border-components-input-border-destructive text-components-input-text-filled hover:bg-components-input-bg-destructive hover:border-components-input-border-destructive focus:bg-components-input-bg-destructive focus:border-components-input-border-destructive', |
| | | className, |
| | | )} |
| | | placeholder={placeholder ?? (showLeftIcon |
| | |
| | | {...props} |
| | | /> |
| | | {showClearIcon && value && !disabled && !destructive && ( |
| | | <div className={cn('group absolute right-2 top-1/2 -translate-y-1/2 cursor-pointer p-[1px]')} onClick={onClear}> |
| | | <RiCloseCircleFill className='h-3.5 w-3.5 cursor-pointer text-text-quaternary group-hover:text-text-tertiary' /> |
| | | <div className={cn('absolute right-2 top-1/2 -translate-y-1/2 group p-[1px] cursor-pointer')} onClick={onClear}> |
| | | <RiCloseCircleFill className='w-3.5 h-3.5 text-text-quaternary cursor-pointer group-hover:text-text-tertiary' /> |
| | | </div> |
| | | )} |
| | | {destructive && ( |
| | | <RiErrorWarningLine className='absolute right-2 top-1/2 h-4 w-4 -translate-y-1/2 text-text-destructive-secondary' /> |
| | | <RiErrorWarningLine className='absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-text-destructive-secondary' /> |
| | | )} |
| | | { |
| | | unit && ( |
| | | <div className='system-sm-regular absolute right-2 top-1/2 -translate-y-1/2 text-text-tertiary'> |
| | | <div className='absolute right-2 top-1/2 -translate-y-1/2 system-sm-regular text-text-tertiary'> |
| | | {unit} |
| | | </div> |
| | | ) |