Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/components/ui/input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,40 @@ import { forwardRef, type ReactNode } from 'react';

import { cn } from '@/lib/utils';

interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
iconButton?: ReactNode;
// 둘 다 없음
interface NoneIcons {
frontIcon?: undefined;
iconButton?: undefined;
}

// frontIcon만
interface OnlyFront {
frontIcon: ReactNode;
iconButton?: undefined;
}

// backIcon만
interface OnlyBack {
frontIcon?: undefined;
iconButton: ReactNode;
}

type InputProps = (NoneIcons | OnlyFront | OnlyBack) & React.InputHTMLAttributes<HTMLInputElement>;

export const Input = forwardRef<HTMLInputElement, InputProps>(
({ className, type, iconButton, ...props }, ref) => {
({ className, type, iconButton, frontIcon, ...props }, ref) => {
const hasIcon = !!iconButton;
const hasFrontIcon = !!frontIcon;

return (
<div className='relative w-full'>
{frontIcon}
<input
ref={ref}
className={cn(
'text-text-md-medium w-full px-4 py-4 text-gray-800 focus:outline-none',
hasIcon && 'pr-12 pl-5',
hasIcon && 'pr-11',
hasFrontIcon && 'pl-11',
className,
)}
type={type}
Expand Down