From 2fd3ff1240ebd8174097aa95daaa3e87ad2401f8 Mon Sep 17 00:00:00 2001 From: Phil-hacker <61991187+Phil-hacker@users.noreply.github.com> Date: Sun, 1 Jun 2025 08:25:35 +0200 Subject: [PATCH] Add a time component (#2347) * Add Time component * Use the Time component on the tournament and scrims pages * fix formatting issues * renamed the Time component to TimePopover * change the Time component trigger to a button * remove unused import * fix button styling --- app/components/TimePopover.tsx | 83 +++++++++++++++++++ app/features/scrims/routes/scrims.$id.tsx | 21 +++-- .../tournament/routes/to.$id.register.tsx | 14 ++-- app/styles/common.css | 15 ++++ locales/de/common.json | 1 + locales/en/common.json | 1 + 6 files changed, 120 insertions(+), 15 deletions(-) create mode 100644 app/components/TimePopover.tsx diff --git a/app/components/TimePopover.tsx b/app/components/TimePopover.tsx new file mode 100644 index 000000000..6affe59ff --- /dev/null +++ b/app/components/TimePopover.tsx @@ -0,0 +1,83 @@ +import { useRef, useState } from "react"; +import * as React from "react"; +import { Dialog } from "react-aria-components"; +import { Popover } from "react-aria-components"; +import { useTranslation } from "react-i18next"; +import { useCopyToClipboard } from "react-use"; +import { SendouButton } from "./elements/Button"; +import { CheckmarkIcon } from "./icons/Checkmark"; +import { ClipboardIcon } from "./icons/Clipboard"; + +export default function TimePopover({ + time, + options = { + minute: "numeric", + hour: "numeric", + day: "numeric", + month: "long", + }, +}: { + time: Date; + options?: Intl.DateTimeFormatOptions; +}) { + const { i18n } = useTranslation(); + + const [open, setOpen] = useState(false); + + const triggerRef = useRef(null); + + const { t } = useTranslation(["common"]); + + const [state, copyToClipboard] = useCopyToClipboard(); + const [copySuccess, setCopySuccess] = React.useState(false); + + React.useEffect(() => { + if (!state.value) return; + + setCopySuccess(true); + const timeout = setTimeout(() => setCopySuccess(false), 2000); + + return () => clearTimeout(timeout); + }, [state]); + + return ( +