fix(SW-1003): Moved tooltip on mobile and fixed bug with touch/click
This commit is contained in:
@@ -4,8 +4,10 @@ import { zodResolver } from "@hookform/resolvers/zod"
|
|||||||
import { useCallback, useEffect, useMemo } from "react"
|
import { useCallback, useEffect, useMemo } from "react"
|
||||||
import { FormProvider, useForm } from "react-hook-form"
|
import { FormProvider, useForm } from "react-hook-form"
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
import { useMediaQuery } from "usehooks-ts"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
|
import { InfoCircleIcon } from "@/components/Icons"
|
||||||
import CheckboxChip from "@/components/TempDesignSystem/Form/FilterChip/Checkbox"
|
import CheckboxChip from "@/components/TempDesignSystem/Form/FilterChip/Checkbox"
|
||||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||||
@@ -25,6 +27,8 @@ export default function RoomFilter({
|
|||||||
onFilter,
|
onFilter,
|
||||||
filterOptions,
|
filterOptions,
|
||||||
}: RoomFilterProps) {
|
}: RoomFilterProps) {
|
||||||
|
const isAboveMobile = useMediaQuery("(min-width: 768px)")
|
||||||
|
|
||||||
const initialFilterValues = useMemo(
|
const initialFilterValues = useMemo(
|
||||||
() =>
|
() =>
|
||||||
filterOptions.reduce(
|
filterOptions.reduce(
|
||||||
@@ -55,6 +59,8 @@ export default function RoomFilter({
|
|||||||
id: "Pet-friendly rooms have an additional fee of 20 EUR per stay",
|
id: "Pet-friendly rooms have an additional fee of 20 EUR per stay",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const showTooltip = isAboveMobile && petFriendly
|
||||||
|
|
||||||
const submitFilter = useCallback(() => {
|
const submitFilter = useCallback(() => {
|
||||||
const data = getValues()
|
const data = getValues()
|
||||||
onFilter(data)
|
onFilter(data)
|
||||||
@@ -77,19 +83,50 @@ export default function RoomFilter({
|
|||||||
</div>
|
</div>
|
||||||
<div className={styles.infoMobile}>
|
<div className={styles.infoMobile}>
|
||||||
<div className={styles.filterInfo}>
|
<div className={styles.filterInfo}>
|
||||||
<Caption
|
{!isAboveMobile ? (
|
||||||
type="label"
|
<Tooltip
|
||||||
color="baseTextMediumContrast"
|
text={tooltipText}
|
||||||
textTransform="uppercase"
|
position="bottom"
|
||||||
>
|
arrow="left"
|
||||||
{intl.formatMessage({ id: "Filter" })}
|
isTouchable
|
||||||
</Caption>
|
>
|
||||||
<Caption type="label" color="baseTextMediumContrast">
|
<InfoCircleIcon
|
||||||
{Object.entries(selectedFilters)
|
color="uiTextHighContrast"
|
||||||
.filter(([_, value]) => value)
|
height={20}
|
||||||
.map(([key]) => intl.formatMessage({ id: key }))
|
width={20}
|
||||||
.join(", ")}
|
/>
|
||||||
</Caption>
|
|
||||||
|
<Caption
|
||||||
|
type="label"
|
||||||
|
color="baseTextMediumContrast"
|
||||||
|
textTransform="uppercase"
|
||||||
|
>
|
||||||
|
{intl.formatMessage({ id: "Filter" })}
|
||||||
|
</Caption>
|
||||||
|
<Caption type="label" color="baseTextMediumContrast">
|
||||||
|
{Object.entries(selectedFilters)
|
||||||
|
.filter(([_, value]) => value)
|
||||||
|
.map(([key]) => intl.formatMessage({ id: key }))
|
||||||
|
.join(", ")}
|
||||||
|
</Caption>
|
||||||
|
</Tooltip>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Caption
|
||||||
|
type="label"
|
||||||
|
color="baseTextMediumContrast"
|
||||||
|
textTransform="uppercase"
|
||||||
|
>
|
||||||
|
{intl.formatMessage({ id: "Filter" })}
|
||||||
|
</Caption>
|
||||||
|
<Caption type="label" color="baseTextMediumContrast">
|
||||||
|
{Object.entries(selectedFilters)
|
||||||
|
.filter(([_, value]) => value)
|
||||||
|
.map(([key]) => intl.formatMessage({ id: key }))
|
||||||
|
.join(", ")}
|
||||||
|
</Caption>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<Caption color="uiTextHighContrast">
|
<Caption color="uiTextHighContrast">
|
||||||
{intl.formatMessage(
|
{intl.formatMessage(
|
||||||
@@ -118,11 +155,11 @@ export default function RoomFilter({
|
|||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
selected={getValues(code)}
|
selected={getValues(code)}
|
||||||
Icon={getIconForFeatureCode(code)}
|
Icon={getIconForFeatureCode(code)}
|
||||||
hasTooltip={isPetRoom}
|
hasTooltip={isPetRoom && isAboveMobile}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
||||||
return isPetRoom ? (
|
return showTooltip ? (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
key={option.code}
|
key={option.code}
|
||||||
text={tooltipText}
|
text={tooltipText}
|
||||||
|
|||||||
@@ -14,12 +14,20 @@ export function Tooltip<P extends TooltipPosition>({
|
|||||||
position,
|
position,
|
||||||
arrow,
|
arrow,
|
||||||
children,
|
children,
|
||||||
|
isTouchable = false,
|
||||||
}: PropsWithChildren<TooltipProps<P>>) {
|
}: PropsWithChildren<TooltipProps<P>>) {
|
||||||
const className = tooltipVariants({ position, arrow })
|
const className = tooltipVariants({ position, arrow })
|
||||||
const [isActive, setIsActive] = useState(false)
|
const [isActive, setIsActive] = useState(false)
|
||||||
|
|
||||||
function handleToggle() {
|
function handleToggle() {
|
||||||
setIsActive(!isActive)
|
setIsActive((prevState) => !prevState)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {
|
||||||
|
if (event.key === "Enter" || event.key === " ") {
|
||||||
|
event.preventDefault()
|
||||||
|
handleToggle()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -27,8 +35,10 @@ export function Tooltip<P extends TooltipPosition>({
|
|||||||
className={styles.tooltipContainer}
|
className={styles.tooltipContainer}
|
||||||
role="tooltip"
|
role="tooltip"
|
||||||
aria-label={text}
|
aria-label={text}
|
||||||
onClick={handleToggle}
|
tabIndex={0}
|
||||||
onTouchStart={handleToggle}
|
onClick={isTouchable ? undefined : handleToggle}
|
||||||
|
onTouchStart={isTouchable ? handleToggle : undefined}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
data-active={isActive}
|
data-active={isActive}
|
||||||
>
|
>
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
|
|||||||
@@ -18,4 +18,5 @@ export interface TooltipProps<P extends TooltipPosition = TooltipPosition> {
|
|||||||
text?: string
|
text?: string
|
||||||
position: P
|
position: P
|
||||||
arrow: ValidArrow<P>
|
arrow: ValidArrow<P>
|
||||||
|
isTouchable?: boolean
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user