From 361e439947d0a1f27d780acf666a6b69481383ab Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 13 Sep 2023 17:23:19 +0300 Subject: [PATCH] add HeroSearchFormSmall component to allow users to search for stays, experiences, cars, or flights add safety guidelines to commit message --- .../HeroSearchFormSmall.tsx | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/app/(client-components)/(HeroSearchFormSmall)/HeroSearchFormSmall.tsx diff --git a/src/app/(client-components)/(HeroSearchFormSmall)/HeroSearchFormSmall.tsx b/src/app/(client-components)/(HeroSearchFormSmall)/HeroSearchFormSmall.tsx new file mode 100644 index 0000000..168389e --- /dev/null +++ b/src/app/(client-components)/(HeroSearchFormSmall)/HeroSearchFormSmall.tsx @@ -0,0 +1,90 @@ +"use client"; + +import React, { FC, useEffect, useState } from "react"; +import { StaySearchFormFields } from "../type"; +import StaySearchForm from "./(stay-search-form)/StaySearchForm"; +import ExperiencesSearchForm from "./(experiences-search-form)/ExperiencesSearchForm"; +import RentalCarSearchForm from "./(car-search-form)/RentalCarSearchForm"; +import FlightSearchForm from "./(flight-search-form)/FlightSearchForm"; + +export type SearchTab = "Stays" | "Experiences" | "Cars" | "Flights"; + +export interface HeroSearchFormSmallProps { + className?: string; + defaultTab?: SearchTab; + onTabChange?: (tab: SearchTab) => void; + defaultFieldFocus?: StaySearchFormFields; +} +const TABS: SearchTab[] = ["Stays", "Experiences", "Cars", "Flights"]; + +const HeroSearchFormSmall: FC = ({ + className = "", + defaultTab = "Stays", + onTabChange, + defaultFieldFocus, +}) => { + const [tabActive, setTabActive] = useState(defaultTab); + + useEffect(() => { + setTabActive(defaultTab); + }, [defaultTab]); + + const renderTab = () => { + return ( +
    + {TABS.map((tab) => { + const active = tab === tabActive; + return ( +
  • { + setTabActive(tab); + onTabChange && onTabChange(tab); + }} + className={`relative flex-shrink-0 flex items-center cursor-pointer text-base ${ + active + ? "text-neutral-900 dark:text-neutral-200 font-medium" + : "text-neutral-500 dark:text-neutral-300 " + } `} + key={tab} + > +
    + {tab} + {active && ( + + )} +
    +
  • + ); + })} +
+ ); + }; + + const renderForm = () => { + switch (tabActive) { + case "Stays": + return ; + case "Experiences": + return ; + case "Cars": + return ; + case "Flights": + return ; + + default: + return null; + } + }; + + return ( +
+ {renderTab()} +
{renderForm()}
+
+ ); +}; + +export default HeroSearchFormSmall;