Files
web/packages/design-system/lib/components/Tooltip/index.tsx
Christel Westerberg 6b08d5a113 Merged in fix/STAY-135 (pull request #3368)
Fix/STAY-135 & STAY-127

* fix: make quantity and delivery separate steps in mobile

* fix: update design for delivery step in ancillary flow

* fix: add error state for missing time

* fix: only allow points or cash payment for ancillaries

* fix: break out stepper to design system

* fix: update design of select quantity step in add ancillaries flow

* fix: add error states for quantity

* fix: handle insufficient points case

* fix: update stepper to include optional disabledMessage tooltip

* fix: handle validations

* fix: change name to camel case


Approved-by: Bianca Widstam
Approved-by: Chuma Mcphoy (We Ahead)
2025-12-18 13:31:43 +00:00

89 lines
2.1 KiB
TypeScript

import { type PropsWithChildren, useState } from 'react'
import { tooltipVariants } from './variants'
import styles from './tooltip.module.css'
import { Typography } from '../Typography'
type TooltipPosition = 'left' | 'right' | 'top' | 'bottom'
type VerticalArrow = 'top' | 'bottom' | 'center'
type HorizontalArrow = 'left' | 'right' | 'center'
type ValidArrowMap = {
left: VerticalArrow
right: VerticalArrow
top: HorizontalArrow
bottom: HorizontalArrow
}
type ValidArrow<P extends TooltipPosition> = P extends keyof ValidArrowMap
? ValidArrowMap[P]
: never
interface TooltipProps<P extends TooltipPosition = TooltipPosition> {
heading?: string
text?: string
position: P
arrow: ValidArrow<P>
isTouchable?: boolean
isVisible?: boolean
}
export function Tooltip<P extends TooltipPosition>({
heading,
text,
position,
arrow,
children,
isTouchable = false,
isVisible = true,
}: PropsWithChildren<TooltipProps<P>>) {
const className = tooltipVariants({ position, arrow })
const [isActive, setIsActive] = useState(false)
function handleToggle() {
setIsActive((prevState) => !prevState)
setTimeout(() => {
setIsActive(false)
}, 3000)
}
function handleKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault()
handleToggle()
}
}
if (!isVisible) {
return <> {children} </>
}
return (
<div
className={styles.tooltipContainer}
role="tooltip"
aria-label={text}
tabIndex={0}
onClick={isTouchable ? undefined : handleToggle}
onTouchStart={isTouchable ? handleToggle : undefined}
onKeyDown={handleKeyDown}
data-active={isActive}
>
<div className={className}>
{heading ? (
<Typography variant="Body/Supporting text (caption)/smBold">
<p>{heading}</p>
</Typography>
) : null}
{text ? (
<Typography variant="Body/Supporting text (caption)/smRegular">
<p>{text} </p>
</Typography>
) : null}
</div>
{children}
</div>
)
}