@opsinjs/react 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +114 -2
- package/dist/components/accordion.d.ts +82 -0
- package/dist/components/accordion.d.ts.map +1 -0
- package/dist/components/accordion.js +154 -0
- package/dist/components/accordion.js.map +1 -0
- package/dist/components/alert-banner.d.ts +291 -0
- package/dist/components/alert-banner.d.ts.map +1 -0
- package/dist/components/alert-banner.js +529 -0
- package/dist/components/alert-banner.js.map +1 -0
- package/dist/components/avatar.d.ts +45 -0
- package/dist/components/avatar.d.ts.map +1 -0
- package/dist/components/avatar.js +159 -0
- package/dist/components/avatar.js.map +1 -0
- package/dist/components/badge.d.ts +78 -0
- package/dist/components/badge.d.ts.map +1 -0
- package/dist/components/badge.js +32 -0
- package/dist/components/badge.js.map +1 -0
- package/dist/components/body-map.d.ts +51 -0
- package/dist/components/body-map.d.ts.map +1 -0
- package/dist/components/body-map.js +190 -0
- package/dist/components/body-map.js.map +1 -0
- package/dist/components/button.d.ts +260 -0
- package/dist/components/button.d.ts.map +1 -0
- package/dist/components/button.js +609 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/callout.d.ts +99 -0
- package/dist/components/callout.d.ts.map +1 -0
- package/dist/components/callout.js +285 -0
- package/dist/components/callout.js.map +1 -0
- package/dist/components/card.d.ts +156 -0
- package/dist/components/card.d.ts.map +1 -0
- package/dist/components/card.js +396 -0
- package/dist/components/card.js.map +1 -0
- package/dist/components/care-card.d.ts +182 -0
- package/dist/components/care-card.d.ts.map +1 -0
- package/dist/components/care-card.js +544 -0
- package/dist/components/care-card.js.map +1 -0
- package/dist/components/checkbox.d.ts +58 -0
- package/dist/components/checkbox.d.ts.map +1 -0
- package/dist/components/checkbox.js +167 -0
- package/dist/components/checkbox.js.map +1 -0
- package/dist/components/combobox.d.ts +71 -0
- package/dist/components/combobox.d.ts.map +1 -0
- package/dist/components/combobox.js +204 -0
- package/dist/components/combobox.js.map +1 -0
- package/dist/components/consent-sheet.d.ts +186 -0
- package/dist/components/consent-sheet.d.ts.map +1 -0
- package/dist/components/consent-sheet.js +452 -0
- package/dist/components/consent-sheet.js.map +1 -0
- package/dist/components/dialog.d.ts +108 -0
- package/dist/components/dialog.d.ts.map +1 -0
- package/dist/components/dialog.js +573 -0
- package/dist/components/dialog.js.map +1 -0
- package/dist/components/disclaimer-note.d.ts +144 -0
- package/dist/components/disclaimer-note.d.ts.map +1 -0
- package/dist/components/disclaimer-note.js +486 -0
- package/dist/components/disclaimer-note.js.map +1 -0
- package/dist/components/divider.d.ts +76 -0
- package/dist/components/divider.d.ts.map +1 -0
- package/dist/components/divider.js +101 -0
- package/dist/components/divider.js.map +1 -0
- package/dist/components/dose-tracker.d.ts +137 -0
- package/dist/components/dose-tracker.d.ts.map +1 -0
- package/dist/components/dose-tracker.js +154 -0
- package/dist/components/dose-tracker.js.map +1 -0
- package/dist/components/empty-state.d.ts +171 -0
- package/dist/components/empty-state.d.ts.map +1 -0
- package/dist/components/empty-state.js +387 -0
- package/dist/components/empty-state.js.map +1 -0
- package/dist/components/field.d.ts +195 -0
- package/dist/components/field.d.ts.map +1 -0
- package/dist/components/field.js +282 -0
- package/dist/components/field.js.map +1 -0
- package/dist/components/goal-ring.d.ts +114 -0
- package/dist/components/goal-ring.d.ts.map +1 -0
- package/dist/components/goal-ring.js +254 -0
- package/dist/components/goal-ring.js.map +1 -0
- package/dist/components/icon-button.d.ts +124 -0
- package/dist/components/icon-button.d.ts.map +1 -0
- package/dist/components/icon-button.js +113 -0
- package/dist/components/icon-button.js.map +1 -0
- package/dist/components/link.d.ts +122 -0
- package/dist/components/link.d.ts.map +1 -0
- package/dist/components/link.js +164 -0
- package/dist/components/link.js.map +1 -0
- package/dist/components/log-sheet.d.ts +259 -0
- package/dist/components/log-sheet.d.ts.map +1 -0
- package/dist/components/log-sheet.js +437 -0
- package/dist/components/log-sheet.js.map +1 -0
- package/dist/components/menu.d.ts +69 -0
- package/dist/components/menu.d.ts.map +1 -0
- package/dist/components/menu.js +190 -0
- package/dist/components/menu.js.map +1 -0
- package/dist/components/metric-tile.d.ts +301 -0
- package/dist/components/metric-tile.d.ts.map +1 -0
- package/dist/components/metric-tile.js +533 -0
- package/dist/components/metric-tile.js.map +1 -0
- package/dist/components/number-field.d.ts +62 -0
- package/dist/components/number-field.d.ts.map +1 -0
- package/dist/components/number-field.js +134 -0
- package/dist/components/number-field.js.map +1 -0
- package/dist/components/popover.d.ts +70 -0
- package/dist/components/popover.d.ts.map +1 -0
- package/dist/components/popover.js +174 -0
- package/dist/components/popover.js.map +1 -0
- package/dist/components/progress.d.ts +83 -0
- package/dist/components/progress.d.ts.map +1 -0
- package/dist/components/progress.js +140 -0
- package/dist/components/progress.js.map +1 -0
- package/dist/components/questionnaire.d.ts +123 -0
- package/dist/components/questionnaire.d.ts.map +1 -0
- package/dist/components/questionnaire.js +148 -0
- package/dist/components/questionnaire.js.map +1 -0
- package/dist/components/radio-group.d.ts +66 -0
- package/dist/components/radio-group.d.ts.map +1 -0
- package/dist/components/radio-group.js +186 -0
- package/dist/components/radio-group.js.map +1 -0
- package/dist/components/range-bar.d.ts +172 -0
- package/dist/components/range-bar.d.ts.map +1 -0
- package/dist/components/range-bar.js +578 -0
- package/dist/components/range-bar.js.map +1 -0
- package/dist/components/range-legend.d.ts +97 -0
- package/dist/components/range-legend.d.ts.map +1 -0
- package/dist/components/range-legend.js +166 -0
- package/dist/components/range-legend.js.map +1 -0
- package/dist/components/reading-input.d.ts +225 -0
- package/dist/components/reading-input.d.ts.map +1 -0
- package/dist/components/reading-input.js +651 -0
- package/dist/components/reading-input.js.map +1 -0
- package/dist/components/relative-time.d.ts +177 -0
- package/dist/components/relative-time.d.ts.map +1 -0
- package/dist/components/relative-time.js +603 -0
- package/dist/components/relative-time.js.map +1 -0
- package/dist/components/result-card.d.ts +319 -0
- package/dist/components/result-card.d.ts.map +1 -0
- package/dist/components/result-card.js +614 -0
- package/dist/components/result-card.js.map +1 -0
- package/dist/components/scale-input.d.ts +58 -0
- package/dist/components/scale-input.d.ts.map +1 -0
- package/dist/components/scale-input.js +170 -0
- package/dist/components/scale-input.js.map +1 -0
- package/dist/components/score-dial.d.ts +205 -0
- package/dist/components/score-dial.d.ts.map +1 -0
- package/dist/components/score-dial.js +728 -0
- package/dist/components/score-dial.js.map +1 -0
- package/dist/components/scroll-area.d.ts +38 -0
- package/dist/components/scroll-area.d.ts.map +1 -0
- package/dist/components/scroll-area.js +138 -0
- package/dist/components/scroll-area.js.map +1 -0
- package/dist/components/segmented-control.d.ts +69 -0
- package/dist/components/segmented-control.d.ts.map +1 -0
- package/dist/components/segmented-control.js +259 -0
- package/dist/components/segmented-control.js.map +1 -0
- package/dist/components/select.d.ts +72 -0
- package/dist/components/select.d.ts.map +1 -0
- package/dist/components/select.js +205 -0
- package/dist/components/select.js.map +1 -0
- package/dist/components/sheet.d.ts +192 -0
- package/dist/components/sheet.d.ts.map +1 -0
- package/dist/components/sheet.js +952 -0
- package/dist/components/sheet.js.map +1 -0
- package/dist/components/skeleton.d.ts +104 -0
- package/dist/components/skeleton.d.ts.map +1 -0
- package/dist/components/skeleton.js +266 -0
- package/dist/components/skeleton.js.map +1 -0
- package/dist/components/slider.d.ts +55 -0
- package/dist/components/slider.d.ts.map +1 -0
- package/dist/components/slider.js +170 -0
- package/dist/components/slider.js.map +1 -0
- package/dist/components/source-citation.d.ts +127 -0
- package/dist/components/source-citation.d.ts.map +1 -0
- package/dist/components/source-citation.js +391 -0
- package/dist/components/source-citation.js.map +1 -0
- package/dist/components/spinner.d.ts +86 -0
- package/dist/components/spinner.d.ts.map +1 -0
- package/dist/components/spinner.js +97 -0
- package/dist/components/spinner.js.map +1 -0
- package/dist/components/status-pill.d.ts +90 -0
- package/dist/components/status-pill.d.ts.map +1 -0
- package/dist/components/status-pill.js +259 -0
- package/dist/components/status-pill.js.map +1 -0
- package/dist/components/stepper.d.ts +99 -0
- package/dist/components/stepper.d.ts.map +1 -0
- package/dist/components/stepper.js +152 -0
- package/dist/components/stepper.js.map +1 -0
- package/dist/components/surface.d.ts +92 -0
- package/dist/components/surface.d.ts.map +1 -0
- package/dist/components/surface.js +261 -0
- package/dist/components/surface.js.map +1 -0
- package/dist/components/switch.d.ts +48 -0
- package/dist/components/switch.d.ts.map +1 -0
- package/dist/components/switch.js +152 -0
- package/dist/components/switch.js.map +1 -0
- package/dist/components/symptom-picker.d.ts +69 -0
- package/dist/components/symptom-picker.d.ts.map +1 -0
- package/dist/components/symptom-picker.js +170 -0
- package/dist/components/symptom-picker.js.map +1 -0
- package/dist/components/tab-bar.d.ts +110 -0
- package/dist/components/tab-bar.d.ts.map +1 -0
- package/dist/components/tab-bar.js +118 -0
- package/dist/components/tab-bar.js.map +1 -0
- package/dist/components/table.d.ts +117 -0
- package/dist/components/table.d.ts.map +1 -0
- package/dist/components/table.js +65 -0
- package/dist/components/table.js.map +1 -0
- package/dist/components/tabs.d.ts +106 -0
- package/dist/components/tabs.d.ts.map +1 -0
- package/dist/components/tabs.js +136 -0
- package/dist/components/tabs.js.map +1 -0
- package/dist/components/term.d.ts +243 -0
- package/dist/components/term.d.ts.map +1 -0
- package/dist/components/term.js +562 -0
- package/dist/components/term.js.map +1 -0
- package/dist/components/textarea.d.ts +157 -0
- package/dist/components/textarea.d.ts.map +1 -0
- package/dist/components/textarea.js +66 -0
- package/dist/components/textarea.js.map +1 -0
- package/dist/components/timeline-entry.d.ts +99 -0
- package/dist/components/timeline-entry.d.ts.map +1 -0
- package/dist/components/timeline-entry.js +47 -0
- package/dist/components/timeline-entry.js.map +1 -0
- package/dist/components/toast.d.ts +80 -0
- package/dist/components/toast.d.ts.map +1 -0
- package/dist/components/toast.js +266 -0
- package/dist/components/toast.js.map +1 -0
- package/dist/components/tooltip.d.ts +48 -0
- package/dist/components/tooltip.d.ts.map +1 -0
- package/dist/components/tooltip.js +159 -0
- package/dist/components/tooltip.js.map +1 -0
- package/dist/components/trend-sparkline.d.ts +188 -0
- package/dist/components/trend-sparkline.d.ts.map +1 -0
- package/dist/components/trend-sparkline.js +796 -0
- package/dist/components/trend-sparkline.js.map +1 -0
- package/dist/components/value.d.ts +150 -0
- package/dist/components/value.d.ts.map +1 -0
- package/dist/components/value.js +402 -0
- package/dist/components/value.js.map +1 -0
- package/dist/components/visually-hidden.d.ts +61 -0
- package/dist/components/visually-hidden.d.ts.map +1 -0
- package/dist/components/visually-hidden.js +172 -0
- package/dist/components/visually-hidden.js.map +1 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/opsinjs.d.ts +443 -0
- package/dist/opsinjs.d.ts.map +1 -0
- package/dist/opsinjs.js +906 -0
- package/dist/opsinjs.js.map +1 -0
- package/dist/status.d.ts +111 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +125 -0
- package/dist/status.js.map +1 -0
- package/dist/styles.css +2 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +82 -0
- package/dist/utils.js.map +1 -0
- package/package.json +86 -3
- package/styles/base.css +132 -0
- package/styles/roles.css +412 -0
- package/styles/standalone.css +20 -0
- package/styles/tailwind.css +18 -0
- package/styles/theme.css +309 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* Menu is a list of actions opened from a button. Its home is the small set of
|
|
5
|
+
* commands that act on one thing, an item's Share, Rename and Duplicate being
|
|
6
|
+
* the case it was built for, folded behind a trigger so they do not take the
|
|
7
|
+
* space of showing every command at once.
|
|
8
|
+
*
|
|
9
|
+
* IT IS BUILT ON BASE UI's Menu, AND THAT IS WHERE THE KEYBOARD COMES FROM. The
|
|
10
|
+
* trigger is the one tab stop; Enter, Space or Arrow Down opens the list; the
|
|
11
|
+
* Arrow keys move a highlight through the items with the popup holding focus;
|
|
12
|
+
* Enter or Space runs the highlighted item and closes; Escape closes without
|
|
13
|
+
* running anything and returns focus to the trigger. That is the WAI-ARIA menu
|
|
14
|
+
* button pattern rather than a bespoke one nobody has tested, and the primitive
|
|
15
|
+
* renders `aria-haspopup` on the trigger, `role="menu"` on the popup and
|
|
16
|
+
* `role="menuitem"` on each item, so a screen reader reads the control in the
|
|
17
|
+
* register a reader expects.
|
|
18
|
+
*
|
|
19
|
+
* THE TRIGGER IS THE CALLER's OWN BUTTON, AND THE `render` PROP IS WHY. A menu
|
|
20
|
+
* button is a button, and the system already ships one, so this component does
|
|
21
|
+
* not draw a second. The caller passes their button as `trigger`, and Base UI
|
|
22
|
+
* merges the open behaviour, the `aria-haspopup` and the `aria-expanded` state
|
|
23
|
+
* onto it through `render`, so there is one button rather than a button nested
|
|
24
|
+
* inside another button, which is invalid and which a plain wrapper would
|
|
25
|
+
* produce. That also means the trigger's target floor and focus ring are the
|
|
26
|
+
* caller's button's own rather than this file's to add, which is why nothing
|
|
27
|
+
* here floors the trigger.
|
|
28
|
+
*
|
|
29
|
+
* THE LIST FLOATS IN A PORTAL, ON PURPOSE. The items are rendered through
|
|
30
|
+
* `Menu.Portal` into a `Menu.Positioner`, so the popup escapes the overflow
|
|
31
|
+
* clipping and stacking context of whatever card, toolbar or scroll area the
|
|
32
|
+
* trigger sits in. The positioner caps the popup's height at `--available-height`
|
|
33
|
+
* with an internal scroll, so a long list stays inside the viewport rather than
|
|
34
|
+
* growing past it, and the popup floats on the `overlay` material rung so it
|
|
35
|
+
* reads as a raised object rather than a flat block.
|
|
36
|
+
*
|
|
37
|
+
* NEITHER COLOUR AXIS, AND NO DESTRUCTIVE TINT. A menu runs actions; it states
|
|
38
|
+
* no clinical level and names no category, so it carries neither `data-status`
|
|
39
|
+
* nor `data-category` and draws only neutral chrome. There is deliberately no
|
|
40
|
+
* red for a removing or a clearing action either: the only red in this system is
|
|
41
|
+
* the clinical status axis, so a destructive item stays neutral and its WORD is
|
|
42
|
+
* what tells the reader what it does. A menu is also the wrong place to confirm
|
|
43
|
+
* anything irreversible, because a menu item runs on a single press with no
|
|
44
|
+
* second step. An action that cannot be undone runs a confirming Dialog rather
|
|
45
|
+
* than firing straight from the list.
|
|
46
|
+
*
|
|
47
|
+
* A SAFETY-RELEVANT ACTION DOES NOT BELONG IN HERE AT ALL. Hiding a destructive
|
|
48
|
+
* or a safety-relevant command behind an overflow trigger is a defect whatever
|
|
49
|
+
* draws the overflow, because the reader cannot weigh a command they cannot see.
|
|
50
|
+
* Such a command belongs on the screen as a button, with a Dialog to confirm it.
|
|
51
|
+
* The component cannot read the meaning of an action's label, so it cannot
|
|
52
|
+
* enforce this; the page states it and the demo keeps to it.
|
|
53
|
+
*
|
|
54
|
+
* THE ITEMS FLOOR THEIR TARGET AND CARRY THEIR OWN HIGHLIGHT. Each item floors
|
|
55
|
+
* its hit area at `--opsin-target-minimum` in rem so a 44pt pressable row
|
|
56
|
+
* survives and grows with the reader's text size, and the active row under the
|
|
57
|
+
* Arrow keys and the pointer is lifted by the neutral `state-hover` surface read
|
|
58
|
+
* from `data-highlighted` rather than by a hue, so the roving highlight survives
|
|
59
|
+
* greyscale. A disabled item drops to the measured muted ink rather than an
|
|
60
|
+
* opacity wash and is skipped by the keys, so it stays legible while reading as
|
|
61
|
+
* unavailable.
|
|
62
|
+
*/
|
|
63
|
+
import { Menu as MenuPrimitive } from "@base-ui/react/menu";
|
|
64
|
+
import { Fragment } from "react";
|
|
65
|
+
import { isDevelopment } from "../opsinjs.js";
|
|
66
|
+
import { cn } from "../utils.js";
|
|
67
|
+
/**
|
|
68
|
+
* UNFOLD, the fourth of the five interaction motions (ADR 0031), shared by every
|
|
69
|
+
* popup in the system so a menu opens the way a menu, a select, a combobox, a
|
|
70
|
+
* popover and a tooltip all do.
|
|
71
|
+
*
|
|
72
|
+
* The menu grows out of the button that opened it rather than appearing out
|
|
73
|
+
* of nowhere. `origin-(--transform-origin)` reads the point Base UI's
|
|
74
|
+
* positioner computes on the button's side of the popup, so it scales up from
|
|
75
|
+
* there and collapses back into it. It arrives from 0.96 and slightly soft, a
|
|
76
|
+
* 4px blur that clears as it settles, so it comes into focus the way an object
|
|
77
|
+
* does when it is brought close, on `spring-settle`, the spring
|
|
78
|
+
* tokens/motion.json names for popovers, tooltips and menus. It leaves faster
|
|
79
|
+
* than it came, to 0.98 and transparent on `ease-exit` over `duration-fast`,
|
|
80
|
+
* because a reader does not need to watch a dismissal finish. When Escape, or
|
|
81
|
+
* a second press on the control that opened it, closes it, Base UI marks the
|
|
82
|
+
* popup `data-instant="dismiss"`, and that cancels the transition, so a reader
|
|
83
|
+
* who asked for it gone has it gone at once. Base UI also marks a popup opened from the keyboard
|
|
84
|
+
* `data-instant="click"`, and that one is ignored on purpose: a reader who
|
|
85
|
+
* opens it with Enter sees the same unfold as a reader with a pointer.
|
|
86
|
+
*
|
|
87
|
+
* Under `prefers-reduced-motion: reduce` the scale and the blur are pinned to
|
|
88
|
+
* rest, and `spring-settle` collapses in the generated sheet to a 100ms linear
|
|
89
|
+
* fade, so the menu still visibly appears and does not travel. The exit's
|
|
90
|
+
* `duration-fast` collapses to 1ms. A menu holds actions and never a reading, so nothing here animates a value.
|
|
91
|
+
*/
|
|
92
|
+
const UNFOLD = "origin-(--transform-origin) " +
|
|
93
|
+
"transition-[opacity,scale,filter] duration-(--opsin-duration-spring-settle) ease-opsin-spring-settle " +
|
|
94
|
+
"data-[starting-style]:opacity-0 data-[starting-style]:scale-96 data-[starting-style]:blur-xs " +
|
|
95
|
+
"data-[ending-style]:opacity-0 data-[ending-style]:scale-98 " +
|
|
96
|
+
"data-[ending-style]:duration-(--opsin-duration-fast) data-[ending-style]:ease-opsin-exit " +
|
|
97
|
+
"data-[instant=dismiss]:transition-none " +
|
|
98
|
+
"motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[starting-style]:blur-none " +
|
|
99
|
+
"motion-reduce:data-[ending-style]:scale-100";
|
|
100
|
+
/**
|
|
101
|
+
* The popup surface, spelled once. A raised card with a hairline: `bg-card`
|
|
102
|
+
* lifts it off whatever it floats over, `border-border` draws its edge for
|
|
103
|
+
* greyscale, and the `overlay` material rung casts the one black-alpha shadow
|
|
104
|
+
* the material ladder publishes for a floating surface. It caps its height at
|
|
105
|
+
* `--available-height` with an internal scroll, so a long list stays inside the
|
|
106
|
+
* viewport rather than growing past it, and it is at least as wide as the
|
|
107
|
+
* trigger through `--anchor-width`. Consuming the material token rather than a
|
|
108
|
+
* raw shadow literal keeps this file inside the colour contract.
|
|
109
|
+
* Its entrance and exit are `UNFOLD`, set out above.
|
|
110
|
+
*/
|
|
111
|
+
const POPUP = "max-h-[var(--available-height)] min-w-[var(--anchor-width)] overflow-y-auto " +
|
|
112
|
+
"rounded-opsin-md border border-edge bg-card p-opsin-1 " +
|
|
113
|
+
"shadow-(--opsin-material-raised-shadow) [color:var(--foreground)] " +
|
|
114
|
+
UNFOLD;
|
|
115
|
+
/**
|
|
116
|
+
* One action row, spelled once. A full-width row with the label on the left. The
|
|
117
|
+
* highlight is the neutral `state-hover` surface switched on by `data-highlighted`,
|
|
118
|
+
* which is the active row under the Arrow keys and under the pointer, so the
|
|
119
|
+
* roving highlight is visible without a colour on either axis. Base UI moves
|
|
120
|
+
* real keyboard focus onto the highlighted row, so the row also carries the
|
|
121
|
+
* house focus ring on `focus-visible`, which is the strong keyboard cue that
|
|
122
|
+
* the low-contrast surface lift cannot be on its own. A disabled row
|
|
123
|
+
* drops to the muted ink and is skipped by the keys. Each row floors its target
|
|
124
|
+
* at `--opsin-target-minimum` in rem with a literal fallback, so a touch reader
|
|
125
|
+
* gets a 44pt row and the declaration stays valid where the token sheet was not
|
|
126
|
+
* installed. The ink is the arbitrary property `[color:var(--foreground)]` and
|
|
127
|
+
* not `text-foreground`, for the reason `select.tsx` sets out: tailwind-merge
|
|
128
|
+
* files a `text-*` colour in the same conflict group as the `text-opsin-*` type
|
|
129
|
+
* step and drops one of them, so the arbitrary property keeps both the ink and
|
|
130
|
+
* the size.
|
|
131
|
+
*/
|
|
132
|
+
const ITEM = "relative flex w-full cursor-pointer select-none items-center gap-opsin-2 " +
|
|
133
|
+
"rounded-opsin-sm px-opsin-3 py-opsin-2 min-h-(--opsin-target-minimum,2.75rem) " +
|
|
134
|
+
"text-opsin-body [color:var(--foreground)] outline-none " +
|
|
135
|
+
// The offset is negated so the ring sits inside the item's box. The item runs
|
|
136
|
+
// the full width of POPUP, whose padding equals the ring's outward reach and
|
|
137
|
+
// which is `overflow-y-auto` with rounded corners, so an outward ring would be
|
|
138
|
+
// clipped at the popup's edge and its rounded corners, most visibly on the
|
|
139
|
+
// first item highlighted when the menu opens. This is the same inset-ring
|
|
140
|
+
// treatment `accordion.tsx` uses inside its own clipping shell.
|
|
141
|
+
"focus-visible:outline-[length:var(--opsin-border-focus,2px)] focus-visible:outline-offset-[calc(var(--opsin-border-focus-offset,2px)*-1)] focus-visible:outline-ring " +
|
|
142
|
+
"data-[highlighted]:bg-state-hover " +
|
|
143
|
+
"data-[disabled]:cursor-not-allowed data-[disabled]:[color:var(--muted-foreground)] data-[disabled]:bg-transparent";
|
|
144
|
+
/**
|
|
145
|
+
* The separator between two groups of actions, spelled once. A neutral hairline
|
|
146
|
+
* inset to the popup's padding, drawing only `border-border`, so it reads as a
|
|
147
|
+
* boundary and carries neither colour axis.
|
|
148
|
+
*/
|
|
149
|
+
const SEPARATOR = "-mx-opsin-1 my-opsin-1 h-px border-0 bg-border";
|
|
150
|
+
/**
|
|
151
|
+
* Development warnings, said once per distinct offender. Nothing here has an
|
|
152
|
+
* `OpsinErrorCode`: the codes in `tokens/errors.json` describe mistakes a
|
|
153
|
+
* consumer makes with the clinical API, and a menu asserts nothing clinical.
|
|
154
|
+
* `select.tsx` keeps the same small set for the same reason.
|
|
155
|
+
*/
|
|
156
|
+
const warned = new Set();
|
|
157
|
+
function warnDev(key, message) {
|
|
158
|
+
if (!isDevelopment() || warned.has(key))
|
|
159
|
+
return;
|
|
160
|
+
warned.add(key);
|
|
161
|
+
console.warn(message);
|
|
162
|
+
}
|
|
163
|
+
export function Menu({ trigger, items, className }) {
|
|
164
|
+
if (isDevelopment()) {
|
|
165
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
166
|
+
warnDev("no-items", "[opsinjs] <Menu> was rendered with no items, so it has nothing to " +
|
|
167
|
+
"open. A menu is a list of actions; supply them through the `items` " +
|
|
168
|
+
"prop.");
|
|
169
|
+
}
|
|
170
|
+
else if (items.length === 1) {
|
|
171
|
+
warnDev("one-item", "[opsinjs] <Menu> was given a single item, which is a button that has " +
|
|
172
|
+
"not admitted it. Render the one action as a Button on the screen " +
|
|
173
|
+
"rather than folding it behind a trigger the reader has to open.");
|
|
174
|
+
}
|
|
175
|
+
if (Array.isArray(items)) {
|
|
176
|
+
for (const item of items) {
|
|
177
|
+
if (typeof item.onClick !== "function" && item.disabled !== true) {
|
|
178
|
+
warnDev(`item-no-onclick:${item.label}`, `[opsinjs] <Menu> item "${item.label}" has no onClick and is not ` +
|
|
179
|
+
"disabled, so it renders as an action that does nothing when run. " +
|
|
180
|
+
"Give it an onClick, or mark it disabled if it is a placeholder.");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
return (_jsxs(MenuPrimitive.Root, { children: [_jsx(MenuPrimitive.Trigger, { "data-slot": "menu-trigger", render: trigger }), _jsx(MenuPrimitive.Portal, { children: _jsx(MenuPrimitive.Positioner, { className: "z-50", side: "bottom", align: "start", sideOffset: 6, children: _jsx(MenuPrimitive.Popup, { "data-slot": "menu-popup", className: cn(POPUP, className), children: items.map((item, index) => (_jsxs(Fragment, { children: [item.separatorBefore && index > 0 ? (_jsx(MenuPrimitive.Separator, { "data-slot": "menu-separator", className: SEPARATOR })) : null, _jsx(MenuPrimitive.Item, { "data-slot": "menu-item", className: ITEM, disabled: item.disabled, onClick: item.onClick, children: item.label })] }, `${item.label}-${index}`))) }) }) })] }));
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=menu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu.js","sourceRoot":"","sources":["../../src/components/menu.tsx"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MetricTile is one measurement, its unit and its age, at the size that fits in
|
|
3
|
+
* a grid with seven others.
|
|
4
|
+
*
|
|
5
|
+
* WHAT IT ASSERTS, and the list is three items long: that this measurement had
|
|
6
|
+
* this value, in this unit, at this time. Nothing else. It does not say whether
|
|
7
|
+
* the number is where it should be, whether it has moved, or what to do about
|
|
8
|
+
* it. Every one of those needs a sentence, and a tile has no room for one.
|
|
9
|
+
* `label`, `value` and `now` are always required, and `measuredAt` is required
|
|
10
|
+
* for a reading: an undated reading is unusable, and a reading with no instant
|
|
11
|
+
* to measure its age against cannot be shown to be current or shown to be old.
|
|
12
|
+
* An absent reading needs no time, so `measuredAt` may be `null` beside one.
|
|
13
|
+
*
|
|
14
|
+
* WHEN THERE IS NO READING THE THIRD ASSERTION IS WITHHELD. A tile whose `value`
|
|
15
|
+
* is `null` or a broken number shows the absence and the label and stops there.
|
|
16
|
+
* The time line is dropped, because "Measured" beside "no reading yet" claims a
|
|
17
|
+
* measurement that did not happen, and no event word would make that pairing
|
|
18
|
+
* honest. With no measurement there need be no measurement time, so `measuredAt`
|
|
19
|
+
* may be `null` in that state, and a real timestamp passed there is still not
|
|
20
|
+
* rendered, because there is no reading for it to date.
|
|
21
|
+
*
|
|
22
|
+
* IT DERIVES NO VERDICT. `status` is an input, assigned by the product, and it
|
|
23
|
+
* is rendered by StatusPill and by nothing else here. This file contains no
|
|
24
|
+
* comparison of a value against anything, because it has no range, no
|
|
25
|
+
* threshold and no reader.
|
|
26
|
+
*
|
|
27
|
+
* THE TWO AXES, AND WHICH ELEMENT TAKES WHICH. The category tints the icon and
|
|
28
|
+
* the label. That is identity, so the sleep tiles are findable among the heart
|
|
29
|
+
* tiles without reading eight labels. The status appears as an embedded
|
|
30
|
+
* StatusPill and never as the tile's fill: a grid of status-coloured tiles is a
|
|
31
|
+
* picture of somebody's body rendered as a heat map, and it is least readable
|
|
32
|
+
* at the moment it matters most. No element here carries both, so there is no
|
|
33
|
+
* OPSIN-0001 to raise. `axisConflict()` is a per-ELEMENT check, and calling it
|
|
34
|
+
* on this component's props would report every correct tile.
|
|
35
|
+
*
|
|
36
|
+
* TWO PLACES WHERE THE SPECIFICATION COULD NOT BE BUILT AS WRITTEN, both
|
|
37
|
+
* resolved here and both written up on the page.
|
|
38
|
+
*
|
|
39
|
+
* 1. THERE IS NO `trend` PROP AND NO EMBEDDED SPARKLINE. The specification asks
|
|
40
|
+
* for `trend?: TrendPoint[]` drawn small, "decorative at tile size", hidden
|
|
41
|
+
* from assistive technology. TrendSparkline shipped with a mandatory,
|
|
42
|
+
* visible caption and a `role="img"` plot named by it, because a line
|
|
43
|
+
* through somebody's readings is a claim that a pattern exists and the
|
|
44
|
+
* sentence beside it is the only part that says which pattern. A picture of
|
|
45
|
+
* a person's health with nothing saying what it is cannot be built, so the
|
|
46
|
+
* honest options were two. One is a tile big enough for a real caption,
|
|
47
|
+
* which by then is a card. The other is no trend at all. This is no trend at
|
|
48
|
+
* all: the tile leads somewhere that can carry one. A product that wants a
|
|
49
|
+
* line in a grid cell composes TrendSparkline in its own layout, at a size
|
|
50
|
+
* where the caption fits; that arrangement is demonstrated by the
|
|
51
|
+
* sparkline's own example.
|
|
52
|
+
*
|
|
53
|
+
* 2. `value` IS `number | null`, NOT `number | string | null`. Every number a
|
|
54
|
+
* reader sees goes through Value, which formats it, resolves the spoken form
|
|
55
|
+
* of the unit and keeps absence apart from zero. Value takes a number.
|
|
56
|
+
* A pre-formatted string is a number somebody else has already rounded, with
|
|
57
|
+
* no spoken unit and no machine-readable datum behind it, and accepting one
|
|
58
|
+
* would put a second formatter in the system. The case the string was for is
|
|
59
|
+
* a compound reading. A compound reading is a pair rather than a number, and
|
|
60
|
+
* a pair is two measurements: it belongs in two tiles, or on a surface that
|
|
61
|
+
* can show both. A value that
|
|
62
|
+
* is not a finite number reaches Value anyway in a JavaScript project, and
|
|
63
|
+
* Value says "not available" and reports it, which is the right words in the
|
|
64
|
+
* right place.
|
|
65
|
+
*
|
|
66
|
+
* STALENESS IS THE PRODUCT'S NUMBER AND NOBODY ELSE'S. `staleAfterHours` has no
|
|
67
|
+
* default and never will: what counts as an old reading is clinical and differs
|
|
68
|
+
* by measurement. Omitted, the tile has no stale treatment at all, which is the
|
|
69
|
+
* honest output when nobody has said what stale means here. Supplied, the tile
|
|
70
|
+
* mutes itself AND RelativeTime says the words. The muting is the scanning aid,
|
|
71
|
+
* the words are the carrier, and a treatment that survives greyscale is the
|
|
72
|
+
* only kind worth having. No number is written down anywhere in this file, in
|
|
73
|
+
* its demo, or in either of its examples, and none may be added: opsinjs owns
|
|
74
|
+
* no staleness boundary for any measurement in any population, and a number in
|
|
75
|
+
* a file opsinjs publishes is a boundary opsinjs has published, to every app
|
|
76
|
+
* that installs the package or copies the demo.
|
|
77
|
+
*
|
|
78
|
+
* WHAT THIS COMPONENT DOES NOT DO, listed here as well as on its page, because
|
|
79
|
+
* this file travels and the page does not. It cannot say where a number came
|
|
80
|
+
* from: `event` names the moment and the product picks it, but nothing here
|
|
81
|
+
* checks that the word matches how the figure was obtained, so a self-reported
|
|
82
|
+
* or device-estimated figure named "measured" is still announced as one. It has no
|
|
83
|
+
* masking affordance, so a reading cannot be obscured on a shared screen
|
|
84
|
+
* without the layout moving. It does not require an `href` beside a level that
|
|
85
|
+
* asks for action. And it holds a second copy of RelativeTime's instant rule
|
|
86
|
+
* because RelativeTime publishes neither the parser nor the verdict; the copy
|
|
87
|
+
* is exact today and nothing but a reader stops it drifting. Every one of those
|
|
88
|
+
* is a gap this file has, not a gap it hides.
|
|
89
|
+
*/
|
|
90
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
91
|
+
import { type ClinicalStatus, type HealthCategory } from "../opsinjs.ts";
|
|
92
|
+
import { type TimeEvent } from "./relative-time.tsx";
|
|
93
|
+
export interface MetricTileProps {
|
|
94
|
+
/**
|
|
95
|
+
* What was measured, in the reader's words. Use two or three of them, not an
|
|
96
|
+
* acronym and not an internal code: a dashboard that has to be learnt before
|
|
97
|
+
* it can be read is a dashboard that is read wrong.
|
|
98
|
+
*/
|
|
99
|
+
label: string;
|
|
100
|
+
/**
|
|
101
|
+
* The reading. `null` renders the no-reading state, which is not zero. Zero
|
|
102
|
+
* is a real measurement for several metrics and a missing one is not a
|
|
103
|
+
* measurement at all.
|
|
104
|
+
*
|
|
105
|
+
* A number and not a string. A pre-formatted reading has already been rounded
|
|
106
|
+
* by somebody, carries no spoken unit and leaves nothing machine-readable
|
|
107
|
+
* behind it; a compound reading such as a pair is two measurements and takes
|
|
108
|
+
* two tiles.
|
|
109
|
+
*/
|
|
110
|
+
value: number | null;
|
|
111
|
+
/**
|
|
112
|
+
* Display symbol, exactly as `tokens/units.json` spells it, as in "kg",
|
|
113
|
+
* "mmol/L" or "steps". The spoken form is resolved from that table by Value,
|
|
114
|
+
* so this is the only place the unit is named. Optional by type and all but
|
|
115
|
+
* mandatory in practice: a bare number is ambiguous between unit systems, and
|
|
116
|
+
* Value raises OPSIN-0003 when one arrives without a unit rather than this
|
|
117
|
+
* file raising a second copy of the same complaint.
|
|
118
|
+
*/
|
|
119
|
+
unit?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Decimal places, from the precision of the measurement. That is the
|
|
122
|
+
* resolution of the device, or the number of places the laboratory reported.
|
|
123
|
+
* Required, so a TypeScript caller cannot omit it: a bare number that arrived
|
|
124
|
+
* from arithmetic can carry seventeen digits, which on a tile is also a
|
|
125
|
+
* layout problem. Forwarded to Value untouched. A JavaScript caller who omits
|
|
126
|
+
* it still gets the digits it was handed plus a development warning from
|
|
127
|
+
* Value.
|
|
128
|
+
*/
|
|
129
|
+
precision: number;
|
|
130
|
+
/**
|
|
131
|
+
* When the reading was taken, ISO 8601 with an offset. The time of
|
|
132
|
+
* MEASUREMENT, never of retrieval, sync or render. A tile that timestamps
|
|
133
|
+
* itself with the moment the screen was drawn tells every reader that every
|
|
134
|
+
* reading is current. The word this instant is announced with is `event`,
|
|
135
|
+
* which defaults to "measured".
|
|
136
|
+
*
|
|
137
|
+
* A reading must be dated. A value with no locatable time is undated, and for
|
|
138
|
+
* health data undated is the same as wrong, so a reading passed with a time
|
|
139
|
+
* this component cannot locate is refused and nothing is drawn.
|
|
140
|
+
*
|
|
141
|
+
* `null` is allowed, and it means one thing only: there is no measurement
|
|
142
|
+
* time because there was no measurement. It is legal solely beside an absent
|
|
143
|
+
* `value`, where the tile shows the absence and no time at all. A reading
|
|
144
|
+
* present beside `measuredAt={null}` is the undated reading above and is
|
|
145
|
+
* refused the same way. A tile that has a value it cannot date is not a tile.
|
|
146
|
+
*/
|
|
147
|
+
measuredAt: string | null;
|
|
148
|
+
/**
|
|
149
|
+
* The word the time line is announced with. It names the moment rather than
|
|
150
|
+
* the origin of the number. The five events RelativeTime publishes are
|
|
151
|
+
* "measured", "recorded", "received", "synced" and "issued"; this defaults to
|
|
152
|
+
* "measured" so an existing caller is unchanged, and a product measuring off a
|
|
153
|
+
* device or reading a laboratory value names the one that is true.
|
|
154
|
+
*
|
|
155
|
+
* It names the moment and not the provenance. This component cannot check that
|
|
156
|
+
* the word matches how the number was obtained, so a self-reported figure
|
|
157
|
+
* routed through here with `event="measured"` is still announced as a
|
|
158
|
+
* measurement. The product owns that word. Data provenance and device accuracy
|
|
159
|
+
* asks for the provenance class to be shown in plain words, which this
|
|
160
|
+
* component still does not carry, and the page records that as an open gap.
|
|
161
|
+
*/
|
|
162
|
+
event?: TimeEvent;
|
|
163
|
+
/**
|
|
164
|
+
* The instant the age is measured against, in the same form as `measuredAt`.
|
|
165
|
+
* Required for the same reason RelativeTime requires it: a component that
|
|
166
|
+
* read the clock itself would be impure, would read it once per tile rather
|
|
167
|
+
* than once per screen, and would let a grid of eight disagree with itself
|
|
168
|
+
* across a minute boundary. Read it once where the screen is rendered. Use
|
|
169
|
+
* `new Date().toISOString()` and pass the same value to every tile on it.
|
|
170
|
+
*/
|
|
171
|
+
now: string;
|
|
172
|
+
/**
|
|
173
|
+
* Hours after which the tile shows its stale treatment. Supplied by the
|
|
174
|
+
* product, and by nobody else: what counts as an old reading is clinical, it
|
|
175
|
+
* differs completely from one measurement to the next, and opsinjs holds no
|
|
176
|
+
* such number for any measurement in any population. Writing one here would
|
|
177
|
+
* publish a boundary this system has no standing to publish. The same is true
|
|
178
|
+
* of writing one in an example, or in a comment as an illustration.
|
|
179
|
+
*
|
|
180
|
+
* There is no default and there will not be one. Omitted, there is no stale
|
|
181
|
+
* treatment at all. That is the honest output when nobody has said what stale
|
|
182
|
+
* means here, and never a substituted number.
|
|
183
|
+
*/
|
|
184
|
+
staleAfterHours?: number;
|
|
185
|
+
/**
|
|
186
|
+
* The level the product assigned to this reading. Rendered as an embedded
|
|
187
|
+
* StatusPill and never as the tile's fill. Omitted, no pill is rendered at
|
|
188
|
+
* all: there is no neutral level to fall back on, and a pill invented to fill
|
|
189
|
+
* a gap would be a verdict nobody gave.
|
|
190
|
+
*
|
|
191
|
+
* PAIR `attention` AND `urgent` WITH AN `href`. Clinical status semantics
|
|
192
|
+
* says of `attention` that there is always a named action, and a tile has no
|
|
193
|
+
* room for a sentence. So on a tile the action is the tile itself, and a
|
|
194
|
+
* level on a tile that leads nowhere leaves a reader a verdict and no way to
|
|
195
|
+
* act on it. Nothing here enforces the pairing: the check belongs in the
|
|
196
|
+
* shared warning channel, which this file cannot add a code to, and it is
|
|
197
|
+
* recorded as an open gap on the component's page rather than left silent.
|
|
198
|
+
*/
|
|
199
|
+
status?: ClinicalStatus;
|
|
200
|
+
/**
|
|
201
|
+
* Tints the icon and the label, and nothing else. Identity rather than
|
|
202
|
+
* meaning: in greyscale the tint is lost and not one fact goes with it.
|
|
203
|
+
*/
|
|
204
|
+
category?: HealthCategory;
|
|
205
|
+
/**
|
|
206
|
+
* The category glyph, supplied by the product. opsinjs ships no category icon
|
|
207
|
+
* set. [category identity](https://opsinjs.pensievelabs.org/docs/health/two-colour-axes)
|
|
208
|
+
* says an icon is governed separately. So this is a slot rather than a
|
|
209
|
+
* lookup, and a tile with no icon is a complete tile.
|
|
210
|
+
*
|
|
211
|
+
* Rendered decorative: the label beside it says the same thing in words, and
|
|
212
|
+
* a glyph announced as well would make a screen reader say the subject twice.
|
|
213
|
+
* It must not be interactive; the tile is one target and nothing nests inside
|
|
214
|
+
* it. Because the wrapper is `aria-hidden`, a control passed here would
|
|
215
|
+
* be reachable by Tab and absent from the accessibility tree at the same
|
|
216
|
+
* time. Nothing here checks that, so this sentence is the whole guard, and
|
|
217
|
+
* the page's claim that nothing inside a tile is focusable is scoped to what
|
|
218
|
+
* this component controls.
|
|
219
|
+
*/
|
|
220
|
+
icon?: ReactNode;
|
|
221
|
+
/**
|
|
222
|
+
* Where the tile leads. With it the whole tile is one link, meeting the
|
|
223
|
+
* target floor on both axes; without it the tile is a static readout. A
|
|
224
|
+
* clinical tile with nowhere to go raises a question the product refuses to
|
|
225
|
+
* answer, so most tiles should have one.
|
|
226
|
+
*
|
|
227
|
+
* With an `href` the tile renders a trailing chevron and underlines its label
|
|
228
|
+
* on hover and on keyboard focus, so a reader on a touch screen can see the
|
|
229
|
+
* tile is a door without hovering it. A static tile shows neither.
|
|
230
|
+
*
|
|
231
|
+
* ONE CONSTRAINT COMES WITH THE LINK, and it is named here because a product
|
|
232
|
+
* choosing a unit is the one who meets it. A link takes its accessible name
|
|
233
|
+
* from its content, and Value hides the unit SYMBOL from assistive technology
|
|
234
|
+
* and substitutes the spoken form. So a tile whose visible text reads "kg" is
|
|
235
|
+
* announced "kilograms", and the link's visible label shares no substring with
|
|
236
|
+
* its name. That is WCAG 2.2 SC 2.5.3, and this component cannot repair it: an
|
|
237
|
+
* `aria-label` would replace the whole sentence rather than mend one clause of
|
|
238
|
+
* it, so none is offered. It does not arise for a unit whose symbol and spoken
|
|
239
|
+
* form are the same word. It is recorded on the component's page rather than
|
|
240
|
+
* left to be discovered.
|
|
241
|
+
*/
|
|
242
|
+
href?: string;
|
|
243
|
+
/**
|
|
244
|
+
* The product's own router link element, rendered in place of the plain
|
|
245
|
+
* anchor while keeping the tile's `href`, its `data-slot="metric-tile"`, its
|
|
246
|
+
* shape and its target floor on it. Pass a Next or React Router link here so
|
|
247
|
+
* a tap navigates client-side rather than reloading the page. Inert without
|
|
248
|
+
* an `href`, because the tile is a static readout with nowhere to go and
|
|
249
|
+
* nothing to route.
|
|
250
|
+
*
|
|
251
|
+
* WHY THE TILE TAKES THE SLOT RATHER THAN THE Link COMPONENT. Link is the
|
|
252
|
+
* seventh actions-and-forms component and the five action-bearing cards route
|
|
253
|
+
* their action anchors through it, but a tile is not one of those cases. Its
|
|
254
|
+
* anchor is a WRAPPER: it carries the tile's own `data-slot`, its shape and
|
|
255
|
+
* `text-inherit no-underline`, so the whole tile is one target and one object
|
|
256
|
+
* in the accessibility tree. Wrapping the tile in a `Link` would move
|
|
257
|
+
* `data-slot="link"` onto a foreign root and put an action link's box around a
|
|
258
|
+
* whole card, so this file keeps its own anchor and takes the escape hatch
|
|
259
|
+
* `Field.Control` offers instead: the element is the tile, not a control
|
|
260
|
+
* inside it. The merge follows Link's: the tile's attributes win over the
|
|
261
|
+
* router element's and the class lists are joined so neither deletes the
|
|
262
|
+
* other.
|
|
263
|
+
*/
|
|
264
|
+
render?: ReactElement;
|
|
265
|
+
/**
|
|
266
|
+
* BCP 47 locale for the number, its separators and the date. Passed through
|
|
267
|
+
* to Value and to RelativeTime together, so the reading and its timestamp
|
|
268
|
+
* cannot show two conventions on one tile. Omitted, the reader's own
|
|
269
|
+
* environment decides.
|
|
270
|
+
*/
|
|
271
|
+
locale?: string;
|
|
272
|
+
/**
|
|
273
|
+
* IANA time zone name, for example `"Europe/London"`, for the exact date the
|
|
274
|
+
* timestamp carries. Passed straight to RelativeTime, so the tile does not
|
|
275
|
+
* read it itself. Give the reader's own zone to put the reading on their wall
|
|
276
|
+
* clock; omitted, RelativeTime keeps the stored instant and labels its offset
|
|
277
|
+
* rather than guessing a zone. A name RelativeTime does not recognise is
|
|
278
|
+
* refused rather than approximated, on the same rule that governs it there.
|
|
279
|
+
*/
|
|
280
|
+
timeZone?: string;
|
|
281
|
+
/**
|
|
282
|
+
* Forwarded to the RelativeTime on the time line, which owns the offset
|
|
283
|
+
* label. A tile whose reading the reader's own device took passes `false`,
|
|
284
|
+
* because a zone that cannot differ from the reader's own is not worth naming
|
|
285
|
+
* and "UTC+1" is not a phrase a layperson reaches for. Omitted, RelativeTime's
|
|
286
|
+
* default stands and the offset is labelled, which is right for a reading that
|
|
287
|
+
* may have crossed zones. This component sets no default of its own and makes
|
|
288
|
+
* no such claim, because it cannot tell where the number came from, so the
|
|
289
|
+
* caller decides.
|
|
290
|
+
*/
|
|
291
|
+
showOffset?: boolean;
|
|
292
|
+
/**
|
|
293
|
+
* Merged onto the root with `tailwind-merge`, and a class passed here wins
|
|
294
|
+
* where the two conflict. That includes `truncate` and a fixed height, either
|
|
295
|
+
* of which can take digits off the end of a reading at 200% text. This
|
|
296
|
+
* component sets neither and never shortens a number on its own.
|
|
297
|
+
*/
|
|
298
|
+
className?: string;
|
|
299
|
+
}
|
|
300
|
+
export declare function MetricTile({ label, value, unit, precision, measuredAt, event, now, staleAfterHours, status, category, icon, href, render, locale, timeZone, showOffset, className, }: MetricTileProps): import("react").JSX.Element | null;
|
|
301
|
+
//# sourceMappingURL=metric-tile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metric-tile.d.ts","sourceRoot":"","sources":["../../src/components/metric-tile.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwFG;AAEH,OAAO,EAAgC,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAIvF,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAgB,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAmOlE,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;;;;;OASG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;;;;;OAQG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;;;;;;;;;;;;;;;OAgBG;IACH,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB;;;;;;;OAOG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB;;;OAGG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAA;IACzB;;;;;;;;;;;;;;OAcG;IACH,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,KAAK,EACL,IAAI,EACJ,SAAS,EACT,UAAU,EACV,KAAkB,EAClB,GAAG,EACH,eAAe,EACf,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,MAAM,EACN,QAAQ,EACR,UAAU,EACV,SAAS,GACV,EAAE,eAAe,sCA8YjB"}
|