From 86ae1acedd4ce37025f87ace0a4ad99b30c2fda2 Mon Sep 17 00:00:00 2001 From: giuliana-gladeye Date: Tue, 9 Jun 2026 17:37:29 +1200 Subject: [PATCH 1/7] feat: added format date component --- .../demo/src/components/demo/format-date.tsx | 162 ++++++++++++++++++ .../src/content/components/format-date.mdx | 106 ++++++++++++ .../format-date/format-date.module.css | 10 ++ .../components/format-date/format-date.tsx | 162 ++++++++++++++++++ packages/ui/src/components/index.ts | 1 + 5 files changed, 441 insertions(+) create mode 100644 packages/demo/src/components/demo/format-date.tsx create mode 100644 packages/demo/src/content/components/format-date.mdx create mode 100644 packages/ui/src/components/format-date/format-date.module.css create mode 100644 packages/ui/src/components/format-date/format-date.tsx diff --git a/packages/demo/src/components/demo/format-date.tsx b/packages/demo/src/components/demo/format-date.tsx new file mode 100644 index 0000000..3ee4316 --- /dev/null +++ b/packages/demo/src/components/demo/format-date.tsx @@ -0,0 +1,162 @@ +import { PanelLabel, FormatDate, Card, CardContent } from "@eqtylab/equality"; +import { useMemo } from "react"; + +const MINUTE = 60 * 1000; +const HOUR = 60 * MINUTE; +const DAY = 24 * HOUR; +const WEEK = 7 * DAY; + +export function FormatDateRelativeDemo() { + // Compute offsets from "now" once on mount so the examples read naturally. + const samples = useMemo(() => { + const now = new Date(); + const time = now.getTime(); + return [ + { label: "Seconds ago", date: new Date(time - 10 * 1000) }, + { label: "Minutes ago", date: new Date(time - 5 * MINUTE) }, + { label: "Hours ago", date: new Date(time - 3 * HOUR) }, + { label: "Days ago", date: new Date(time - 2 * DAY) }, + { label: "Weeks ago", date: new Date(time - 2 * WEEK) }, + { label: "In the future", date: new Date(time + 4 * DAY) }, + ]; + }, []); + + return ( +
+ + + {samples.map((sample) => ( +
+ + +
+ ))} +
+
+
+ ); +} + +export function FormatDateTimeZoneDemo() { + const date = useMemo(() => new Date("2026-06-09T18:42:03Z"), []); + + return ( +
+ + +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ ); +} + +export function FormatDateOptionsDemo() { + const date = useMemo(() => new Date("2026-06-09T18:42:03Z"), []); + + // Each entry overrides the default Intl.DateTimeFormat options. + const samples: { + label: string; + options: Intl.DateTimeFormatOptions; + }[] = [ + { + label: "Date only", + options: { year: "numeric", month: "long", day: "numeric" }, + }, + { + label: "Time only", + options: { hour: "2-digit", minute: "2-digit" }, + }, + { + label: "With weekday", + options: { + weekday: "long", + year: "numeric", + month: "long", + day: "numeric", + }, + }, + { + label: "Short numeric", + options: { dateStyle: "short", timeStyle: "short" }, + }, + ]; + + return ( +
+ + + {samples.map((sample) => ( +
+ + +
+ ))} +
+
+
+ ); +} diff --git a/packages/demo/src/content/components/format-date.mdx b/packages/demo/src/content/components/format-date.mdx new file mode 100644 index 0000000..783ad96 --- /dev/null +++ b/packages/demo/src/content/components/format-date.mdx @@ -0,0 +1,106 @@ +--- +layout: "@demo/layouts/mdx-layout.astro" +heading: "Format Date" +description: "Render a date as relative or absolute time using a semantic