diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx index f0c9faef4..3e4c16291 100644 --- a/.storybook/preview.tsx +++ b/.storybook/preview.tsx @@ -4,6 +4,7 @@ import { initialize, mswLoader } from "msw-storybook-addon"; import { RouterContext } from "next/dist/shared/lib/router-context.shared-runtime"; import React from "react"; import { MemoryRouter } from "react-router-dom"; +import "react-tooltip/dist/react-tooltip.css"; import "tailwindcss/tailwind.css"; import "../pages/global.css"; import "./storybook.css"; diff --git a/src/ui/Age/Age.stories.tsx b/src/ui/Age/Age.stories.tsx new file mode 100644 index 000000000..3913b06dc --- /dev/null +++ b/src/ui/Age/Age.stories.tsx @@ -0,0 +1,16 @@ +import { Meta } from "@storybook/react"; +import dayjs from "dayjs"; +import Age from "./Age"; + +export default { + component: Age, + title: "Age" +} satisfies Meta; + +export const Default = () => ( + +); + +export const WithFromAndTwo = () => ( + +); diff --git a/src/ui/Age/Age.tsx b/src/ui/Age/Age.tsx index 0b5895ee3..05402c274 100644 --- a/src/ui/Age/Age.tsx +++ b/src/ui/Age/Age.tsx @@ -1,45 +1,84 @@ -import dayjs from "dayjs"; import clsx from "clsx"; +import dayjs from "dayjs"; +import LocalizedFormat from "dayjs/plugin/localizedFormat"; +import { Tooltip } from "react-tooltip"; import { isEmpty } from "../../utils/date"; +function formatDate(data: dayjs.Dayjs) { + return data.format("YYYY-MM-DD HH:mm:ssZ"); +} + +dayjs.extend(LocalizedFormat); + +type AgeProps = { + className?: string; + from?: Date | string; + to?: Date | string; + suffix?: boolean; +}; + export default function Age({ className = "", from, to, suffix = false -}: { - className?: string; - from?: Date | string; - to?: Date | string; - suffix?: boolean; -}) { +}: AgeProps) { if (isEmpty(from)) { return null; } - let _from = dayjs(from); + + const _from = dayjs(from); if (isEmpty(to)) { return ( - - {_from.local().fromNow(!suffix)} - + <> + + {_from.local().fromNow(!suffix)} + + + ); } - let _to = dayjs(to); - let duration = dayjs.duration(_to.diff(_from)); + const _to = dayjs(to); + + const duration = dayjs.duration(_to.diff(_from)); if (duration.asMilliseconds() < 1000) { return ( - - {duration.asMilliseconds()}ms - + <> + + {duration.asMilliseconds()}ms + + + ); } return ( - - {_from.local().to(_to)} - + <> + + {_from.local().to(_to)} + + + ); }