From acfd6640e0c3e7340e15cb4d28a32a4accd6be6e Mon Sep 17 00:00:00 2001 From: Alina Visan Date: Wed, 15 Feb 2023 17:50:20 +0200 Subject: [PATCH] Tooltip refactor (#1080) Co-authored-by: ImmanuelBaskaran Co-authored-by: sion-docs <104632245+sion-docs@users.noreply.github.com> Co-authored-by: Josh Wooding <12938082+joshwooding@users.noreply.github.com> --- internal/CalendarDay.tsx | 72 ++++++++---------- internal/CalendarNavigation.tsx | 126 +++++++++++++------------------- 2 files changed, 80 insertions(+), 118 deletions(-) diff --git a/internal/CalendarDay.tsx b/internal/CalendarDay.tsx index deb1d97cd..a3b11e706 100644 --- a/internal/CalendarDay.tsx +++ b/internal/CalendarDay.tsx @@ -1,13 +1,13 @@ -import { makePrefixer, useForkRef } from "@salt-ds/core"; +import { makePrefixer } from "@salt-ds/core"; import { CloseIcon } from "@salt-ds/icons"; import { clsx } from "clsx"; import { ComponentPropsWithRef, forwardRef, ReactElement, useRef } from "react"; import { DateValue } from "@internationalized/date"; +import { Tooltip, TooltipProps } from "../../tooltip"; import { DayStatus, useCalendarDay } from "../useCalendarDay"; import "./CalendarDay.css"; import { formatDate } from "./utils"; -import { Tooltip, TooltipProps, useTooltip } from "../../tooltip"; export type DateFormatter = (day: Date) => string | undefined; @@ -38,45 +38,35 @@ export const CalendarDay = forwardRef( ); const { outOfRange, today, unselectable, hidden } = status; - const { getTriggerProps, getTooltipProps } = useTooltip({ - disabled: !unselectableReason, - placement: "top", - enterDelay: 300, - }); - - const { ref: triggerRef, ...triggerProps } = getTriggerProps<"button">({ - "aria-label": formatDate(day), - ...dayProps, - ...rest, - className: clsx( - withBaseName(), - { - [withBaseName("hidden")]: hidden, - [withBaseName("outOfRange")]: outOfRange, - [withBaseName("today")]: today, - [withBaseName("unselectable")]: !!unselectable, - [withBaseName("unselectableLow")]: unselectable === "low", - [withBaseName("unselectableMedium")]: unselectable === "medium", - }, - dayProps.className, - className - ), - }); - - const handleTriggerRef = useForkRef(triggerRef, dayRef); - const handleRef = useForkRef(handleTriggerRef, ref); - return ( - <> - - - + ); } ); diff --git a/internal/CalendarNavigation.tsx b/internal/CalendarNavigation.tsx index c1afe6997..32e81eece 100644 --- a/internal/CalendarNavigation.tsx +++ b/internal/CalendarNavigation.tsx @@ -9,7 +9,7 @@ import { } from "react"; import { Dropdown, DropdownProps } from "../../dropdown"; import { ListItem, ListItemType } from "../../list"; -import { Tooltip, useTooltip } from "../../tooltip"; +import { Tooltip } from "../../tooltip"; import { useCalendarContext } from "./CalendarContext"; @@ -112,26 +112,15 @@ const ListItemWithTooltip: ListItemType = ({ item, label, ...props -}) => { - const { getTooltipProps, getTriggerProps } = useTooltip({ - placement: "right", - disabled: !item?.disabled, - }); - - const { ref: triggerRef, ...triggerProps } = - getTriggerProps(props); - - return ( - - {label} - - - ); -}; +}) => ( + + {label} + +); export const CalendarNavigation = forwardRef< HTMLDivElement, @@ -186,14 +175,15 @@ export const CalendarNavigation = forwardRef< } }; - const monthDropdownId = useId(MonthDropdownProps?.id); + const monthDropdownId = useId(MonthDropdownProps?.id) || ""; const monthDropdownLabelledBy = clsx( MonthDropdownProps?.["aria-labelledby"], // TODO need a prop on Dropdown to allow buttonId to be passed, should not make assumptions about internal // id assignment like this `${monthDropdownId}-control` ); - const yearDropdownId = useId(YearDropdownProps?.id); + + const yearDropdownId = useId(YearDropdownProps?.id) || ""; const yearDropdownLabelledBy = clsx( YearDropdownProps?.["aria-labelledby"], `${yearDropdownId}-control` @@ -210,22 +200,6 @@ export const CalendarNavigation = forwardRef< return formatDate(date.value, { year: "numeric" }); }; - const { - getTriggerProps: getPreviousButtonProps, - getTooltipProps: getPreviousButtonTooltipProps, - } = useTooltip({ - placement: "top", - disabled: canNavigatePrevious, - }); - - const { - getTriggerProps: getNextButtonProps, - getTooltipProps: getNextButtonTooltipProps, - } = useTooltip({ - placement: "top", - disabled: canNavigateNext, - }); - return (
- + placement="top" + disabled={canNavigatePrevious} + content="Past dates are out of range" + > + + source={months} id={monthDropdownId} @@ -282,26 +255,25 @@ export const CalendarNavigation = forwardRef< fullWidth /> )} - + placement="top" + disabled={canNavigateNext} + content="Future dates are out of range" + > + +
); });