import * as React from "react"; import type { locales } from "@shared/utils/date"; import Tooltip from "~/components/Tooltip"; import { useLocaleTime } from "~/hooks/useLocaleTime"; export type Props = { children?: React.ReactNode; dateTime: string; addSuffix?: boolean; shorten?: boolean; relative?: boolean; format?: Partial>; /** Additional content shown below the date in the tooltip. */ tooltipDetail?: React.ReactNode; }; const LocaleTime: React.FC = ({ children, tooltipDetail, ...rest }: Props) => { const { tooltipContent, content } = useLocaleTime(rest); const [isInteractive, setIsInteractive] = React.useState(false); // Detail is only available in the tooltip, so it must be reachable by keyboard. const hasDetail = !!tooltipDetail; const time = ( ); return isInteractive || hasDetail ? ( {tooltipContent}
{tooltipDetail} ) : ( tooltipContent ) } side="bottom" > {time}
) : ( time ); }; export default LocaleTime;