/** * @license * Copyright 2025 Qwen Team * SPDX-License-Identifier: Apache-2.0 */ import type React from 'react'; import { forwardRef } from 'react'; /** * Input size types */ export type InputSize = 'sm' | 'md' | 'lg'; /** * Input component props interface */ export interface InputProps extends Omit, 'size'> { /** Input size */ size?: InputSize; /** Error state */ error?: boolean; /** Error message to display */ errorMessage?: string; /** Label for the input */ label?: string; /** Helper text below input */ helperText?: string; /** Left icon/element */ leftElement?: React.ReactNode; /** Right icon/element */ rightElement?: React.ReactNode; /** Full width input */ fullWidth?: boolean; } /** * Input component with multiple sizes and states * * @example * ```tsx * * ``` */ const Input = forwardRef( ( { size = 'md', error = false, errorMessage, label, helperText, leftElement, rightElement, fullWidth = false, className = '', id, disabled, ...props }, ref, ) => { const inputId = id || `input-${Math.random().toString(36).substr(2, 9)}`; const baseClasses = 'border rounded transition-colors focus:outline-none focus:ring-2'; const sizeClasses: Record = { sm: 'px-2 py-1 text-sm', md: 'px-3 py-2', lg: 'px-4 py-3 text-lg', }; const stateClasses = error ? 'border-red-500 focus:ring-red-500 focus:border-red-500' : 'border-gray-300 focus:ring-blue-500 focus:border-blue-500'; const disabledClasses = disabled ? 'bg-gray-100 cursor-not-allowed opacity-60' : 'bg-white'; const widthClass = fullWidth ? 'w-full' : ''; const paddingClasses = [ leftElement ? 'pl-10' : '', rightElement ? 'pr-10' : '', ].join(' '); return (
{label && ( )}
{leftElement && (
{leftElement}
)} {rightElement && (
{rightElement}
)}
{errorMessage && error && (

{errorMessage}

)} {helperText && !error && (

{helperText}

)}
); }, ); Input.displayName = 'Input'; export default Input;