Files
James Ritchie 553a03580f Show a tooltip when hovering over any DateTime (#2003)
* Adds a tooltip to display the UTC, timezone and local time for DateTime

* Made it safer for SSR

* Makes the copy function into a hook and separate button + adds copy dateTime button to the date tooltip

* Adds an extra-small size copy button

* Show the offset (UTC +1) next to your local time

* Optionally don’t show the date tooltip. Defaults to true (always show)

* Tidy imports

* Refactor the tooltip content to remove duplicated markup

* Coderabbit suggestion to include support for minutes for some timezones like Nepal
2025-05-01 10:00:42 +01:00

23 lines
496 B
TypeScript

import { useCallback, useState } from "react";
export function useCopy(value: string, duration = 1500) {
const [copied, setCopied] = useState(false);
const copy = useCallback(
(e?: React.MouseEvent) => {
if (e) {
e.preventDefault();
e.stopPropagation();
}
navigator.clipboard.writeText(value);
setCopied(true);
setTimeout(() => {
setCopied(false);
}, duration);
},
[value, duration]
);
return { copy, copied };
}