* Memoize delayProps * Refactor Escape key handler * Use useTooltipContext * Remove delay: 0 from tooltips * Only use isTooltipOpen if available * Only show transition for initial tooltip GitOrigin-RevId: 74950ea7e705acb8f42dea552b23ce93c66058c7
42 lines
900 B
TypeScript
42 lines
900 B
TypeScript
import {
|
|
createContext,
|
|
Dispatch,
|
|
FC,
|
|
PropsWithChildren,
|
|
SetStateAction,
|
|
useContext,
|
|
useMemo,
|
|
useState,
|
|
} from 'react'
|
|
import useDebounce from '@/shared/hooks/use-debounce'
|
|
|
|
const TooltipContext = createContext<
|
|
| {
|
|
isTooltipOpen: boolean
|
|
setIsTooltipOpen: Dispatch<SetStateAction<boolean>>
|
|
}
|
|
| undefined
|
|
>(undefined)
|
|
|
|
export const TooltipProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
const [isTooltipOpen, setIsTooltipOpen] = useState(false)
|
|
|
|
const debouncedIsTooltipOpen = useDebounce(isTooltipOpen, 100)
|
|
|
|
const value = useMemo(
|
|
() => ({
|
|
isTooltipOpen: debouncedIsTooltipOpen,
|
|
setIsTooltipOpen,
|
|
}),
|
|
[debouncedIsTooltipOpen, setIsTooltipOpen]
|
|
)
|
|
|
|
return (
|
|
<TooltipContext.Provider value={value}>{children}</TooltipContext.Provider>
|
|
)
|
|
}
|
|
|
|
export const useTooltipContext = () => {
|
|
return useContext(TooltipContext)
|
|
}
|