2026-02-10 11:16:39 +09:00
|
|
|
import type { FormEvent } from "react";
|
2026-02-12 14:20:07 +09:00
|
|
|
import { Search, X } from "lucide-react";
|
2026-02-11 14:06:06 +09:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
2026-02-10 11:16:39 +09:00
|
|
|
|
|
|
|
|
interface StockSearchFormProps {
|
|
|
|
|
keyword: string;
|
|
|
|
|
onKeywordChange: (value: string) => void;
|
2026-02-11 14:06:06 +09:00
|
|
|
onSubmit: (event: FormEvent) => void;
|
|
|
|
|
onInputFocus?: () => void;
|
2026-02-10 11:16:39 +09:00
|
|
|
disabled?: boolean;
|
|
|
|
|
isLoading?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-11 14:06:06 +09:00
|
|
|
/**
|
|
|
|
|
* @description 종목 검색 입력/제출 폼을 렌더링합니다.
|
2026-02-11 16:31:28 +09:00
|
|
|
* @see features/trade/components/TradeContainer.tsx 검색 패널에서 키워드 입력 이벤트를 전달합니다.
|
2026-02-11 14:06:06 +09:00
|
|
|
*/
|
2026-02-10 11:16:39 +09:00
|
|
|
export function StockSearchForm({
|
|
|
|
|
keyword,
|
|
|
|
|
onKeywordChange,
|
|
|
|
|
onSubmit,
|
2026-02-11 14:06:06 +09:00
|
|
|
onInputFocus,
|
2026-02-10 11:16:39 +09:00
|
|
|
disabled,
|
|
|
|
|
isLoading,
|
|
|
|
|
}: StockSearchFormProps) {
|
2026-02-12 14:20:07 +09:00
|
|
|
const handleClear = () => {
|
|
|
|
|
onKeywordChange("");
|
|
|
|
|
// 포커스 로직이 필요하다면 상위에서 ref를 전달받거나 여기서 ref를 사용해야 함.
|
|
|
|
|
// 현재는 단순 값 초기화만 수행.
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-10 11:16:39 +09:00
|
|
|
return (
|
|
|
|
|
<form onSubmit={onSubmit} className="flex gap-2">
|
2026-02-11 14:06:06 +09:00
|
|
|
{/* ========== SEARCH INPUT ========== */}
|
2026-02-10 11:16:39 +09:00
|
|
|
<div className="relative flex-1">
|
2026-02-11 14:06:06 +09:00
|
|
|
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground dark:text-brand-100/65" />
|
2026-02-10 11:16:39 +09:00
|
|
|
<Input
|
|
|
|
|
value={keyword}
|
|
|
|
|
onChange={(e) => onKeywordChange(e.target.value)}
|
2026-02-11 14:06:06 +09:00
|
|
|
onFocus={onInputFocus}
|
|
|
|
|
placeholder="종목명 또는 종목코드(6자리)를 입력하세요."
|
|
|
|
|
autoComplete="off"
|
2026-02-12 14:20:07 +09:00
|
|
|
className="pl-9 pr-9 dark:border-brand-700/55 dark:bg-brand-900/28 dark:text-brand-100 dark:placeholder:text-brand-100/55"
|
2026-02-10 11:16:39 +09:00
|
|
|
/>
|
2026-02-12 14:20:07 +09:00
|
|
|
{keyword && (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={handleClear}
|
|
|
|
|
className="absolute right-2.5 top-2.5 text-muted-foreground hover:text-foreground dark:text-brand-100/65 dark:hover:text-brand-100"
|
|
|
|
|
tabIndex={-1}
|
|
|
|
|
aria-label="검색어 지우기"
|
|
|
|
|
>
|
|
|
|
|
<X className="h-4 w-4" />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
2026-02-10 11:16:39 +09:00
|
|
|
</div>
|
2026-02-11 14:06:06 +09:00
|
|
|
|
|
|
|
|
{/* ========== SUBMIT BUTTON ========== */}
|
2026-02-10 11:16:39 +09:00
|
|
|
<Button type="submit" disabled={disabled || isLoading}>
|
|
|
|
|
{isLoading ? "검색 중..." : "검색"}
|
|
|
|
|
</Button>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
}
|