@gerege-systems/ui 0.14.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist-lib/components/ui/Avatar.js +1 -0
  2. package/dist-lib/components/ui/Avatar.js.map +1 -1
  3. package/dist-lib/components/ui/DataGrid.d.ts +7 -2
  4. package/dist-lib/components/ui/DataGrid.js +66 -54
  5. package/dist-lib/components/ui/DataGrid.js.map +1 -1
  6. package/dist-lib/components/ui/DesignSystemProvider.js +25 -25
  7. package/dist-lib/components/ui/DesignSystemProvider.js.map +1 -1
  8. package/dist-lib/components/ui/Dialog.d.ts +5 -1
  9. package/dist-lib/components/ui/Dialog.js +54 -57
  10. package/dist-lib/components/ui/Dialog.js.map +1 -1
  11. package/dist-lib/components/ui/ErrorState.d.ts +5 -3
  12. package/dist-lib/components/ui/ErrorState.js +1 -1
  13. package/dist-lib/components/ui/ErrorState.js.map +1 -1
  14. package/dist-lib/components/ui/FileUpload.d.ts +6 -0
  15. package/dist-lib/components/ui/FileUpload.js +60 -55
  16. package/dist-lib/components/ui/FileUpload.js.map +1 -1
  17. package/dist-lib/components/ui/MultiSelect.js +40 -39
  18. package/dist-lib/components/ui/MultiSelect.js.map +1 -1
  19. package/dist-lib/components/ui/RelativeTime.d.ts +5 -1
  20. package/dist-lib/components/ui/RelativeTime.js +23 -19
  21. package/dist-lib/components/ui/RelativeTime.js.map +1 -1
  22. package/dist-lib/components/ui/Sidebar.d.ts +3 -1
  23. package/dist-lib/components/ui/Sidebar.js +97 -97
  24. package/dist-lib/components/ui/Sidebar.js.map +1 -1
  25. package/dist-lib/components/ui/Slider.js +28 -28
  26. package/dist-lib/components/ui/Slider.js.map +1 -1
  27. package/dist-lib/lib/strings.d.ts +4 -0
  28. package/dist-lib/lib/strings.js +3 -1
  29. package/dist-lib/lib/strings.js.map +1 -1
  30. package/dist-lib/lib/strings.mn.js +3 -1
  31. package/dist-lib/lib/strings.mn.js.map +1 -1
  32. package/dist-lib/styles.css +1 -1
  33. package/dist-lib/theme.css +25 -21
  34. package/package.json +1 -1
@@ -1,72 +1,72 @@
1
1
  "use client";
2
2
  import { jsxs as i, jsx as t } from "react/jsx-runtime";
3
- import { forwardRef as Y, useState as N, useRef as O, useCallback as k, useMemo as P } from "react";
3
+ import { forwardRef as Y, useState as N, useRef as P, useCallback as k, useMemo as j } from "react";
4
4
  import * as g from "@radix-ui/react-popover";
5
- import { Command as b } from "cmdk";
6
- import { X as j, ChevronsUpDown as Z, Check as _ } from "../../icons/index.js";
7
- import { cn as a } from "../../lib/utils.js";
5
+ import { Command as h } from "cmdk";
6
+ import { X as B, ChevronsUpDown as Z, Check as _ } from "../../icons/index.js";
7
+ import { cn as l } from "../../lib/utils.js";
8
8
  import { useStrings as ee } from "../../hooks/use-strings.js";
9
9
  import { formatString as te } from "../../lib/strings.js";
10
10
  import { useFieldIds as re } from "../../hooks/use-field-ids.js";
11
11
  const oe = Y(function({
12
- options: l,
12
+ options: d,
13
13
  value: r,
14
14
  onChange: n,
15
- label: d,
16
- helperText: h,
15
+ label: c,
16
+ helperText: b,
17
17
  error: x,
18
- placeholder: B,
18
+ placeholder: F,
19
19
  emptyText: L,
20
20
  maxVisibleChips: M = 3,
21
21
  clearable: E = !0,
22
- disabled: c,
22
+ disabled: a,
23
23
  id: S,
24
24
  className: K
25
25
  }, U) {
26
- const s = ee(), z = B ?? s.multiSelect.placeholder, $ = L ?? s.multiSelect.empty, v = !!x, { fieldId: u, helperId: q, errorId: H, describedBy: Q } = re(S, {
27
- hasHelper: !!h,
26
+ const s = ee(), z = F ?? s.multiSelect.placeholder, $ = L ?? s.multiSelect.empty, v = !!x, { fieldId: u, helperId: q, errorId: H, describedBy: Q } = re(S, {
27
+ hasHelper: !!b,
28
28
  hasError: v
29
- }), [f, m] = N(!1), [p, X] = N(""), C = O(null), I = O(null), [G, J] = N(void 0), T = k((e) => J(e == null ? void 0 : e.id), []), w = P(() => l.filter((e) => r.includes(e.value)), [l, r]), D = k(
29
+ }), [f, m] = N(!1), [p, X] = N(""), C = P(null), I = P(null), [G, J] = N(void 0), T = k((e) => J(e == null ? void 0 : e.id), []), w = j(() => d.filter((e) => r.includes(e.value)), [d, r]), D = k(
30
30
  (e) => {
31
31
  r.includes(e) ? n(r.filter((o) => o !== e)) : n([...r, e]);
32
32
  },
33
33
  [r, n]
34
34
  ), V = k(() => n([]), [n]), W = (e) => {
35
35
  e.key === "Backspace" && p === "" && r.length > 0 ? n(r.slice(0, -1)) : (e.key === "ArrowDown" || e.key === "ArrowUp") && !f && m(!0);
36
- }, R = P(
37
- () => l.filter((e) => e.label.toLowerCase().includes(p.toLowerCase())),
38
- [l, p]
36
+ }, R = j(
37
+ () => d.filter((e) => e.label.toLowerCase().includes(p.toLowerCase())),
38
+ [d, p]
39
39
  ), y = w.slice(0, M), A = w.length - y.length;
40
40
  return (
41
41
  // min-w-0: as a grid or flex child the trigger's chips would otherwise
42
42
  // set a min-content width and push the field past its column.
43
- /* @__PURE__ */ i("div", { ref: U, className: a("flex min-w-0 flex-col gap-1.5", K), children: [
44
- d && /* @__PURE__ */ t(
43
+ /* @__PURE__ */ i("div", { ref: U, className: l("flex min-w-0 flex-col gap-1.5", K), children: [
44
+ c && /* @__PURE__ */ t(
45
45
  "label",
46
46
  {
47
47
  id: `${u}-label`,
48
48
  htmlFor: u,
49
49
  className: "text-foreground text-sm font-medium",
50
- children: d
50
+ children: c
51
51
  }
52
52
  ),
53
- /* @__PURE__ */ t(b, { shouldFilter: !1, className: "flex w-full flex-col", children: /* @__PURE__ */ i(g.Root, { open: f, onOpenChange: m, children: [
53
+ /* @__PURE__ */ t(h, { shouldFilter: !1, className: "flex w-full flex-col", children: /* @__PURE__ */ i(g.Root, { open: f, onOpenChange: m, children: [
54
54
  /* @__PURE__ */ t(g.Anchor, { asChild: !0, children: /* @__PURE__ */ i(
55
55
  "div",
56
56
  {
57
57
  "data-slot": "multi-select",
58
58
  ref: I,
59
- "aria-disabled": c || void 0,
60
- className: a(
59
+ "aria-disabled": a || void 0,
60
+ className: l(
61
61
  "bg-card flex h-9 w-full cursor-text items-center gap-1.5 overflow-hidden rounded-md border px-2 py-1 text-sm",
62
62
  "transition-colors duration-[var(--duration-fast)] ease-[var(--ease-out)]",
63
63
  "focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2",
64
64
  v ? "border-danger focus-within:border-danger focus-within:ring-danger" : "border-border-input focus-within:border-accent focus-within:ring-ring",
65
- c && "pointer-events-none opacity-50"
65
+ a && "pointer-events-none opacity-50"
66
66
  ),
67
67
  onClick: () => {
68
68
  var e;
69
- (e = C.current) == null || e.focus(), c || m(!0);
69
+ (e = C.current) == null || e.focus(), a || m(!0);
70
70
  },
71
71
  children: [
72
72
  /* @__PURE__ */ i("div", { className: "flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden", children: [
@@ -85,7 +85,7 @@ const oe = Y(function({
85
85
  onClick: (o) => {
86
86
  o.stopPropagation(), D(e.value);
87
87
  },
88
- children: /* @__PURE__ */ t(j, { className: "size-3", "aria-hidden": !0 })
88
+ children: /* @__PURE__ */ t(B, { className: "size-3", "aria-hidden": !0 })
89
89
  }
90
90
  )
91
91
  ]
@@ -104,8 +104,9 @@ const oe = Y(function({
104
104
  type: "text",
105
105
  autoComplete: "off",
106
106
  value: p,
107
- onChange: (e) => X(e.target.value),
108
- onFocus: () => m(!0),
107
+ onChange: (e) => {
108
+ X(e.target.value), a || m(!0);
109
+ },
109
110
  onKeyDown: W,
110
111
  placeholder: y.length === 0 ? z : void 0,
111
112
  role: "combobox",
@@ -113,12 +114,12 @@ const oe = Y(function({
113
114
  "aria-controls": f ? G : void 0,
114
115
  "aria-haspopup": "listbox",
115
116
  "aria-autocomplete": "list",
116
- "aria-labelledby": d ? `${u}-label` : void 0,
117
- "aria-label": d || S ? void 0 : z,
117
+ "aria-labelledby": c ? `${u}-label` : void 0,
118
+ "aria-label": c || S ? void 0 : z,
118
119
  "aria-invalid": v || void 0,
119
120
  "aria-describedby": Q,
120
121
  className: "placeholder:text-foreground-subtle min-w-[6ch] flex-1 bg-transparent text-lg outline-hidden md:text-sm",
121
- disabled: c
122
+ disabled: a
122
123
  }
123
124
  )
124
125
  ] }),
@@ -132,7 +133,7 @@ const oe = Y(function({
132
133
  e.stopPropagation(), V();
133
134
  },
134
135
  className: "text-foreground-subtle hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background inline-flex size-6 shrink-0 items-center justify-center rounded-sm outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2",
135
- children: /* @__PURE__ */ t(j, { className: "size-4", "aria-hidden": !0 })
136
+ children: /* @__PURE__ */ t(B, { className: "size-4", "aria-hidden": !0 })
136
137
  }
137
138
  ),
138
139
  /* @__PURE__ */ t(Z, { className: "text-foreground-subtle size-4", "aria-hidden": !0 })
@@ -146,7 +147,7 @@ const oe = Y(function({
146
147
  align: "start",
147
148
  sideOffset: 4,
148
149
  "aria-label": s.command.suggestions,
149
- className: a(
150
+ className: l(
150
151
  "border-border bg-popover text-popover-foreground z-[var(--z-popover)] w-[var(--radix-popover-trigger-width)] overflow-hidden rounded-lg border shadow-md",
151
152
  "data-[state=open]:animate-in data-[state=closed]:animate-out",
152
153
  "data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
@@ -154,12 +155,12 @@ const oe = Y(function({
154
155
  ),
155
156
  onOpenAutoFocus: (e) => e.preventDefault(),
156
157
  onInteractOutside: (e) => {
157
- var F;
158
+ var O;
158
159
  const o = e.target;
159
- o && ((F = I.current) != null && F.contains(o)) && e.preventDefault();
160
+ o && ((O = I.current) != null && O.contains(o)) && e.preventDefault();
160
161
  },
161
162
  children: /* @__PURE__ */ i(
162
- b.List,
163
+ h.List,
163
164
  {
164
165
  ref: T,
165
166
  label: s.command.suggestions,
@@ -168,12 +169,12 @@ const oe = Y(function({
168
169
  R.map((e) => {
169
170
  const o = r.includes(e.value);
170
171
  return /* @__PURE__ */ i(
171
- b.Item,
172
+ h.Item,
172
173
  {
173
174
  value: e.value,
174
175
  disabled: e.disabled,
175
176
  onSelect: () => D(e.value),
176
- className: a(
177
+ className: l(
177
178
  "text-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm",
178
179
  "data-[selected=true]:bg-background-muted",
179
180
  "data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50"
@@ -183,7 +184,7 @@ const oe = Y(function({
183
184
  "span",
184
185
  {
185
186
  "aria-hidden": !0,
186
- className: a(
187
+ className: l(
187
188
  "flex size-4 items-center justify-center rounded-sm border",
188
189
  o ? "border-accent bg-accent text-on-accent" : "border-border-input"
189
190
  ),
@@ -197,14 +198,14 @@ const oe = Y(function({
197
198
  e.value
198
199
  );
199
200
  }),
200
- R.length === 0 && /* @__PURE__ */ t(b.Empty, { className: "text-foreground-subtle px-2 py-6 text-center text-sm", children: $ })
201
+ R.length === 0 && /* @__PURE__ */ t(h.Empty, { className: "text-foreground-subtle px-2 py-6 text-center text-sm", children: $ })
201
202
  ]
202
203
  }
203
204
  )
204
205
  }
205
206
  ) })
206
207
  ] }) }),
207
- x ? /* @__PURE__ */ t("p", { id: H, className: "text-danger-text text-xs", children: x }) : h ? /* @__PURE__ */ t("p", { id: q, className: "text-foreground-subtle text-xs", children: h }) : null
208
+ x ? /* @__PURE__ */ t("p", { id: H, className: "text-danger-text text-xs", children: x }) : b ? /* @__PURE__ */ t("p", { id: q, className: "text-foreground-subtle text-xs", children: b }) : null
208
209
  ] })
209
210
  );
210
211
  });
@@ -1 +1 @@
1
- {"version":3,"file":"MultiSelect.js","sources":["../../../src/components/ui/MultiSelect.tsx"],"sourcesContent":["'use client';\n\nimport {\n forwardRef,\n useCallback,\n useMemo,\n useRef,\n useState,\n type KeyboardEvent,\n type ReactNode,\n} from 'react';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { Command as CommandPrimitive } from 'cmdk';\nimport { Check, ChevronsUpDown, X } from '@/icons';\nimport { cn } from '@/lib/utils';\nimport { useStrings } from '@/hooks/use-strings';\nimport { formatString } from '@/lib/strings';\nimport { useFieldIds } from '@/hooks/use-field-ids';\n\nexport interface MultiSelectOption {\n /** Stable, unique value submitted in `onChange`. */\n value: string;\n /** Visible label shown both in the menu and in the selected chip. */\n label: string;\n /** Optional secondary text shown after the label in the menu. */\n description?: string;\n /** Disable selecting this option. */\n disabled?: boolean;\n}\n\nexport interface MultiSelectProps {\n /** All possible options. */\n options: MultiSelectOption[];\n /** Currently selected values. Controlled. */\n value: string[];\n /** Called whenever the selection changes. */\n onChange: (next: string[]) => void;\n /** Visible label above the field. */\n label?: ReactNode;\n /** Hint below the field. Hidden when `error` is set. */\n helperText?: ReactNode;\n /** Validation message. */\n error?: ReactNode;\n /** Empty-state placeholder shown when nothing is selected. */\n placeholder?: string;\n /** Text shown when no options match the search. */\n emptyText?: string;\n /** Max number of chips rendered inline; remainder shown as \"+N more\". */\n maxVisibleChips?: number;\n /** Whether the user can clear all selections with a single click. */\n clearable?: boolean;\n /** Disable the entire field. */\n disabled?: boolean;\n /** Consumer-supplied id for the search input (label association). */\n id?: string;\n className?: string;\n}\n\n/**\n * Chip-based multi-select with a searchable menu (cmdk under the hood).\n *\n * Keyboard:\n * - Backspace on the input with empty query removes the last chip\n * - ArrowUp / ArrowDown move the highlight, Enter toggles the highlighted option\n * - Escape closes the menu\n *\n * @example Tag picker\n * <MultiSelect label=\"Tags\"\n * options={tags}\n * value={selected}\n * onChange={setSelected}\n * placeholder=\"Pick tags\" />\n *\n * @example Bounded with overflow chip\n * <MultiSelect options={users}\n * value={value}\n * onChange={setValue}\n * maxVisibleChips={3} />\n *\n * @do Cap `maxVisibleChips` (3–5) on narrow surfaces so the field doesn't\n * reflow as the user adds selections.\n * @dont Use MultiSelect for fewer than ~6 options. CheckboxGroup is clearer.\n */\nexport const MultiSelect = forwardRef<HTMLDivElement, MultiSelectProps>(function MultiSelect(\n {\n options,\n value,\n onChange,\n label,\n helperText,\n error,\n placeholder: placeholderProp,\n emptyText: emptyTextProp,\n maxVisibleChips = 3,\n clearable = true,\n disabled,\n id,\n className,\n },\n ref,\n) {\n const strings = useStrings();\n const placeholder = placeholderProp ?? strings.multiSelect.placeholder;\n const emptyText = emptyTextProp ?? strings.multiSelect.empty;\n const isError = Boolean(error);\n const { fieldId, helperId, errorId, describedBy } = useFieldIds(id, {\n hasHelper: Boolean(helperText),\n hasError: isError,\n });\n\n const [open, setOpen] = useState(false);\n const [query, setQuery] = useState('');\n const inputRef = useRef<HTMLInputElement>(null);\n const fieldRef = useRef<HTMLDivElement>(null);\n // cmdk assigns its own id to the list (ours is ignored), so read it back\n // from the node once the portal mounts to keep aria-controls truthful.\n const [listId, setListId] = useState<string | undefined>(undefined);\n const listRef = useCallback((el: HTMLDivElement | null) => setListId(el?.id), []);\n\n const selected = useMemo(() => options.filter((o) => value.includes(o.value)), [options, value]);\n\n const toggle = useCallback(\n (v: string) => {\n if (value.includes(v)) onChange(value.filter((x) => x !== v));\n else onChange([...value, v]);\n },\n [value, onChange],\n );\n\n const clear = useCallback(() => onChange([]), [onChange]);\n\n const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === 'Backspace' && query === '' && value.length > 0) {\n onChange(value.slice(0, -1));\n } else if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && !open) {\n setOpen(true);\n }\n };\n\n const filtered = useMemo(\n () => options.filter((o) => o.label.toLowerCase().includes(query.toLowerCase())),\n [options, query],\n );\n\n const visibleChips = selected.slice(0, maxVisibleChips);\n const overflow = selected.length - visibleChips.length;\n\n return (\n // min-w-0: as a grid or flex child the trigger's chips would otherwise\n // set a min-content width and push the field past its column.\n <div ref={ref} className={cn('flex min-w-0 flex-col gap-1.5', className)}>\n {label && (\n <label\n id={`${fieldId}-label`}\n htmlFor={fieldId}\n className=\"text-foreground text-sm font-medium\"\n >\n {label}\n </label>\n )}\n\n {/* The Command root wraps the whole field so cmdk's root keydown handler\n (ArrowUp/Down/Enter) sees the input even though the list is portaled.\n A plain <input> is used instead of Command.Input because cmdk forces\n its own id / aria-* on that element, breaking the label association. */}\n <CommandPrimitive shouldFilter={false} className=\"flex w-full flex-col\">\n <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>\n <PopoverPrimitive.Anchor asChild>\n {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions -- click-to-focus wrapper; the <input role=\"combobox\"> inside owns keyboard handling */}\n <div\n data-slot=\"multi-select\"\n ref={fieldRef}\n aria-disabled={disabled || undefined}\n className={cn(\n 'bg-card flex h-9 w-full cursor-text items-center gap-1.5 overflow-hidden rounded-md border px-2 py-1 text-sm',\n 'transition-colors duration-[var(--duration-fast)] ease-[var(--ease-out)]',\n 'focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2',\n isError\n ? 'border-danger focus-within:border-danger focus-within:ring-danger'\n : 'border-border-input focus-within:border-accent focus-within:ring-ring',\n disabled && 'pointer-events-none opacity-50',\n )}\n onClick={() => {\n inputRef.current?.focus();\n if (!disabled) setOpen(true);\n }}\n >\n <div className=\"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden\">\n {visibleChips.map((opt) => (\n <span\n key={opt.value}\n className=\"bg-accent-soft text-on-accent-soft inline-flex max-w-[10rem] shrink-0 items-center gap-1 rounded-md px-1.5 py-0.5 text-xs font-medium\"\n >\n <span className=\"truncate\" title={opt.label}>\n {opt.label}\n </span>\n <button\n type=\"button\"\n aria-label={formatString(strings.multiSelect.remove, { label: opt.label })}\n className=\"text-on-accent-soft hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background relative inline-flex items-center rounded-sm outline-hidden before:absolute before:-inset-1.5 before:content-[''] focus-visible:ring-2 focus-visible:ring-offset-1\"\n onClick={(e) => {\n e.stopPropagation();\n toggle(opt.value);\n }}\n >\n <X className=\"size-3\" aria-hidden />\n </button>\n </span>\n ))}\n {overflow > 0 && (\n <span className=\"bg-background-muted text-foreground-muted shrink-0 rounded-md px-1.5 py-0.5 text-xs font-medium\">\n +{overflow}\n </span>\n )}\n <input\n ref={inputRef}\n id={fieldId}\n type=\"text\"\n autoComplete=\"off\"\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n onFocus={() => setOpen(true)}\n onKeyDown={handleKeyDown}\n placeholder={visibleChips.length === 0 ? placeholder : undefined}\n role=\"combobox\"\n aria-expanded={open}\n aria-controls={open ? listId : undefined}\n aria-haspopup=\"listbox\"\n aria-autocomplete=\"list\"\n // Unlabelled field: name the input after the placeholder. A\n // consumer `id` implies an external <label htmlFor>.\n aria-labelledby={label ? `${fieldId}-label` : undefined}\n aria-label={label || id ? undefined : placeholder}\n aria-invalid={isError || undefined}\n aria-describedby={describedBy}\n className=\"placeholder:text-foreground-subtle min-w-[6ch] flex-1 bg-transparent text-lg outline-hidden md:text-sm\"\n disabled={disabled}\n />\n </div>\n <span className=\"flex shrink-0 items-center gap-1 pl-1\">\n {clearable && selected.length > 0 && (\n <button\n type=\"button\"\n aria-label={strings.multiSelect.clearAll}\n onClick={(e) => {\n e.stopPropagation();\n clear();\n }}\n className=\"text-foreground-subtle hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background inline-flex size-6 shrink-0 items-center justify-center rounded-sm outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2\"\n >\n <X className=\"size-4\" aria-hidden />\n </button>\n )}\n <ChevronsUpDown className=\"text-foreground-subtle size-4\" aria-hidden />\n </span>\n </div>\n </PopoverPrimitive.Anchor>\n\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n align=\"start\"\n sideOffset={4}\n // Radix gives the content role=\"dialog\"; a dialog needs a name.\n aria-label={strings.command.suggestions}\n className={cn(\n 'border-border bg-popover text-popover-foreground z-[var(--z-popover)] w-[var(--radix-popover-trigger-width)] overflow-hidden rounded-lg border shadow-md',\n 'data-[state=open]:animate-in data-[state=closed]:animate-out',\n 'data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',\n 'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',\n )}\n onOpenAutoFocus={(e) => e.preventDefault()}\n onInteractOutside={(e) => {\n // Clicks inside the anchor (chips, clear) must not close the menu.\n const target = e.target as Node | null;\n if (target && fieldRef.current?.contains(target)) e.preventDefault();\n }}\n >\n <CommandPrimitive.List\n ref={listRef}\n label={strings.command.suggestions}\n className=\"max-h-64 overflow-y-auto p-1\"\n >\n {filtered.map((opt) => {\n const isSelected = value.includes(opt.value);\n return (\n <CommandPrimitive.Item\n key={opt.value}\n value={opt.value}\n disabled={opt.disabled}\n onSelect={() => toggle(opt.value)}\n className={cn(\n 'text-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm',\n 'data-[selected=true]:bg-background-muted',\n 'data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50',\n )}\n >\n <span\n aria-hidden\n className={cn(\n 'flex size-4 items-center justify-center rounded-sm border',\n isSelected\n ? 'border-accent bg-accent text-on-accent'\n : 'border-border-input',\n )}\n >\n {isSelected && <Check className=\"size-3\" aria-hidden />}\n </span>\n <span className=\"flex-1\">{opt.label}</span>\n {opt.description && (\n <span className=\"text-foreground-subtle text-xs\">{opt.description}</span>\n )}\n </CommandPrimitive.Item>\n );\n })}\n {filtered.length === 0 && (\n <CommandPrimitive.Empty className=\"text-foreground-subtle px-2 py-6 text-center text-sm\">\n {emptyText}\n </CommandPrimitive.Empty>\n )}\n </CommandPrimitive.List>\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n </CommandPrimitive>\n\n {error ? (\n <p id={errorId} className=\"text-danger-text text-xs\">\n {error}\n </p>\n ) : helperText ? (\n <p id={helperId} className=\"text-foreground-subtle text-xs\">\n {helperText}\n </p>\n ) : null}\n </div>\n );\n});\n\nMultiSelect.displayName = 'MultiSelect';\n"],"names":["MultiSelect","forwardRef","options","value","onChange","label","helperText","error","placeholderProp","emptyTextProp","maxVisibleChips","clearable","disabled","id","className","ref","strings","useStrings","placeholder","emptyText","isError","fieldId","helperId","errorId","describedBy","useFieldIds","open","setOpen","useState","query","setQuery","inputRef","useRef","fieldRef","listId","setListId","listRef","useCallback","el","selected","useMemo","o","toggle","v","x","clear","handleKeyDown","filtered","visibleChips","overflow","cn","jsx","CommandPrimitive","jsxs","PopoverPrimitive","_a","opt","formatString","e","X","ChevronsUpDown","target","isSelected","Check"],"mappings":";;;;;;;;;;AAmFO,MAAMA,KAAcC,EAA6C,SACtE;AAAA,EACE,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,YAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAaC;AAAA,EACb,WAAWC;AAAA,EACX,iBAAAC,IAAkB;AAAA,EAClB,WAAAC,IAAY;AAAA,EACZ,UAAAC;AAAA,EACA,IAAAC;AAAA,EACA,WAAAC;AACF,GACAC,GACA;AACA,QAAMC,IAAUC,GAAA,GACVC,IAAcV,KAAmBQ,EAAQ,YAAY,aACrDG,IAAYV,KAAiBO,EAAQ,YAAY,OACjDI,IAAU,EAAQb,GAClB,EAAE,SAAAc,GAAS,UAAAC,GAAU,SAAAC,GAAS,aAAAC,EAAA,IAAgBC,GAAYZ,GAAI;AAAA,IAClE,WAAW,EAAQP;AAAA,IACnB,UAAUc;AAAA,EAAA,CACX,GAEK,CAACM,GAAMC,CAAO,IAAIC,EAAS,EAAK,GAChC,CAACC,GAAOC,CAAQ,IAAIF,EAAS,EAAE,GAC/BG,IAAWC,EAAyB,IAAI,GACxCC,IAAWD,EAAuB,IAAI,GAGtC,CAACE,GAAQC,CAAS,IAAIP,EAA6B,MAAS,GAC5DQ,IAAUC,EAAY,CAACC,MAA8BH,EAAUG,KAAA,gBAAAA,EAAI,EAAE,GAAG,EAAE,GAE1EC,IAAWC,EAAQ,MAAMtC,EAAQ,OAAO,CAACuC,MAAMtC,EAAM,SAASsC,EAAE,KAAK,CAAC,GAAG,CAACvC,GAASC,CAAK,CAAC,GAEzFuC,IAASL;AAAA,IACb,CAACM,MAAc;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AW,KACnB,gBAAAI,EAACC,EAAiB,OAAjB,EAAuB,WAAU,wDAC/B,UAAAjC,EAAA,CACH;AAAA,gBAAA;AAAA,cAAA;AAAA,YAAA;AAAA,UAEJ;AAAA,QAAA,EACF,CACF;AAAA,MAAA,EAAA,CACF,EAAA,CACF;AAAA,MAECZ,IACC,gBAAA4C,EAAC,KAAA,EAAE,IAAI5B,GAAS,WAAU,4BACvB,UAAAhB,EAAA,CACH,IACED,sBACD,KAAA,EAAE,IAAIgB,GAAU,WAAU,kCACxB,aACH,IACE;AAAA,IAAA,EAAA,CACN;AAAA;AAEJ,CAAC;AAEDtB,GAAY,cAAc;"}
1
+ {"version":3,"file":"MultiSelect.js","sources":["../../../src/components/ui/MultiSelect.tsx"],"sourcesContent":["'use client';\n\nimport {\n forwardRef,\n useCallback,\n useMemo,\n useRef,\n useState,\n type KeyboardEvent,\n type ReactNode,\n} from 'react';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { Command as CommandPrimitive } from 'cmdk';\nimport { Check, ChevronsUpDown, X } from '@/icons';\nimport { cn } from '@/lib/utils';\nimport { useStrings } from '@/hooks/use-strings';\nimport { formatString } from '@/lib/strings';\nimport { useFieldIds } from '@/hooks/use-field-ids';\n\nexport interface MultiSelectOption {\n /** Stable, unique value submitted in `onChange`. */\n value: string;\n /** Visible label shown both in the menu and in the selected chip. */\n label: string;\n /** Optional secondary text shown after the label in the menu. */\n description?: string;\n /** Disable selecting this option. */\n disabled?: boolean;\n}\n\nexport interface MultiSelectProps {\n /** All possible options. */\n options: MultiSelectOption[];\n /** Currently selected values. Controlled. */\n value: string[];\n /** Called whenever the selection changes. */\n onChange: (next: string[]) => void;\n /** Visible label above the field. */\n label?: ReactNode;\n /** Hint below the field. Hidden when `error` is set. */\n helperText?: ReactNode;\n /** Validation message. */\n error?: ReactNode;\n /** Empty-state placeholder shown when nothing is selected. */\n placeholder?: string;\n /** Text shown when no options match the search. */\n emptyText?: string;\n /** Max number of chips rendered inline; remainder shown as \"+N more\". */\n maxVisibleChips?: number;\n /** Whether the user can clear all selections with a single click. */\n clearable?: boolean;\n /** Disable the entire field. */\n disabled?: boolean;\n /** Consumer-supplied id for the search input (label association). */\n id?: string;\n className?: string;\n}\n\n/**\n * Chip-based multi-select with a searchable menu (cmdk under the hood).\n *\n * Keyboard:\n * - Backspace on the input with empty query removes the last chip\n * - ArrowUp / ArrowDown move the highlight, Enter toggles the highlighted option\n * - Escape closes the menu\n *\n * @example Tag picker\n * <MultiSelect label=\"Tags\"\n * options={tags}\n * value={selected}\n * onChange={setSelected}\n * placeholder=\"Pick tags\" />\n *\n * @example Bounded with overflow chip\n * <MultiSelect options={users}\n * value={value}\n * onChange={setValue}\n * maxVisibleChips={3} />\n *\n * @do Cap `maxVisibleChips` (3–5) on narrow surfaces so the field doesn't\n * reflow as the user adds selections.\n * @dont Use MultiSelect for fewer than ~6 options. CheckboxGroup is clearer.\n */\nexport const MultiSelect = forwardRef<HTMLDivElement, MultiSelectProps>(function MultiSelect(\n {\n options,\n value,\n onChange,\n label,\n helperText,\n error,\n placeholder: placeholderProp,\n emptyText: emptyTextProp,\n maxVisibleChips = 3,\n clearable = true,\n disabled,\n id,\n className,\n },\n ref,\n) {\n const strings = useStrings();\n const placeholder = placeholderProp ?? strings.multiSelect.placeholder;\n const emptyText = emptyTextProp ?? strings.multiSelect.empty;\n const isError = Boolean(error);\n const { fieldId, helperId, errorId, describedBy } = useFieldIds(id, {\n hasHelper: Boolean(helperText),\n hasError: isError,\n });\n\n const [open, setOpen] = useState(false);\n const [query, setQuery] = useState('');\n const inputRef = useRef<HTMLInputElement>(null);\n const fieldRef = useRef<HTMLDivElement>(null);\n // cmdk assigns its own id to the list (ours is ignored), so read it back\n // from the node once the portal mounts to keep aria-controls truthful.\n const [listId, setListId] = useState<string | undefined>(undefined);\n const listRef = useCallback((el: HTMLDivElement | null) => setListId(el?.id), []);\n\n const selected = useMemo(() => options.filter((o) => value.includes(o.value)), [options, value]);\n\n const toggle = useCallback(\n (v: string) => {\n if (value.includes(v)) onChange(value.filter((x) => x !== v));\n else onChange([...value, v]);\n },\n [value, onChange],\n );\n\n const clear = useCallback(() => onChange([]), [onChange]);\n\n const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === 'Backspace' && query === '' && value.length > 0) {\n onChange(value.slice(0, -1));\n } else if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && !open) {\n setOpen(true);\n }\n };\n\n const filtered = useMemo(\n () => options.filter((o) => o.label.toLowerCase().includes(query.toLowerCase())),\n [options, query],\n );\n\n const visibleChips = selected.slice(0, maxVisibleChips);\n const overflow = selected.length - visibleChips.length;\n\n return (\n // min-w-0: as a grid or flex child the trigger's chips would otherwise\n // set a min-content width and push the field past its column.\n <div ref={ref} className={cn('flex min-w-0 flex-col gap-1.5', className)}>\n {label && (\n <label\n id={`${fieldId}-label`}\n htmlFor={fieldId}\n className=\"text-foreground text-sm font-medium\"\n >\n {label}\n </label>\n )}\n\n {/* The Command root wraps the whole field so cmdk's root keydown handler\n (ArrowUp/Down/Enter) sees the input even though the list is portaled.\n A plain <input> is used instead of Command.Input because cmdk forces\n its own id / aria-* on that element, breaking the label association. */}\n <CommandPrimitive shouldFilter={false} className=\"flex w-full flex-col\">\n <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>\n <PopoverPrimitive.Anchor asChild>\n {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions -- click-to-focus wrapper; the <input role=\"combobox\"> inside owns keyboard handling */}\n <div\n data-slot=\"multi-select\"\n ref={fieldRef}\n aria-disabled={disabled || undefined}\n className={cn(\n 'bg-card flex h-9 w-full cursor-text items-center gap-1.5 overflow-hidden rounded-md border px-2 py-1 text-sm',\n 'transition-colors duration-[var(--duration-fast)] ease-[var(--ease-out)]',\n 'focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2',\n isError\n ? 'border-danger focus-within:border-danger focus-within:ring-danger'\n : 'border-border-input focus-within:border-accent focus-within:ring-ring',\n disabled && 'pointer-events-none opacity-50',\n )}\n onClick={() => {\n inputRef.current?.focus();\n if (!disabled) setOpen(true);\n }}\n >\n <div className=\"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden\">\n {visibleChips.map((opt) => (\n <span\n key={opt.value}\n className=\"bg-accent-soft text-on-accent-soft inline-flex max-w-[10rem] shrink-0 items-center gap-1 rounded-md px-1.5 py-0.5 text-xs font-medium\"\n >\n <span className=\"truncate\" title={opt.label}>\n {opt.label}\n </span>\n <button\n type=\"button\"\n aria-label={formatString(strings.multiSelect.remove, { label: opt.label })}\n className=\"text-on-accent-soft hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background relative inline-flex items-center rounded-sm outline-hidden before:absolute before:-inset-1.5 before:content-[''] focus-visible:ring-2 focus-visible:ring-offset-1\"\n onClick={(e) => {\n e.stopPropagation();\n toggle(opt.value);\n }}\n >\n <X className=\"size-3\" aria-hidden />\n </button>\n </span>\n ))}\n {overflow > 0 && (\n <span className=\"bg-background-muted text-foreground-muted shrink-0 rounded-md px-1.5 py-0.5 text-xs font-medium\">\n +{overflow}\n </span>\n )}\n <input\n ref={inputRef}\n id={fieldId}\n type=\"text\"\n autoComplete=\"off\"\n value={query}\n // Typing opens the list; focus alone does not, so tabbing\n // through a form never pops a listbox on every pass.\n onChange={(e) => {\n setQuery(e.target.value);\n if (!disabled) setOpen(true);\n }}\n onKeyDown={handleKeyDown}\n placeholder={visibleChips.length === 0 ? placeholder : undefined}\n role=\"combobox\"\n aria-expanded={open}\n aria-controls={open ? listId : undefined}\n aria-haspopup=\"listbox\"\n aria-autocomplete=\"list\"\n // Unlabelled field: name the input after the placeholder. A\n // consumer `id` implies an external <label htmlFor>.\n aria-labelledby={label ? `${fieldId}-label` : undefined}\n aria-label={label || id ? undefined : placeholder}\n aria-invalid={isError || undefined}\n aria-describedby={describedBy}\n className=\"placeholder:text-foreground-subtle min-w-[6ch] flex-1 bg-transparent text-lg outline-hidden md:text-sm\"\n disabled={disabled}\n />\n </div>\n <span className=\"flex shrink-0 items-center gap-1 pl-1\">\n {clearable && selected.length > 0 && (\n <button\n type=\"button\"\n aria-label={strings.multiSelect.clearAll}\n onClick={(e) => {\n e.stopPropagation();\n clear();\n }}\n className=\"text-foreground-subtle hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background inline-flex size-6 shrink-0 items-center justify-center rounded-sm outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2\"\n >\n <X className=\"size-4\" aria-hidden />\n </button>\n )}\n <ChevronsUpDown className=\"text-foreground-subtle size-4\" aria-hidden />\n </span>\n </div>\n </PopoverPrimitive.Anchor>\n\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n align=\"start\"\n sideOffset={4}\n // Radix gives the content role=\"dialog\"; a dialog needs a name.\n aria-label={strings.command.suggestions}\n className={cn(\n 'border-border bg-popover text-popover-foreground z-[var(--z-popover)] w-[var(--radix-popover-trigger-width)] overflow-hidden rounded-lg border shadow-md',\n 'data-[state=open]:animate-in data-[state=closed]:animate-out',\n 'data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',\n 'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',\n )}\n onOpenAutoFocus={(e) => e.preventDefault()}\n onInteractOutside={(e) => {\n // Clicks inside the anchor (chips, clear) must not close the menu.\n const target = e.target as Node | null;\n if (target && fieldRef.current?.contains(target)) e.preventDefault();\n }}\n >\n <CommandPrimitive.List\n ref={listRef}\n label={strings.command.suggestions}\n className=\"max-h-64 overflow-y-auto p-1\"\n >\n {filtered.map((opt) => {\n const isSelected = value.includes(opt.value);\n return (\n <CommandPrimitive.Item\n key={opt.value}\n value={opt.value}\n disabled={opt.disabled}\n onSelect={() => toggle(opt.value)}\n className={cn(\n 'text-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm',\n 'data-[selected=true]:bg-background-muted',\n 'data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50',\n )}\n >\n <span\n aria-hidden\n className={cn(\n 'flex size-4 items-center justify-center rounded-sm border',\n isSelected\n ? 'border-accent bg-accent text-on-accent'\n : 'border-border-input',\n )}\n >\n {isSelected && <Check className=\"size-3\" aria-hidden />}\n </span>\n <span className=\"flex-1\">{opt.label}</span>\n {opt.description && (\n <span className=\"text-foreground-subtle text-xs\">{opt.description}</span>\n )}\n </CommandPrimitive.Item>\n );\n })}\n {filtered.length === 0 && (\n <CommandPrimitive.Empty className=\"text-foreground-subtle px-2 py-6 text-center text-sm\">\n {emptyText}\n </CommandPrimitive.Empty>\n )}\n </CommandPrimitive.List>\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n </CommandPrimitive>\n\n {error ? (\n <p id={errorId} className=\"text-danger-text text-xs\">\n {error}\n </p>\n ) : helperText ? (\n <p id={helperId} className=\"text-foreground-subtle text-xs\">\n {helperText}\n </p>\n ) : null}\n </div>\n );\n});\n\nMultiSelect.displayName = 'MultiSelect';\n"],"names":["MultiSelect","forwardRef","options","value","onChange","label","helperText","error","placeholderProp","emptyTextProp","maxVisibleChips","clearable","disabled","id","className","ref","strings","useStrings","placeholder","emptyText","isError","fieldId","helperId","errorId","describedBy","useFieldIds","open","setOpen","useState","query","setQuery","inputRef","useRef","fieldRef","listId","setListId","listRef","useCallback","el","selected","useMemo","o","toggle","v","x","clear","handleKeyDown","filtered","visibleChips","overflow","cn","jsx","CommandPrimitive","jsxs","PopoverPrimitive","_a","opt","formatString","e","X","ChevronsUpDown","target","isSelected","Check"],"mappings":";;;;;;;;;;AAmFO,MAAMA,KAAcC,EAA6C,SACtE;AAAA,EACE,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,YAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAaC;AAAA,EACb,WAAWC;AAAA,EACX,iBAAAC,IAAkB;AAAA,EAClB,WAAAC,IAAY;AAAA,EACZ,UAAAC;AAAA,EACA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ps extends Omit<TimeHTMLAttributes<HTMLTimeElement>, 'dateTime'> {
4
4
  /** The instant to describe. */
5
5
  date: Date | number | string;
6
- /** Reference "now". Default `Date.now()` at render — pass one for stable SSR/tests. */
6
+ /**
7
+ * Reference "now". Omitted: the current minute, re-read every minute so the
8
+ * label does not go stale ("1 min ago" stays true). Pass a fixed value for
9
+ * deterministic SSR and tests.
10
+ */
7
11
  now?: Date | number;
8
12
  /** Options for the absolute `title` (tooltip). */
9
13
  absolute?: FormatDateOptions;
@@ -1,32 +1,36 @@
1
1
  "use client";
2
- import { jsx as D } from "react/jsx-runtime";
3
- import { forwardRef as N } from "react";
4
- import { formatDate as h } from "../../lib/format.js";
5
- import { formatString as a } from "../../lib/strings.js";
6
- import { useStrings as M } from "../../hooks/use-strings.js";
7
- import { cn as b } from "../../lib/utils.js";
8
- const f = 6e4, l = 60 * f, m = 24 * l, R = N(function({ date: n, now: o, absolute: d, className: g, ...p }, T) {
9
- const t = M().relativeTime, s = n instanceof Date ? n : new Date(n), v = o === void 0 ? Date.now() : o instanceof Date ? o.getTime() : o, c = s.getTime() - v, e = Math.abs(c), r = c > 0, u = h(s, d);
2
+ import { jsx as b } from "react/jsx-runtime";
3
+ import { forwardRef as R, useSyncExternalStore as y } from "react";
4
+ import { formatDate as A } from "../../lib/format.js";
5
+ import { formatString as f } from "../../lib/strings.js";
6
+ import { useStrings as I } from "../../hooks/use-strings.js";
7
+ import { cn as x } from "../../lib/utils.js";
8
+ const r = 6e4, d = 60 * r, u = 24 * d, a = /* @__PURE__ */ new Set();
9
+ let m;
10
+ const j = (c) => (a.add(c), m ?? (m = setInterval(() => a.forEach((o) => o()), 3e4)), () => {
11
+ a.delete(c), a.size === 0 && m !== void 0 && (clearInterval(m), m = void 0);
12
+ }), h = () => Math.floor(Date.now() / r) * r, w = R(function({ date: o, now: n, absolute: p, className: M, ...T }, D) {
13
+ const e = I().relativeTime, s = o instanceof Date ? o : new Date(o), N = y(j, h, h), S = n === void 0 ? N : n instanceof Date ? n.getTime() : n, v = s.getTime() - S, t = Math.abs(v), l = v > 0, g = A(s, p);
10
14
  let i;
11
- return e < f ? i = t.justNow : e < l ? i = a(r ? t.inMinutes : t.minutesAgo, {
12
- n: Math.round(e / f)
13
- }) : e < m ? i = a(r ? t.inHours : t.hoursAgo, {
14
- n: Math.round(e / l)
15
- }) : e < 30 * m ? i = a(r ? t.inDays : t.daysAgo, { n: Math.round(e / m) }) : i = u, /* @__PURE__ */ D(
15
+ return t < r ? i = e.justNow : t < d ? i = f(l ? e.inMinutes : e.minutesAgo, {
16
+ n: Math.round(t / r)
17
+ }) : t < u ? i = f(l ? e.inHours : e.hoursAgo, {
18
+ n: Math.round(t / d)
19
+ }) : t < 30 * u ? i = f(l ? e.inDays : e.daysAgo, { n: Math.round(t / u) }) : i = g, /* @__PURE__ */ b(
16
20
  "time",
17
21
  {
18
22
  "data-slot": "relative-time",
19
- ref: T,
23
+ ref: D,
20
24
  dateTime: Number.isNaN(s.getTime()) ? void 0 : s.toISOString(),
21
- title: u,
22
- className: b("tabular", g),
23
- ...p,
25
+ title: g,
26
+ className: x("tabular", M),
27
+ ...T,
24
28
  children: i
25
29
  }
26
30
  );
27
31
  });
28
- R.displayName = "RelativeTime";
32
+ w.displayName = "RelativeTime";
29
33
  export {
30
- R as RelativeTime
34
+ w as RelativeTime
31
35
  };
32
36
  //# sourceMappingURL=RelativeTime.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RelativeTime.js","sources":["../../../src/components/ui/RelativeTime.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef, type TimeHTMLAttributes } from 'react';\nimport { formatDate, type FormatDateOptions } from '@/lib/format';\nimport { formatString } from '@/lib/strings';\nimport { useStrings } from '@/hooks/use-strings';\nimport { cn } from '@/lib/utils';\n\nexport interface RelativeTimeProps extends Omit<TimeHTMLAttributes<HTMLTimeElement>, 'dateTime'> {\n /** The instant to describe. */\n date: Date | number | string;\n /** Reference \"now\". Default `Date.now()` at render — pass one for stable SSR/tests. */\n now?: Date | number;\n /** Options for the absolute `title` (tooltip). */\n absolute?: FormatDateOptions;\n}\n\nconst MIN = 60_000;\nconst HOUR = 60 * MIN;\nconst DAY = 24 * HOUR;\n\n/**\n * `<time>` showing \"5 min ago\" with the absolute timestamp as `title` and a\n * machine-readable `dateTime`. Strings come from `UiStrings.relativeTime`.\n * Beyond 30 days it falls back to the absolute date so text never goes stale.\n *\n * @example\n * <RelativeTime date={post.createdAt} />\n */\nexport const RelativeTime = forwardRef<HTMLTimeElement, RelativeTimeProps>(function RelativeTime(\n { date, now, absolute, className, ...props },\n ref,\n) {\n const strings = useStrings().relativeTime;\n const d = date instanceof Date ? date : new Date(date);\n const ref_ = now === undefined ? Date.now() : now instanceof Date ? now.getTime() : now;\n const diff = d.getTime() - ref_;\n const abs = Math.abs(diff);\n const future = diff > 0;\n const title = formatDate(d, absolute);\n\n let label: string;\n if (abs < MIN) label = strings.justNow;\n else if (abs < HOUR)\n label = formatString(future ? strings.inMinutes : strings.minutesAgo, {\n n: Math.round(abs / MIN),\n });\n else if (abs < DAY)\n label = formatString(future ? strings.inHours : strings.hoursAgo, {\n n: Math.round(abs / HOUR),\n });\n else if (abs < 30 * DAY)\n label = formatString(future ? strings.inDays : strings.daysAgo, { n: Math.round(abs / DAY) });\n else label = title;\n\n return (\n <time\n data-slot=\"relative-time\"\n ref={ref}\n dateTime={Number.isNaN(d.getTime()) ? undefined : d.toISOString()}\n title={title}\n className={cn('tabular', className)}\n {...props}\n >\n {label}\n </time>\n );\n});\nRelativeTime.displayName = 'RelativeTime';\n"],"names":["MIN","HOUR","DAY","RelativeTime","forwardRef","date","now","absolute","className","props","ref","strings","useStrings","d","ref_","diff","abs","future","title","formatDate","label","formatString","jsx","cn"],"mappings":";;;;;;;AAiBA,MAAMA,IAAM,KACNC,IAAO,KAAKD,GACZE,IAAM,KAAKD,GAUJE,IAAeC,EAA+C,SACzE,EAAE,MAAAC,GAAM,KAAAC,GAAK,UAAAC,GAAU,WAAAC,GAAW,GAAGC,EAAA,GACrCC,GACA;AACA,QAAMC,IAAUC,IAAa,cACvBC,IAAIR,aAAgB,OAAOA,IAAO,IAAI,KAAKA,CAAI,GAC/CS,IAAOR,MAAQ,SAAY,KAAK,QAAQA,aAAe,OAAOA,EAAI,QAAA,IAAYA,GAC9ES,IAAOF,EAAE,QAAA,IAAYC,GACrBE,IAAM,KAAK,IAAID,CAAI,GACnBE,IAASF,IAAO,GAChBG,IAAQC,EAAWN,GAAGN,CAAQ;AAEpC,MAAIa;AACJ,SAAIJ,IAAMhB,IAAKoB,IAAQT,EAAQ,UACtBK,IAAMf,IACbmB,IAAQC,EAAaJ,IAASN,EAAQ,YAAYA,EAAQ,YAAY;AAAA,IACpE,GAAG,KAAK,MAAMK,IAAMhB,CAAG;AAAA,EAAA,CACxB,IACMgB,IAAMd,IACbkB,IAAQC,EAAaJ,IAASN,EAAQ,UAAUA,EAAQ,UAAU;AAAA,IAChE,GAAG,KAAK,MAAMK,IAAMf,CAAI;AAAA,EAAA,CACzB,IACMe,IAAM,KAAKd,IAClBkB,IAAQC,EAAaJ,IAASN,EAAQ,SAASA,EAAQ,SAAS,EAAE,GAAG,KAAK,MAAMK,IAAMd,CAAG,GAAG,IACzFkB,IAAQF,GAGX,gBAAAI;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,aAAU;AAAA,MACV,KAAAZ;AAAA,MACA,UAAU,OAAO,MAAMG,EAAE,SAAS,IAAI,SAAYA,EAAE,YAAA;AAAA,MACpD,OAAAK;AAAA,MACA,WAAWK,EAAG,WAAWf,CAAS;AAAA,MACjC,GAAGC;AAAA,MAEH,UAAAW;AAAA,IAAA;AAAA,EAAA;AAGP,CAAC;AACDjB,EAAa,cAAc;"}
1
+ {"version":3,"file":"RelativeTime.js","sources":["../../../src/components/ui/RelativeTime.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef, useSyncExternalStore, type TimeHTMLAttributes } from 'react';\nimport { formatDate, type FormatDateOptions } from '@/lib/format';\nimport { formatString } from '@/lib/strings';\nimport { useStrings } from '@/hooks/use-strings';\nimport { cn } from '@/lib/utils';\n\nexport interface RelativeTimeProps extends Omit<TimeHTMLAttributes<HTMLTimeElement>, 'dateTime'> {\n /** The instant to describe. */\n date: Date | number | string;\n /**\n * Reference \"now\". Omitted: the current minute, re-read every minute so the\n * label does not go stale (\"1 min ago\" stays true). Pass a fixed value for\n * deterministic SSR and tests.\n */\n now?: Date | number;\n /** Options for the absolute `title` (tooltip). */\n absolute?: FormatDateOptions;\n}\n\nconst MIN = 60_000;\nconst HOUR = 60 * MIN;\nconst DAY = 24 * HOUR;\n\n/**\n * One shared minute ticker for every mounted RelativeTime. The snapshot is the\n * current minute (not the millisecond) so it is referentially stable between\n * renders, and so server and client agree unless a minute boundary falls\n * between the two — the same granularity the label itself has.\n */\nconst listeners = new Set<() => void>();\nlet timer: ReturnType<typeof setInterval> | undefined;\nconst subscribe = (cb: () => void) => {\n listeners.add(cb);\n timer ??= setInterval(() => listeners.forEach((l) => l()), 30_000);\n return () => {\n listeners.delete(cb);\n if (listeners.size === 0 && timer !== undefined) {\n clearInterval(timer);\n timer = undefined;\n }\n };\n};\nconst currentMinute = () => Math.floor(Date.now() / MIN) * MIN;\n\n/**\n * `<time>` showing \"5 min ago\" with the absolute timestamp as `title` and a\n * machine-readable `dateTime`. Strings come from `UiStrings.relativeTime`.\n * Beyond 30 days it falls back to the absolute date so text never goes stale.\n *\n * @example\n * <RelativeTime date={post.createdAt} />\n */\nexport const RelativeTime = forwardRef<HTMLTimeElement, RelativeTimeProps>(function RelativeTime(\n { date, now, absolute, className, ...props },\n ref,\n) {\n const strings = useStrings().relativeTime;\n const d = date instanceof Date ? date : new Date(date);\n const tick = useSyncExternalStore(subscribe, currentMinute, currentMinute);\n const ref_ = now === undefined ? tick : now instanceof Date ? now.getTime() : now;\n const diff = d.getTime() - ref_;\n const abs = Math.abs(diff);\n const future = diff > 0;\n const title = formatDate(d, absolute);\n\n let label: string;\n if (abs < MIN) label = strings.justNow;\n else if (abs < HOUR)\n label = formatString(future ? strings.inMinutes : strings.minutesAgo, {\n n: Math.round(abs / MIN),\n });\n else if (abs < DAY)\n label = formatString(future ? strings.inHours : strings.hoursAgo, {\n n: Math.round(abs / HOUR),\n });\n else if (abs < 30 * DAY)\n label = formatString(future ? strings.inDays : strings.daysAgo, { n: Math.round(abs / DAY) });\n else label = title;\n\n return (\n <time\n data-slot=\"relative-time\"\n ref={ref}\n dateTime={Number.isNaN(d.getTime()) ? undefined : d.toISOString()}\n title={title}\n className={cn('tabular', className)}\n {...props}\n >\n {label}\n </time>\n );\n});\nRelativeTime.displayName = 'RelativeTime';\n"],"names":["MIN","HOUR","DAY","listeners","timer","subscribe","cb","l","currentMinute","RelativeTime","forwardRef","date","now","absolute","className","props","ref","strings","useStrings","d","tick","useSyncExternalStore","ref_","diff","abs","future","title","formatDate","label","formatString","jsx","cn"],"mappings":";;;;;;;AAqBA,MAAMA,IAAM,KACNC,IAAO,KAAKD,GACZE,IAAM,KAAKD,GAQXE,wBAAgB,IAAA;AACtB,IAAIC;AACJ,MAAMC,IAAY,CAACC,OACjBH,EAAU,IAAIG,CAAE,GAChBF,UAAU,YAAY,MAAMD,EAAU,QAAQ,CAACI,MAAMA,GAAG,GAAG,GAAM,IAC1D,MAAM;AACX,EAAAJ,EAAU,OAAOG,CAAE,GACfH,EAAU,SAAS,KAAKC,MAAU,WACpC,cAAcA,CAAK,GACnBA,IAAQ;AAEZ,IAEII,IAAgB,MAAM,KAAK,MAAM,KAAK,IAAA,IAAQR,CAAG,IAAIA,GAU9CS,IAAeC,EAA+C,SACzE,EAAE,MAAAC,GAAM,KAAAC,GAAK,UAAAC,GAAU,WAAAC,GAAW,GAAGC,EAAA,GACrCC,GACA;AACA,QAAMC,IAAUC,IAAa,cACvBC,IAAIR,aAAgB,OAAOA,IAAO,IAAI,KAAKA,CAAI,GAC/CS,IAAOC,EAAqBhB,GAAWG,GAAeA,CAAa,GACnEc,IAAOV,MAAQ,SAAYQ,IAAOR,aAAe,OAAOA,EAAI,YAAYA,GACxEW,IAAOJ,EAAE,QAAA,IAAYG,GACrBE,IAAM,KAAK,IAAID,CAAI,GACnBE,IAASF,IAAO,GAChBG,IAAQC,EAAWR,GAAGN,CAAQ;AAEpC,MAAIe;AACJ,SAAIJ,IAAMxB,IAAK4B,IAAQX,EAAQ,UACtBO,IAAMvB,IACb2B,IAAQC,EAAaJ,IAASR,EAAQ,YAAYA,EAAQ,YAAY;AAAA,IACpE,GAAG,KAAK,MAAMO,IAAMxB,CAAG;AAAA,EAAA,CACxB,IACMwB,IAAMtB,IACb0B,IAAQC,EAAaJ,IAASR,EAAQ,UAAUA,EAAQ,UAAU;AAAA,IAChE,GAAG,KAAK,MAAMO,IAAMvB,CAAI;AAAA,EAAA,CACzB,IACMuB,IAAM,KAAKtB,IAClB0B,IAAQC,EAAaJ,IAASR,EAAQ,SAASA,EAAQ,SAAS,EAAE,GAAG,KAAK,MAAMO,IAAMtB,CAAG,GAAG,IACzF0B,IAAQF,GAGX,gBAAAI;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,aAAU;AAAA,MACV,KAAAd;AAAA,MACA,UAAU,OAAO,MAAMG,EAAE,SAAS,IAAI,SAAYA,EAAE,YAAA;AAAA,MACpD,OAAAO;AAAA,MACA,WAAWK,EAAG,WAAWjB,CAAS;AAAA,MACjC,GAAGC;AAAA,MAEH,UAAAa;AAAA,IAAA;AAAA,EAAA;AAGP,CAAC;AACDnB,EAAa,cAAc;"}
@@ -62,7 +62,9 @@ interface SidebarItemBaseProps {
62
62
  tooltip?: ReactNode;
63
63
  /**
64
64
  * Render the child element (router `<Link>`) instead of `<a>`/`<button>`.
65
- * The child receives className, aria-current and the item content.
65
+ * The child receives className, aria-current and the item content — its own
66
+ * children become the label, wrapped with `icon`, `trailing` and the
67
+ * collapsed sr-only text exactly like a plain item.
66
68
  */
67
69
  asChild?: boolean;
68
70
  }