Merged in fix/SW-2451-destinations-mobile-search (pull request #1995)
fix: SW-2451 Fix Search field hidden behind list * fix: SW-2451 Fix Search field hidden behind list (cherry picked from commit 4e8f02ffd7dc94ec0469fc8c572aab39542d459e) * fix: SW-2451 Optimized code * fix: SW-2451 Added forced focus & optimised code * Fix: SW-2451 Optimised code * fix: SW-2451 Removed untranslated error message * fix: SW-2451 Optimised code Approved-by: Erik Tiekstra
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
"use client"
|
|
||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import * as Sentry from "@sentry/nextjs"
|
import * as Sentry from "@sentry/nextjs"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
@@ -10,29 +8,38 @@ import { z } from "zod"
|
|||||||
import { Search } from "@/components/Forms/BookingWidget/FormContent/Search"
|
import { Search } from "@/components/Forms/BookingWidget/FormContent/Search"
|
||||||
import { toast } from "@/components/TempDesignSystem/Toasts"
|
import { toast } from "@/components/TempDesignSystem/Toasts"
|
||||||
|
|
||||||
const jumpToSchema = z.object({
|
const destinationSearchFormSchema = z.object({
|
||||||
destinationSearch: z.string().min(1, "Please enter a search term"),
|
destinationSearch: z.string().min(1),
|
||||||
})
|
})
|
||||||
type JumpToSchema = z.infer<typeof jumpToSchema>
|
type DestinationSearchFormSchema = z.infer<typeof destinationSearchFormSchema>
|
||||||
|
|
||||||
export function JumpTo() {
|
type DestinationSearchFormProps = {
|
||||||
|
isMobile?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DestinationSearchForm({
|
||||||
|
isMobile,
|
||||||
|
}: DestinationSearchFormProps) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
const methods = useForm<JumpToSchema>({
|
|
||||||
|
const methods = useForm<DestinationSearchFormSchema>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
destinationSearch: "",
|
destinationSearch: "",
|
||||||
},
|
},
|
||||||
shouldFocusError: false,
|
shouldFocusError: false,
|
||||||
mode: "onSubmit",
|
mode: "onSubmit",
|
||||||
resolver: zodResolver(jumpToSchema),
|
resolver: zodResolver(destinationSearchFormSchema),
|
||||||
reValidateMode: "onSubmit",
|
reValidateMode: "onSubmit",
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormProvider {...methods}>
|
<FormProvider {...methods}>
|
||||||
<Search
|
<Search
|
||||||
|
autoFocus={isMobile}
|
||||||
|
alwaysShowResults={isMobile}
|
||||||
includeTypes={["cities", "hotels", "countries"]}
|
includeTypes={["cities", "hotels", "countries"]}
|
||||||
variant="rounded"
|
variant={isMobile ? "default" : "rounded"}
|
||||||
handlePressEnter={() => {
|
handlePressEnter={() => {
|
||||||
void 0
|
void 0
|
||||||
}}
|
}}
|
||||||
@@ -51,13 +58,11 @@ export function JumpTo() {
|
|||||||
{ locationName: item.name }
|
{ locationName: item.name }
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
router.push(item.url)
|
router.push(item.url)
|
||||||
}}
|
}}
|
||||||
withSearchButton
|
withSearchButton={!isMobile}
|
||||||
/>
|
/>
|
||||||
</FormProvider>
|
</FormProvider>
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
.trigger {
|
||||||
|
background: var(--Base-Surface-Primary-light-Normal);
|
||||||
|
border: 1px solid var(--Border-Default);
|
||||||
|
border-radius: var(--Corner-radius-rounded);
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: var(--Space-x15) var(--Space-x15) var(--Space-x15) var(--Space-x3);
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.whereTo {
|
||||||
|
display: block;
|
||||||
|
color: var(--Base-Text-Accent);
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
background: var(--Base-Button-Primary-Fill-Normal);
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
border-radius: var(--Corner-radius-Rounded);
|
||||||
|
color: var(--Base-Text-Inverted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modalOverlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background-color: var(--Overlay-40);
|
||||||
|
|
||||||
|
&[data-entering] {
|
||||||
|
animation: overlay-fade 200ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
&[data-exiting] {
|
||||||
|
animation: overlay-fade 150ms reverse ease-in;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: calc(100dvh - 20px);
|
||||||
|
border-radius: var(--Corner-radius-md) var(--Corner-radius-md) 0 0;
|
||||||
|
background-color: var(--Surface-Primary-Default);
|
||||||
|
box-shadow: 0px 0px 14px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
|
||||||
|
&[data-entering] {
|
||||||
|
animation: modal-anim 200ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
&[data-exiting] {
|
||||||
|
animation: modal-anim 150ms reverse ease-in;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.modalDialog {
|
||||||
|
display: grid;
|
||||||
|
gap: var(--Space-x15);
|
||||||
|
padding: var(--Space-x15) var(--Space-x2) var(--Space-x7);
|
||||||
|
}
|
||||||
|
|
||||||
|
.close {
|
||||||
|
margin-right: -10px;
|
||||||
|
justify-self: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes overlay-fade {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes modal-anim {
|
||||||
|
from {
|
||||||
|
transform: translateY(100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Dialog,
|
||||||
|
DialogTrigger,
|
||||||
|
Modal,
|
||||||
|
ModalOverlay,
|
||||||
|
} from "react-aria-components"
|
||||||
|
import { useIntl } from "react-intl"
|
||||||
|
import { useMediaQuery } from "usehooks-ts"
|
||||||
|
|
||||||
|
import { IconButton } from "@scandic-hotels/design-system/IconButton"
|
||||||
|
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||||
|
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||||
|
|
||||||
|
import { DestinationSearchForm } from "./Form"
|
||||||
|
|
||||||
|
import styles from "./destinationSearch.module.css"
|
||||||
|
|
||||||
|
export function DestinationSearch() {
|
||||||
|
const intl = useIntl()
|
||||||
|
const displayInModal = useMediaQuery("(max-width: 767px)")
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div hidden={!displayInModal}>
|
||||||
|
<DialogTrigger>
|
||||||
|
<Button className={styles.trigger}>
|
||||||
|
<span>
|
||||||
|
<Typography variant="Body/Supporting text (caption)/smBold">
|
||||||
|
<span className={styles.whereTo}>
|
||||||
|
{intl.formatMessage({
|
||||||
|
defaultMessage: "Where to?",
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="Body/Paragraph/mdRegular">
|
||||||
|
<span>
|
||||||
|
{intl.formatMessage({
|
||||||
|
defaultMessage: "Hotels & Destinations",
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
</Typography>
|
||||||
|
</span>
|
||||||
|
<span className={styles.icon}>
|
||||||
|
<MaterialIcon color="CurrentColor" icon="search" size={24} />
|
||||||
|
</span>
|
||||||
|
</Button>
|
||||||
|
<ModalOverlay className={styles.modalOverlay} isDismissable={true}>
|
||||||
|
<Modal className={styles.modal}>
|
||||||
|
<Dialog className={styles.modalDialog}>
|
||||||
|
{({ close }) => (
|
||||||
|
<>
|
||||||
|
<IconButton
|
||||||
|
onPress={close}
|
||||||
|
theme="Black"
|
||||||
|
style="Muted"
|
||||||
|
className={styles.close}
|
||||||
|
>
|
||||||
|
<MaterialIcon
|
||||||
|
color="CurrentColor"
|
||||||
|
icon="close"
|
||||||
|
size={24}
|
||||||
|
/>
|
||||||
|
</IconButton>
|
||||||
|
<DestinationSearchForm isMobile={true} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Dialog>
|
||||||
|
</Modal>
|
||||||
|
</ModalOverlay>
|
||||||
|
</DialogTrigger>
|
||||||
|
</div>
|
||||||
|
<div hidden={displayInModal}>
|
||||||
|
<DestinationSearchForm />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
.searchContainer {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
margin: 0 auto;
|
|
||||||
width: 100%;
|
|
||||||
border-radius: var(--Corner-radius-rounded);
|
|
||||||
border: 1px solid var(--Border-Default);
|
|
||||||
background: var(--Surface-Primary-Default);
|
|
||||||
padding: var(--Space-x15) var(--Space-x15) var(--Space-x15) var(--Space-x3);
|
|
||||||
|
|
||||||
& > * {
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.jumpToContainer {
|
.destinationSearchContainer {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
@media screen and (min-width: 768px) {
|
@media screen and (min-width: 768px) {
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import Blocks from "@/components/Blocks"
|
|||||||
import SkeletonShimmer from "@/components/SkeletonShimmer"
|
import SkeletonShimmer from "@/components/SkeletonShimmer"
|
||||||
import TrackingSDK from "@/components/TrackingSDK"
|
import TrackingSDK from "@/components/TrackingSDK"
|
||||||
|
|
||||||
|
import { DestinationSearch } from "./DestinationSearch"
|
||||||
import HotelsSection from "./HotelsSection"
|
import HotelsSection from "./HotelsSection"
|
||||||
import { JumpTo } from "./JumpTo"
|
|
||||||
import OverviewMapContainer from "./OverviewMapContainer"
|
import OverviewMapContainer from "./OverviewMapContainer"
|
||||||
|
|
||||||
import styles from "./destinationOverviewPage.module.css"
|
import styles from "./destinationOverviewPage.module.css"
|
||||||
@@ -29,8 +29,8 @@ export default async function DestinationOverviewPage() {
|
|||||||
<Typography variant="Title/lg">
|
<Typography variant="Title/lg">
|
||||||
<h1 className={styles.heading}>{destinationOverviewPage.heading}</h1>
|
<h1 className={styles.heading}>{destinationOverviewPage.heading}</h1>
|
||||||
</Typography>
|
</Typography>
|
||||||
<div className={styles.jumpToContainer}>
|
<div className={styles.destinationSearchContainer}>
|
||||||
<JumpTo />
|
<DestinationSearch />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.mapContainer}>
|
<div className={styles.mapContainer}>
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import SearchList from "./SearchList"
|
|||||||
import styles from "./search.module.css"
|
import styles from "./search.module.css"
|
||||||
|
|
||||||
interface SearchProps {
|
interface SearchProps {
|
||||||
|
autoFocus?: boolean
|
||||||
|
alwaysShowResults?: boolean
|
||||||
className?: string
|
className?: string
|
||||||
handlePressEnter: () => void
|
handlePressEnter: () => void
|
||||||
inputName: string
|
inputName: string
|
||||||
@@ -32,6 +34,8 @@ interface SearchProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Search({
|
export function Search({
|
||||||
|
autoFocus,
|
||||||
|
alwaysShowResults,
|
||||||
handlePressEnter,
|
handlePressEnter,
|
||||||
inputName: SEARCH_TERM_NAME,
|
inputName: SEARCH_TERM_NAME,
|
||||||
onSelect,
|
onSelect,
|
||||||
@@ -97,6 +101,7 @@ export function Search({
|
|||||||
itemToString={(value) => (value ? value.name : "")}
|
itemToString={(value) => (value ? value.name : "")}
|
||||||
onSelect={handleOnSelect}
|
onSelect={handleOnSelect}
|
||||||
defaultHighlightedIndex={0}
|
defaultHighlightedIndex={0}
|
||||||
|
isOpen={alwaysShowResults}
|
||||||
>
|
>
|
||||||
{({
|
{({
|
||||||
getInputProps,
|
getInputProps,
|
||||||
@@ -149,6 +154,7 @@ export function Search({
|
|||||||
},
|
},
|
||||||
type: "search",
|
type: "search",
|
||||||
})}
|
})}
|
||||||
|
autoFocus={autoFocus}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user