- iOS Safari: ฟอร์ม ≥16px บนมือถือ (กัน auto-zoom โดยไม่ต้องล็อก user-scalable), input[type=search] appearance:none, tap-highlight transparent, text-size-adjust 100% - ย้ายบล็อก cross-engine เข้า @layer base — เดิม unlayered ทับ text-sm ทำให้ desktop เพี้ยนเป็น 16px - admin 3 จุด min-h-screen → min-h-dvh - DESIGN.md: ขยายหัวข้อเป็น Chromium/Firefox/Safari + กฎ @layer · sw VERSION v2.0.3
130 lines
5.1 KiB
TypeScript
130 lines
5.1 KiB
TypeScript
import { IconCircleCheck, IconMapPin, IconSearch } from "@tabler/icons-react";
|
|
import { useRef, type FormEvent } from "react";
|
|
|
|
import { Reveal } from "@/components/site/Reveal";
|
|
import type { NearMeStatus } from "@/hooks/use-near-me";
|
|
import { useI18n } from "@/lib/i18n";
|
|
|
|
type HeroSectionProps = {
|
|
query: string;
|
|
onQueryChange: (query: string) => void;
|
|
nearMeStatus: NearMeStatus;
|
|
onRequestLocation: () => void;
|
|
/** เรียกเมื่อผู้ใช้กดปุ่ม "ค้นหา" หรือกด Enter — ใช้เลื่อนไปที่ผลลัพธ์ (การกรองยังทำงานสดขณะพิมพ์) */
|
|
onSubmitSearch: () => void;
|
|
};
|
|
|
|
/** ข้อความสถานะของปุ่ม "ใกล้ฉัน" — แสดงเฉพาะตอนกำลังหา/ผิดพลาด/พร้อมใช้ */
|
|
function statusMessage(
|
|
status: NearMeStatus,
|
|
messages: ReturnType<typeof useI18n>["messages"],
|
|
) {
|
|
switch (status) {
|
|
case "locating":
|
|
return messages.search.locating;
|
|
case "denied":
|
|
return messages.search.denied;
|
|
case "unsupported":
|
|
return messages.search.unsupported;
|
|
case "error":
|
|
return messages.search.error;
|
|
case "ready":
|
|
return messages.search.sortedByDistance;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/** ฮีโร่หน้าแรก: หัวข้อ + ช่องค้นหา (ค้นทันทีขณะพิมพ์) + ปุ่มหาตำแหน่ง */
|
|
export function HeroSection({
|
|
query,
|
|
onQueryChange,
|
|
nearMeStatus,
|
|
onRequestLocation,
|
|
onSubmitSearch,
|
|
}: HeroSectionProps) {
|
|
const { messages } = useI18n();
|
|
const status = statusMessage(nearMeStatus, messages);
|
|
const isReady = nearMeStatus === "ready";
|
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
|
|
/**
|
|
* ปุ่ม "ค้นหา" / Enter — ไม่ได้ทำหน้าที่กรอง (กรองสดอยู่แล้วใน onChange)
|
|
* หน้าที่คือ: กันหน้าโหลดใหม่, ปิดคีย์บอร์ดมือถือ, แล้วเลื่อนไปที่ผลลัพธ์
|
|
*/
|
|
function handleSubmit(event: FormEvent<HTMLFormElement>) {
|
|
event.preventDefault();
|
|
inputRef.current?.blur();
|
|
onSubmitSearch();
|
|
}
|
|
|
|
return (
|
|
<section className="mx-auto flex max-w-[1016px] flex-col items-center gap-10 pt-24 md:pt-[167px]">
|
|
<Reveal
|
|
delay={60}
|
|
className="flex max-w-[745px] flex-col items-center gap-4 text-center"
|
|
>
|
|
<h1 className="text-4xl font-bold leading-[1.3] md:text-[56px]">
|
|
{messages.hero.titlePrefix}
|
|
<span className="text-[#D47272]">{messages.hero.titleHighlight}</span>
|
|
{messages.hero.titleSuffix}
|
|
</h1>
|
|
<p className="text-base md:text-xl">{messages.hero.subtitle}</p>
|
|
</Reveal>
|
|
|
|
<Reveal
|
|
delay={200}
|
|
className="w-full rounded-2xl border border-[#303030] bg-[#1B1B1B]/80 px-4 py-6 backdrop-blur-[24px] md:px-10"
|
|
>
|
|
<form
|
|
role="search"
|
|
onSubmit={handleSubmit}
|
|
className="flex h-14 items-center gap-3 rounded-lg border border-[#1B1B1B] bg-[#1F1F1F] px-5 transition-colors duration-300 focus-within:border-[#A92626]/70"
|
|
>
|
|
<IconSearch size={16} className="shrink-0 text-[#999]" />
|
|
<input
|
|
ref={inputRef}
|
|
value={query}
|
|
onChange={(event) => onQueryChange(event.target.value)}
|
|
placeholder={messages.search.placeholder}
|
|
aria-label={messages.search.placeholder}
|
|
type="search"
|
|
enterKeyHint="search"
|
|
className="min-w-0 flex-1 bg-transparent text-base text-white outline-none placeholder:text-[#8A8A8A] md:text-sm [&::-webkit-search-cancel-button]:hidden"
|
|
/>
|
|
<button
|
|
type="button"
|
|
onClick={onRequestLocation}
|
|
disabled={nearMeStatus === "locating"}
|
|
aria-label={messages.search.nearMe}
|
|
className={`relative hidden items-center gap-2 border-l border-[#999] px-4 text-sm transition after:absolute after:-inset-y-3 after:inset-x-0 after:content-[''] disabled:opacity-60 sm:flex ${
|
|
isReady ? "text-[#D47272]" : "text-[#999] hover:text-white"
|
|
}`}
|
|
>
|
|
{isReady ? <IconCircleCheck size={16} /> : <IconMapPin size={16} />}
|
|
{messages.search.nearMe}
|
|
</button>
|
|
<button
|
|
type="submit"
|
|
className="relative h-8 rounded-lg border border-[#8F0808] bg-[#8F0808] px-6 text-sm font-medium transition after:absolute after:-inset-y-1.5 after:-inset-x-1 after:content-[''] hover:bg-[#a30a0a]"
|
|
>
|
|
{messages.search.submit}
|
|
</button>
|
|
</form>
|
|
|
|
{status ? (
|
|
<p
|
|
role="status"
|
|
aria-live="polite"
|
|
className={`px-1 pt-3 text-xs ${
|
|
nearMeStatus === "ready" ? "text-[#B3B3B3]" : "text-[#D47272]"
|
|
}`}
|
|
>
|
|
{status}
|
|
</p>
|
|
) : null}
|
|
</Reveal>
|
|
</section>
|
|
);
|
|
}
|