fix(ui): refactor percentage and suffix/prefix inputs to standard Input component with guaranteed padding isolation
This commit is contained in:
1 parent
c4e4a336d8
commit
a62bfb77b3
15 files changed
+11604
-11407
No files matched your search
@@ -4,31 +4,58 @@ export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement>
|
||||
error?: string;
|
||||
leftIcon?: React.ReactNode;
|
||||
rightIcon?: React.ReactNode;
|
||||
prefixElement?: React.ReactNode;
|
||||
suffixElement?: React.ReactNode;
|
||||
inputSize?: 'sm' | 'md' | 'lg';
|
||||
}
|
||||
|
||||
export const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
({ className = '', error, leftIcon, rightIcon, disabled, ...props }, ref) => {
|
||||
(
|
||||
{
|
||||
className = '',
|
||||
error,
|
||||
leftIcon,
|
||||
rightIcon,
|
||||
prefixElement,
|
||||
suffixElement,
|
||||
inputSize = 'md',
|
||||
disabled,
|
||||
dir,
|
||||
...props
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
const hasLeft = Boolean(leftIcon || prefixElement);
|
||||
const hasRight = Boolean(rightIcon || suffixElement);
|
||||
|
||||
const sizeClasses = {
|
||||
sm: 'py-1.5 text-xs rounded-lg',
|
||||
md: 'py-2.5 text-sm rounded-xl',
|
||||
lg: 'py-3 text-base rounded-2xl',
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full relative">
|
||||
{rightIcon && (
|
||||
<div className="absolute right-3.5 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none">
|
||||
{rightIcon}
|
||||
{hasRight && (
|
||||
<div className="absolute right-3.5 top-1/2 -translate-y-1/2 text-gray-400 font-bold text-xs pointer-events-none flex items-center justify-center select-none z-10">
|
||||
{rightIcon || suffixElement}
|
||||
</div>
|
||||
)}
|
||||
<input
|
||||
ref={ref}
|
||||
disabled={disabled}
|
||||
className={`w-full bg-white border font-vazir text-sm transition-all duration-200 outline-none
|
||||
dir={dir}
|
||||
className={`w-full bg-white border font-vazir transition-all duration-200 outline-none
|
||||
${error ? 'border-red-400 focus:border-red-500 focus:ring-2 focus:ring-red-500/20' : 'border-gray-200 focus:border-purple-500 focus:ring-2 focus:ring-purple-500/20'}
|
||||
${disabled ? 'bg-gray-50 text-gray-400 cursor-not-allowed border-gray-200' : 'text-gray-900 placeholder:text-gray-400 hover:border-gray-300'}
|
||||
${rightIcon ? 'pr-10' : 'pr-4'}
|
||||
${leftIcon ? 'pl-10' : 'pl-4'}
|
||||
py-2.5 rounded-xl shadow-xs ${className}`}
|
||||
${hasRight ? 'pr-10' : 'pr-4'}
|
||||
${hasLeft ? 'pl-10' : 'pl-4'}
|
||||
${sizeClasses[inputSize] || sizeClasses.md} shadow-xs ${className}`}
|
||||
{...props}
|
||||
/>
|
||||
{leftIcon && (
|
||||
<div className="absolute left-3.5 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none">
|
||||
{leftIcon}
|
||||
{hasLeft && (
|
||||
<div className="absolute left-3.5 top-1/2 -translate-y-1/2 text-gray-400 font-bold text-xs pointer-events-none flex items-center justify-center select-none z-10">
|
||||
{leftIcon || prefixElement}
|
||||
</div>
|
||||
)}
|
||||
{error && (
|
||||
|
||||
Reference in new issue
Block a user