@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,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EmptyState is what a surface says when there is nothing on it, and what
|
|
3
|
+
* to do about that.
|
|
4
|
+
*
|
|
5
|
+
* THIS COMPONENT WRITES NO SENTENCE ABOUT THE READER. No default body, no
|
|
6
|
+
* default disclaimer, no emergency number, no threshold, and above all no
|
|
7
|
+
* reassuring line about an absence. It is the whole design, and it is why `reason` is required
|
|
8
|
+
* while nothing about `reason` is visible for the four empties: they need four
|
|
9
|
+
* different sentences, and a component that picked one would be writing a
|
|
10
|
+
* sentence about somebody's own health data on the product's behalf. opsinjs
|
|
11
|
+
* does not know the reader, so it does not get to say what an absence means to
|
|
12
|
+
* them.
|
|
13
|
+
*
|
|
14
|
+
* THE FIFTH REASON IS THE EXCEPTION, AND IT HAS TO BE. `could-not-load` is not
|
|
15
|
+
* an empty at all. The system tried to fetch and failed, so the space holds an
|
|
16
|
+
* error rather than an absence, and the two must never look alike. A reader who
|
|
17
|
+
* takes a failed load for an empty list is told their readings are gone when
|
|
18
|
+
* they are only unreachable, which is a falsehood about their own record. So
|
|
19
|
+
* this one reason does render something of its own: a neutral word and an icon
|
|
20
|
+
* that say the system failed, carried by no status colour and no category
|
|
21
|
+
* colour, because a failed fetch is neither a clinical level nor a kind of
|
|
22
|
+
* measurement. It is also the one reason whose action is mandatory, since an
|
|
23
|
+
* error that offers no way back is the failure the state exists to prevent, and
|
|
24
|
+
* the one state that renders no digit of any kind.
|
|
25
|
+
*
|
|
26
|
+
* THE REFUSAL THAT MATTERS MOST. An empty health surface is the easiest place
|
|
27
|
+
* in a product to be accidentally cheerful. "Nothing to see here!", "All
|
|
28
|
+
* clear" and "You're all caught up" are each a clinical claim the product
|
|
29
|
+
* cannot make. A reader with no results has an empty list, not a verdict. So
|
|
30
|
+
* when no body copy arrives, this component says in words that no explanation
|
|
31
|
+
* was supplied rather than inventing a friendly one. There are four
|
|
32
|
+
* reader-facing strings in this file. Two are the missing-body and
|
|
33
|
+
* missing-title admissions; two belong to the error state, the "Could not
|
|
34
|
+
* load" marker and the line shown when an error carries no way back. Every one
|
|
35
|
+
* of them is an admission or a statement about the system, never a sentence
|
|
36
|
+
* about the reader. All of them are written for the reader rather than the
|
|
37
|
+
* developer: an author who sees one on a screen fixes it, and a reader who
|
|
38
|
+
* sees one has at least not been told something untrue.
|
|
39
|
+
*
|
|
40
|
+
* `not-enough` IS THE SAFETY CASE and the reason `reason` exists at all. "There
|
|
41
|
+
* is data, but not enough for this view to be honest" is the empty state a
|
|
42
|
+
* TrendSparkline falls back to rather than drawing a line two readings do not
|
|
43
|
+
* support. Its body is not decoration; it is the statement of the rule and the
|
|
44
|
+
* gap, and it is missing more often than any of the other three.
|
|
45
|
+
*
|
|
46
|
+
* IT MOUNTS NO LIVE REGION. A view that becomes empty after a filter change
|
|
47
|
+
* should be announced once, politely. That announcement belongs to the region
|
|
48
|
+
* that changed, not to the component that happens to be inside it. A component
|
|
49
|
+
* that mounted its own `role="status"` would speak on every keystroke of a
|
|
50
|
+
* search field and would speak twice wherever the caller had already done the
|
|
51
|
+
* right thing.
|
|
52
|
+
*
|
|
53
|
+
* IT IS A SERVER COMPONENT. It holds no state and calls no hook. `onSelect`
|
|
54
|
+
* does not change that: a function cannot cross the server/client boundary, so
|
|
55
|
+
* an EmptyState given one is being rendered by a client component already, and
|
|
56
|
+
* this file joins that graph without a directive of its own. The `href` form
|
|
57
|
+
* stays server-rendered, which is the form to prefer.
|
|
58
|
+
*/
|
|
59
|
+
import { type ReactNode } from "react";
|
|
60
|
+
export interface EmptyStateProps {
|
|
61
|
+
/**
|
|
62
|
+
* Why the surface is empty. Required, and it deliberately changes nothing you
|
|
63
|
+
* can see.
|
|
64
|
+
*
|
|
65
|
+
* `nothing-yet` means the reader has not added anything yet.
|
|
66
|
+
* `no-matches` means a filter or a search matched nothing. The data exists.
|
|
67
|
+
* `nothing-left` means there was content and there is none now; everything
|
|
68
|
+
* was completed or removed.
|
|
69
|
+
* `not-enough` means there is data, but not enough for this view to be
|
|
70
|
+
* honest.
|
|
71
|
+
* `could-not-load` means the system tried to fetch and failed. This is a
|
|
72
|
+
* state about the system and not about the person: the reading is not
|
|
73
|
+
* missing, the request failed. It is the one reason that renders a visible
|
|
74
|
+
* marker of its own and the one reason whose `action` is mandatory, because
|
|
75
|
+
* an error must always offer a retry or a route onwards.
|
|
76
|
+
*
|
|
77
|
+
* It is required because each one needs different words, and because two of
|
|
78
|
+
* them carry more than an inconvenience: `not-enough` is a safety statement,
|
|
79
|
+
* and `could-not-load` is an error that must not be mistaken for an absence.
|
|
80
|
+
* The four empties render nothing of their own, because a component that
|
|
81
|
+
* turned an empty into a sentence would be writing a sentence about the
|
|
82
|
+
* reader's data, which is the one thing this system will not do.
|
|
83
|
+
* `could-not-load` is the deliberate exception: it renders a neutral word and
|
|
84
|
+
* an icon so a failed load never reads as an empty list, and it takes neither
|
|
85
|
+
* axis of colour.
|
|
86
|
+
*/
|
|
87
|
+
reason: "nothing-yet" | "no-matches" | "nothing-left" | "not-enough" | "could-not-load";
|
|
88
|
+
/**
|
|
89
|
+
* What is not here, in one short line. Rendered as a real heading so the
|
|
90
|
+
* empty state can be navigated to rather than stumbled into.
|
|
91
|
+
*
|
|
92
|
+
* Required, and checked as well as typed. A blank or whitespace-only string
|
|
93
|
+
* renders a visible line saying the screen has no heading, and warns. It warns
|
|
94
|
+
* because the alternative is a heading with no name, which is silent to
|
|
95
|
+
* everything except a screen reader and an audit.
|
|
96
|
+
*/
|
|
97
|
+
title: string;
|
|
98
|
+
/**
|
|
99
|
+
* The heading level the surrounding page needs. There is no way for this
|
|
100
|
+
* component to know it, because an empty state replacing a page's main
|
|
101
|
+
* content wants a different level from one inside a card. So `2` is a
|
|
102
|
+
* starting point and not an answer. Check it against the outline of the
|
|
103
|
+
* screen it lands on.
|
|
104
|
+
*
|
|
105
|
+
* @default 2
|
|
106
|
+
*/
|
|
107
|
+
titleLevel?: 2 | 3 | 4 | 5 | 6;
|
|
108
|
+
/**
|
|
109
|
+
* Why it is empty, in one or two sentences. Say what is not here, then why,
|
|
110
|
+
* then what to do; for `not-enough`, state the rule and the gap. It renders a
|
|
111
|
+
* paragraph, so it takes text or inline content rather than a block element.
|
|
112
|
+
*
|
|
113
|
+
* Omitting it does not produce a tidier empty state. It produces a visible
|
|
114
|
+
* line saying there is nothing here and the app does not say why, because the
|
|
115
|
+
* alternative is a default sentence about an absence of health data, which is
|
|
116
|
+
* a sentence nobody reviewed. `false` from a `&&` branch, an empty array and a
|
|
117
|
+
* whitespace-only string all count as omitting it.
|
|
118
|
+
*
|
|
119
|
+
* A body that is only a number is refused outright and replaced with the
|
|
120
|
+
* same line, because `{items.length && "…"}` at a length of zero renders the
|
|
121
|
+
* digit `0`. An absence rendered as a number reads as a measurement of
|
|
122
|
+
* nothing.
|
|
123
|
+
*/
|
|
124
|
+
children?: ReactNode;
|
|
125
|
+
/**
|
|
126
|
+
* Exactly one primary action, or none. Never a row of three.
|
|
127
|
+
*
|
|
128
|
+
* `href` navigates and renders an anchor; `onSelect` acts and renders a
|
|
129
|
+
* Button. Supply one of the two. A control that produces a new URL is a link
|
|
130
|
+
* however it is styled, and rebuilding it as a button loses the new tab, the
|
|
131
|
+
* copied address and the screen reader's list of links.
|
|
132
|
+
*
|
|
133
|
+
* Optional for the four empties, mandatory for `could-not-load`. An error
|
|
134
|
+
* that offers no way back is the one thing this state exists to prevent, so
|
|
135
|
+
* when the reason is `could-not-load` and no usable control renders, the
|
|
136
|
+
* surface shows a visible refusal in its place and warns in development.
|
|
137
|
+
*/
|
|
138
|
+
action?: {
|
|
139
|
+
label: string;
|
|
140
|
+
href?: string;
|
|
141
|
+
onSelect?: () => void;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* A quieter alternative, for the reader who cannot take the primary one. Same
|
|
145
|
+
* shape and same rule; it is not a second primary action, and it does not
|
|
146
|
+
* belong here on its own.
|
|
147
|
+
*/
|
|
148
|
+
secondary?: {
|
|
149
|
+
label: string;
|
|
150
|
+
href?: string;
|
|
151
|
+
onSelect?: () => void;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Decorative only, and never the carrier of the message. It is hidden from
|
|
155
|
+
* assistive technology and made `inert`, dropped in print, and dropped again
|
|
156
|
+
* when the surface is narrow. If a picture is carrying meaning, the meaning
|
|
157
|
+
* is missing from the words.
|
|
158
|
+
*
|
|
159
|
+
* `inert` is why nothing focusable belongs here: a control inside a decorative
|
|
160
|
+
* wrapper would be hidden from the accessibility tree and unreachable by
|
|
161
|
+
* keyboard, which is a worse outcome than not passing it.
|
|
162
|
+
*/
|
|
163
|
+
illustration?: ReactNode;
|
|
164
|
+
/**
|
|
165
|
+
* Merged onto the root. Width, position and place in a grid belong here: they
|
|
166
|
+
* are decisions of the screen this is standing in for, not of this component.
|
|
167
|
+
*/
|
|
168
|
+
className?: string;
|
|
169
|
+
}
|
|
170
|
+
export declare function EmptyState({ reason, title, titleLevel, children, action, secondary, illustration, className, }: EmptyStateProps): import("react").JSX.Element;
|
|
171
|
+
//# sourceMappingURL=empty-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"empty-state.d.ts","sourceRoot":"","sources":["../../src/components/empty-state.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAEH,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAiFhD,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,MAAM,EACF,aAAa,GACb,YAAY,GACZ,cAAc,GACd,YAAY,GACZ,gBAAgB,CAAA;IACpB;;;;;;;;OAQG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC9B;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE,CAAA;IAChE;;;;OAIG;IACH,SAAS,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE,CAAA;IACnE;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,SAAS,CAAA;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AA0ID,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,UAAc,EACd,QAAQ,EACR,MAAM,EACN,SAAS,EACT,YAAY,EACZ,SAAS,GACV,EAAE,eAAe,+BAyRjB"}
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* EmptyState is what a surface says when there is nothing on it, and what
|
|
4
|
+
* to do about that.
|
|
5
|
+
*
|
|
6
|
+
* THIS COMPONENT WRITES NO SENTENCE ABOUT THE READER. No default body, no
|
|
7
|
+
* default disclaimer, no emergency number, no threshold, and above all no
|
|
8
|
+
* reassuring line about an absence. It is the whole design, and it is why `reason` is required
|
|
9
|
+
* while nothing about `reason` is visible for the four empties: they need four
|
|
10
|
+
* different sentences, and a component that picked one would be writing a
|
|
11
|
+
* sentence about somebody's own health data on the product's behalf. opsinjs
|
|
12
|
+
* does not know the reader, so it does not get to say what an absence means to
|
|
13
|
+
* them.
|
|
14
|
+
*
|
|
15
|
+
* THE FIFTH REASON IS THE EXCEPTION, AND IT HAS TO BE. `could-not-load` is not
|
|
16
|
+
* an empty at all. The system tried to fetch and failed, so the space holds an
|
|
17
|
+
* error rather than an absence, and the two must never look alike. A reader who
|
|
18
|
+
* takes a failed load for an empty list is told their readings are gone when
|
|
19
|
+
* they are only unreachable, which is a falsehood about their own record. So
|
|
20
|
+
* this one reason does render something of its own: a neutral word and an icon
|
|
21
|
+
* that say the system failed, carried by no status colour and no category
|
|
22
|
+
* colour, because a failed fetch is neither a clinical level nor a kind of
|
|
23
|
+
* measurement. It is also the one reason whose action is mandatory, since an
|
|
24
|
+
* error that offers no way back is the failure the state exists to prevent, and
|
|
25
|
+
* the one state that renders no digit of any kind.
|
|
26
|
+
*
|
|
27
|
+
* THE REFUSAL THAT MATTERS MOST. An empty health surface is the easiest place
|
|
28
|
+
* in a product to be accidentally cheerful. "Nothing to see here!", "All
|
|
29
|
+
* clear" and "You're all caught up" are each a clinical claim the product
|
|
30
|
+
* cannot make. A reader with no results has an empty list, not a verdict. So
|
|
31
|
+
* when no body copy arrives, this component says in words that no explanation
|
|
32
|
+
* was supplied rather than inventing a friendly one. There are four
|
|
33
|
+
* reader-facing strings in this file. Two are the missing-body and
|
|
34
|
+
* missing-title admissions; two belong to the error state, the "Could not
|
|
35
|
+
* load" marker and the line shown when an error carries no way back. Every one
|
|
36
|
+
* of them is an admission or a statement about the system, never a sentence
|
|
37
|
+
* about the reader. All of them are written for the reader rather than the
|
|
38
|
+
* developer: an author who sees one on a screen fixes it, and a reader who
|
|
39
|
+
* sees one has at least not been told something untrue.
|
|
40
|
+
*
|
|
41
|
+
* `not-enough` IS THE SAFETY CASE and the reason `reason` exists at all. "There
|
|
42
|
+
* is data, but not enough for this view to be honest" is the empty state a
|
|
43
|
+
* TrendSparkline falls back to rather than drawing a line two readings do not
|
|
44
|
+
* support. Its body is not decoration; it is the statement of the rule and the
|
|
45
|
+
* gap, and it is missing more often than any of the other three.
|
|
46
|
+
*
|
|
47
|
+
* IT MOUNTS NO LIVE REGION. A view that becomes empty after a filter change
|
|
48
|
+
* should be announced once, politely. That announcement belongs to the region
|
|
49
|
+
* that changed, not to the component that happens to be inside it. A component
|
|
50
|
+
* that mounted its own `role="status"` would speak on every keystroke of a
|
|
51
|
+
* search field and would speak twice wherever the caller had already done the
|
|
52
|
+
* right thing.
|
|
53
|
+
*
|
|
54
|
+
* IT IS A SERVER COMPONENT. It holds no state and calls no hook. `onSelect`
|
|
55
|
+
* does not change that: a function cannot cross the server/client boundary, so
|
|
56
|
+
* an EmptyState given one is being rendered by a client component already, and
|
|
57
|
+
* this file joins that graph without a directive of its own. The `href` form
|
|
58
|
+
* stays server-rendered, which is the form to prefer.
|
|
59
|
+
*/
|
|
60
|
+
import { Children } from "react";
|
|
61
|
+
import { TriangleAlert } from "lucide-react";
|
|
62
|
+
import { isDevelopment } from "../opsinjs.js";
|
|
63
|
+
import { cn } from "../utils.js";
|
|
64
|
+
import { Button, cardActionClassName } from "./button.js";
|
|
65
|
+
import { Link } from "./link.js";
|
|
66
|
+
/**
|
|
67
|
+
* Development warnings, said once per distinct offender.
|
|
68
|
+
*
|
|
69
|
+
* `warnOnce` in the substrate is keyed to an `OpsinErrorCode`, and the codes in
|
|
70
|
+
* tokens/errors.json describe mistakes a consumer makes with the CLINICAL API.
|
|
71
|
+
* Nothing this file complains about has a code, and a component may not mint
|
|
72
|
+
* one. The codes are a versioned contract and the table on the errors page is
|
|
73
|
+
* generated from that file. What the substrate is right about is the discipline
|
|
74
|
+
* rather than the registry: a warning printed on every render, and twice per
|
|
75
|
+
* render under Strict Mode, degrades into noise, and a noisy channel is one
|
|
76
|
+
* somebody switches off. So this file keeps its own small set, keyed the way
|
|
77
|
+
* `warnOnce` keys its own. The key combines the complaint with whatever names
|
|
78
|
+
* the offender.
|
|
79
|
+
*
|
|
80
|
+
* The key is coarser than "once per call site", because a call site is not
|
|
81
|
+
* observable from inside a function. Two empty states with the same title and
|
|
82
|
+
* the same mistake share one warning. That is the most this can honestly
|
|
83
|
+
* promise, and it is still better than the same sentence on every keystroke.
|
|
84
|
+
* Allocating real codes and deleting this belongs in ../opsinjs.ts.
|
|
85
|
+
*/
|
|
86
|
+
const warned = new Set();
|
|
87
|
+
function warnDev(key, message) {
|
|
88
|
+
if (!isDevelopment() || warned.has(key))
|
|
89
|
+
return;
|
|
90
|
+
warned.add(key);
|
|
91
|
+
console.warn(message);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The rendered text of `children`, or `null` when there will not be any.
|
|
95
|
+
*
|
|
96
|
+
* TypeScript cannot see this. Testing the three sentinels `""`, `null` and
|
|
97
|
+
* `undefined` misses the way a body actually goes missing. It goes missing as
|
|
98
|
+
* `{rows.length > 0 && "…"}` evaluating to `false`, a whitespace-only string
|
|
99
|
+
* arriving from a translation table, or an empty array from a `.map()` that
|
|
100
|
+
* matched nothing. `Children.toArray` drops `null`, `undefined`, booleans and
|
|
101
|
+
* empty arrays for us; a string that is all whitespace is what it keeps and we
|
|
102
|
+
* must still reject.
|
|
103
|
+
*
|
|
104
|
+
* Elements are not text and are not resolvable here, so a body containing one
|
|
105
|
+
* is taken at its word and returned as `""`. It is present but unreadable
|
|
106
|
+
* from here. That is the right way round: this function decides when to say
|
|
107
|
+
* *nothing was supplied*, and saying it over somebody's `<strong>` would be a
|
|
108
|
+
* false accusation printed on their screen.
|
|
109
|
+
*/
|
|
110
|
+
function bodyText(children) {
|
|
111
|
+
const parts = Children.toArray(children);
|
|
112
|
+
if (parts.length === 0)
|
|
113
|
+
return null;
|
|
114
|
+
if (!parts.every((part) => typeof part === "string" || typeof part === "number")) {
|
|
115
|
+
return "";
|
|
116
|
+
}
|
|
117
|
+
const text = parts.map((part) => String(part)).join("").trim();
|
|
118
|
+
return text === "" ? null : text;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Whether the whole body is a bare number.
|
|
122
|
+
*
|
|
123
|
+
* `{items.length && "…"}` with a length of zero passes `0`, and React renders
|
|
124
|
+
* the digit. On an empty health surface that is the failure
|
|
125
|
+
* [numbers-units-precision] rule 13 names outright. Zero, none and unknown are
|
|
126
|
+
* three different things, and an absence is never rendered as `0`. It is also
|
|
127
|
+
* checklist A4: the states have to stay distinguishable, and a `0` where a
|
|
128
|
+
* sentence belongs makes an absence look like a measurement of nothing.
|
|
129
|
+
*
|
|
130
|
+
* A body that is only a number is a caller bug at every value and not only at
|
|
131
|
+
* zero: it explains nothing about why the surface is empty. So it is refused
|
|
132
|
+
* rather than printed, and the same missing-body line takes its place.
|
|
133
|
+
*/
|
|
134
|
+
function bodyIsBareNumber(text) {
|
|
135
|
+
return text !== null && /^-?\d+(?:[.,]\d+)?$/.test(text);
|
|
136
|
+
}
|
|
137
|
+
/* THE NAVIGATING ACTION NOW RENDERS THROUGH THE SHARED Link. Before Link was a
|
|
138
|
+
built component, this file spelled its own anchor here: a TARGET_FLOOR, an
|
|
139
|
+
ACTION_LINK and a SECONDARY_LINK class string. ACTION_LINK was the byte-
|
|
140
|
+
identical copy shared across alert-banner.tsx, result-card.tsx and this file,
|
|
141
|
+
which is the duplication the roster finding named. The quiet constant was a
|
|
142
|
+
different story: it shared only its name with AlertBanner's SECONDARY_LINK and
|
|
143
|
+
differed from it by a boundary and its padding, AlertBanner's carrying border
|
|
144
|
+
border-border and px-opsin-4 against this file's borderless px-opsin-2. That
|
|
145
|
+
divergence under one name was finding cross-component-consistency-14, and
|
|
146
|
+
result-card.tsx never had a SECONDARY_LINK at all. Link closes both, because
|
|
147
|
+
it is the one place those treatments are decided, so a banner's action and an
|
|
148
|
+
empty state's action are the same control on the same screen. The target
|
|
149
|
+
floor, the boundary, the type step and the focus ring that used to live in
|
|
150
|
+
these constants are the card action recipe's now, carried by Link's `action`
|
|
151
|
+
and `secondary` emphases on a neutral ground.
|
|
152
|
+
|
|
153
|
+
The floor is a minimum on both axes, not height alone. SC 2.5.8 is a 44 by 44
|
|
154
|
+
region rather than a 44-tall strip, and the product stylesheet floors only
|
|
155
|
+
`button`, `[role=button]` and `a[data-opsin-target]`, so a quiet action whose
|
|
156
|
+
padding is a third of the recommended one's can fall under the floor on the
|
|
157
|
+
inline axis without the min-width. That reason should live beside the shared
|
|
158
|
+
CARD_ACTION_FLOOR fragment in button.tsx, where every adopter draws from it;
|
|
159
|
+
the crossUnitNotes on 14.b ask comp:button to carry it there. */
|
|
160
|
+
/**
|
|
161
|
+
* Turn one action into a control, or into nothing.
|
|
162
|
+
*
|
|
163
|
+
* Returning `null` rather than rendering something is the point. A control with
|
|
164
|
+
* no name is unreachable by voice and announced as "button"; a control with
|
|
165
|
+
* neither a destination nor a handler is a promise the surface cannot keep, and
|
|
166
|
+
* an empty state whose one next step does nothing is worse than an empty state
|
|
167
|
+
* with no step at all.
|
|
168
|
+
*
|
|
169
|
+
* None of these is an OPSIN code. `tokens/errors.json` allocates codes for
|
|
170
|
+
* mistakes a consumer makes with the clinical API, and a component may not mint
|
|
171
|
+
* one. The codes are a versioned contract and the table on the errors page is
|
|
172
|
+
* generated from that file. A development warning through `warnDev` is the
|
|
173
|
+
* honest channel, and `owner` is what gives it per-empty-state granularity.
|
|
174
|
+
*/
|
|
175
|
+
function actionControl(action, emphasis, owner) {
|
|
176
|
+
const label = action.label?.trim() ? action.label : "";
|
|
177
|
+
const navigates = typeof action.href === "string" && action.href.trim() !== "";
|
|
178
|
+
const acts = typeof action.onSelect === "function";
|
|
179
|
+
if (label === "") {
|
|
180
|
+
warnDev(`action-no-label:${emphasis}:${owner}`, `[opsinjs] <EmptyState> titled "${owner}" was given an action with no ` +
|
|
181
|
+
"label. The visible label is the accessible name, and an empty " +
|
|
182
|
+
"state's one next step is the whole reason the surface is worth " +
|
|
183
|
+
"showing. Nothing was rendered for it.");
|
|
184
|
+
}
|
|
185
|
+
if (label !== "" && !navigates && !acts) {
|
|
186
|
+
warnDev(`action-inert:${label}`, `[opsinjs] <EmptyState> was given the action "${label}" with neither ` +
|
|
187
|
+
"`href` nor `onSelect`, so there is nothing for it to do. Give it a " +
|
|
188
|
+
"destination or a handler; a control that acknowledges a press and " +
|
|
189
|
+
"then does nothing reads as a broken screen. Nothing was rendered for " +
|
|
190
|
+
"it.");
|
|
191
|
+
}
|
|
192
|
+
if (navigates && acts) {
|
|
193
|
+
warnDev(`action-both:${label}`, `[opsinjs] <EmptyState> was given the action "${label}" with both ` +
|
|
194
|
+
"`href` and `onSelect`. It renders as a link, because a destination " +
|
|
195
|
+
"survives a new tab, a copied address and a screen reader's list of " +
|
|
196
|
+
"links and a handler does not. Move the work to the page the link " +
|
|
197
|
+
"goes to, or drop the `href`.");
|
|
198
|
+
}
|
|
199
|
+
if (label === "")
|
|
200
|
+
return null;
|
|
201
|
+
if (navigates && action.href) {
|
|
202
|
+
return (_jsx(Link, { href: action.href, emphasis: emphasis === "primary" ? "action" : "secondary", children: label }));
|
|
203
|
+
}
|
|
204
|
+
if (!acts)
|
|
205
|
+
return null;
|
|
206
|
+
/* NO BRAND FILL ON THE ACTING FORM. `Button variant="primary"` is `bg-primary`
|
|
207
|
+
on `text-primary-foreground`, and the navigating form above is `<Link
|
|
208
|
+
emphasis="action">`, a neutral outlined capsule on `bg-card`.
|
|
209
|
+
Reaching for the brand fill here made the same recommended action carry a
|
|
210
|
+
solid blue button on `onSelect` and a quiet link on `href`, so the reader met
|
|
211
|
+
two different amounts of emphasis for one step depending on a prop they cannot
|
|
212
|
+
see. `secondary` is `bg-card` with `text-foreground`, which is the pair the
|
|
213
|
+
card action recipe behind `emphasis="action"` spells, so the two transports of
|
|
214
|
+
`action` read alike. The size follows for the same motive: the recipe's quiet
|
|
215
|
+
arm takes the smaller subheadline step, so the quiet form rendered as a Button
|
|
216
|
+
takes `sm` and its two transports stop reading as different weights too.
|
|
217
|
+
AlertBanner makes the identical mapping. */
|
|
218
|
+
return (_jsx(Button, { variant: emphasis === "primary" ? "secondary" : "quiet", size: emphasis === "primary" ? "md" : "sm",
|
|
219
|
+
/* The recipe and Button's quiet rung now agree on one ink, the accent
|
|
220
|
+
ink (ADR 0029), so the quiet action reads the same on `onSelect` as on
|
|
221
|
+
`href` with no override here. The recommended branch needs nothing
|
|
222
|
+
either: Button variant="secondary" already carries the foreground ink
|
|
223
|
+
and the boundary the recipe's recommended link arm draws. */
|
|
224
|
+
className: cardActionClassName({
|
|
225
|
+
weight: emphasis === "primary" ? "recommended" : "quiet",
|
|
226
|
+
ground: "neutral",
|
|
227
|
+
as: "button",
|
|
228
|
+
}), onClick: action.onSelect, children: label }));
|
|
229
|
+
}
|
|
230
|
+
export function EmptyState({ reason, title, titleLevel = 2, children, action, secondary, illustration, className, }) {
|
|
231
|
+
/* THE ONE PLACE THIS COMPONENT REFUSES TO BE HELPFUL.
|
|
232
|
+
A missing body is the common case and the dangerous one: the title alone
|
|
233
|
+
says what is absent and never why, and the reader fills the gap with
|
|
234
|
+
whichever assumption is nearest to hand. That assumption is usually that
|
|
235
|
+
the absence is reassuring. `not-enough` is called out separately because
|
|
236
|
+
its body is not an explanation, it is the statement of the rule and the
|
|
237
|
+
gap, and a view that declined to draw something has to say what it is
|
|
238
|
+
waiting for. */
|
|
239
|
+
const body = bodyText(children);
|
|
240
|
+
const numericBody = bodyIsBareNumber(body);
|
|
241
|
+
const bodyMissing = body === null || numericBody;
|
|
242
|
+
/* The one reason that is not an absence. An error renders a visible marker
|
|
243
|
+
and owes a retry, so the component branches on it in three places below:
|
|
244
|
+
the flag above the heading, the mandatory-action warning, and the refusal
|
|
245
|
+
that stands in when no retry was given. */
|
|
246
|
+
const isError = reason === "could-not-load";
|
|
247
|
+
const heading = typeof title === "string" ? title.trim() : "";
|
|
248
|
+
const titleMissing = heading === "";
|
|
249
|
+
/* The title is required and the type says so, and this file still ships as
|
|
250
|
+
source into JavaScript projects where a type is advice. `title=""`
|
|
251
|
+
type-checks even here. An empty heading is a heading with no name: axe
|
|
252
|
+
reports it, a screen-reader user hears "heading level 3" and nothing, and
|
|
253
|
+
the empty state loses the handle the whole page argues it can be navigated
|
|
254
|
+
by. The action label two functions up is already checked this way; the
|
|
255
|
+
heading has more riding on it and was not. */
|
|
256
|
+
if (titleMissing) {
|
|
257
|
+
warnDev(`title-missing:${reason}`, `[opsinjs] <EmptyState reason="${reason}"> was rendered with no title, ` +
|
|
258
|
+
"so it says on screen that the screen has no heading. `title` is what is not " +
|
|
259
|
+
"here, in one short line, and it is the heading the empty state is " +
|
|
260
|
+
"navigated by. An empty one is announced as a heading with no name. " +
|
|
261
|
+
"Write it.");
|
|
262
|
+
}
|
|
263
|
+
if (numericBody) {
|
|
264
|
+
warnDev(`body-number:${reason}`, `[opsinjs] <EmptyState reason="${reason}"> was given the number ` +
|
|
265
|
+
`${String(body)} as its body, which is how \`{items.length && "…"}\` reads ` +
|
|
266
|
+
"when the length is zero. It was refused rather than printed: zero, " +
|
|
267
|
+
"none and unknown are three different things, and an absence rendered " +
|
|
268
|
+
"as a digit reads as a measurement of nothing. Write the sentence the " +
|
|
269
|
+
"conditional was guarding.");
|
|
270
|
+
}
|
|
271
|
+
else if (bodyMissing) {
|
|
272
|
+
warnDev(`body-missing:${reason}`, `[opsinjs] <EmptyState reason="${reason}"> was rendered with no body, so ` +
|
|
273
|
+
"it says on screen that there is nothing here and the app does not say why. That string is " +
|
|
274
|
+
"there because the alternative is a default sentence about missing " +
|
|
275
|
+
"health data, and this system does not own one. Note that `false` " +
|
|
276
|
+
"from a `&&` branch, an empty array and a whitespace-only string all " +
|
|
277
|
+
"count as no body. Write one or two sentences: what is not here, why, " +
|
|
278
|
+
"and what to do about it." +
|
|
279
|
+
(reason === "not-enough"
|
|
280
|
+
? " For `not-enough` the body is the safety statement. State the " +
|
|
281
|
+
"rule this view is waiting for and how far off it is."
|
|
282
|
+
: ""));
|
|
283
|
+
}
|
|
284
|
+
/* A quieter alternative with nothing to be an alternative to is a primary
|
|
285
|
+
action wearing quiet clothes, and it is how a surface ends up with its one
|
|
286
|
+
next step in the least prominent place on it. */
|
|
287
|
+
if (secondary !== undefined && action === undefined) {
|
|
288
|
+
warnDev(`secondary-alone:${heading || reason}`, "[opsinjs] <EmptyState> has a `secondary` action and no `action`. " +
|
|
289
|
+
"`secondary` is the quieter route for a reader who cannot take the " +
|
|
290
|
+
"primary one; on its own it renders the surface's only next step in " +
|
|
291
|
+
"its least prominent treatment. Promote it to `action`.");
|
|
292
|
+
}
|
|
293
|
+
const owner = heading || `reason="${reason}"`;
|
|
294
|
+
const primary = action ? actionControl(action, "primary", owner) : null;
|
|
295
|
+
const alternative = secondary ? actionControl(secondary, "quiet", owner) : null;
|
|
296
|
+
/* The retry or route is the whole obligation the error state exists to meet.
|
|
297
|
+
This keys on whether a control actually rendered rather than on whether
|
|
298
|
+
`action` was passed: a label-less action and one with neither `href` nor
|
|
299
|
+
`onSelect` both come back from actionControl as null, and each leaves a
|
|
300
|
+
silent error with no way back just as surely as a missing prop does. When
|
|
301
|
+
no control rendered this warns and a visible refusal takes its place below,
|
|
302
|
+
the same shape the missing-title and missing-body admissions use, because a
|
|
303
|
+
silent error that offers no way back is exactly the failure the state is
|
|
304
|
+
for. */
|
|
305
|
+
if (isError && primary === null) {
|
|
306
|
+
warnDev(`error-no-retry:${owner}`, `[opsinjs] <EmptyState reason="could-not-load"> was rendered with no ` +
|
|
307
|
+
"usable `action`, so it tells the reader the load did not complete and " +
|
|
308
|
+
"then offers no way back. An error state must carry a retry or a route " +
|
|
309
|
+
"onwards; that is the whole obligation the state exists to meet. A " +
|
|
310
|
+
"visible line saying no retry was offered took its place. Pass `action` " +
|
|
311
|
+
"with a handler that loads it again or a destination that routes around it.");
|
|
312
|
+
}
|
|
313
|
+
/* The level is the page's and the appearance is this component's. A heading
|
|
314
|
+
that hard-coded its level produces an outline which jumps from h1 to h3 on
|
|
315
|
+
one screen and a wall of h2s on another; `titleLevel` keeps the two
|
|
316
|
+
separable. The explicit type step and the zeroed margin below are what
|
|
317
|
+
stop the level carrying visual weight it is not entitled to. Left to the
|
|
318
|
+
browser, the same title would be a different size in an h2 and an h4.
|
|
319
|
+
|
|
320
|
+
AND THE LEVEL IS CHECKED, not merely typed, for the reason every other prop
|
|
321
|
+
here is checked: a type is advice in the JavaScript project this file ships
|
|
322
|
+
into, and a level is exactly the prop a caller computes rather than types.
|
|
323
|
+
Examples are `titleLevel={section.depth + 1}` and a number off a CMS row.
|
|
324
|
+
`titleLevel={7}` builds `<h7>`, an unknown element with no heading role at
|
|
325
|
+
all, so the one line saying what is not here drops out of the document
|
|
326
|
+
outline and out of a screen reader's heading list, which is the whole point
|
|
327
|
+
of rendering it as a heading. `titleLevel={1}` puts a second `h1` on the
|
|
328
|
+
page. Both fall back to the documented default rather than being rendered.
|
|
329
|
+
`care-card.tsx` guards its own `headingLevel` the same way and falls back
|
|
330
|
+
to its own default of 3; the shape travels, the number does not. */
|
|
331
|
+
const LEVELS = [2, 3, 4, 5, 6];
|
|
332
|
+
let level = titleLevel;
|
|
333
|
+
if (!LEVELS.includes(level)) {
|
|
334
|
+
warnDev(`title-level:${String(titleLevel)}`, `[opsinjs] <EmptyState> was given titleLevel ${String(titleLevel)}. The ` +
|
|
335
|
+
"title is a real heading and the level has to be one a document outline " +
|
|
336
|
+
"has: 2 to 6. An h1 makes an empty state compete with the page's own " +
|
|
337
|
+
"name and anything outside the range is not a heading element at all. " +
|
|
338
|
+
"It was rendered at the default, 2.");
|
|
339
|
+
level = 2;
|
|
340
|
+
}
|
|
341
|
+
const Heading = `h${String(level)}`;
|
|
342
|
+
return (_jsxs("div", { "data-slot": "empty-state", className: cn(
|
|
343
|
+
/* `@container` is what makes the illustration rule below work, and it
|
|
344
|
+
is worth the class on its own: the empty state is judged against the
|
|
345
|
+
space it was given rather than against the viewport, so the same
|
|
346
|
+
component drops its picture inside a narrow card and keeps it on a
|
|
347
|
+
full page. */
|
|
348
|
+
/* The outer inset is on Tailwind's density-scaled scale, `px-4 py-8`
|
|
349
|
+
rather than the fixed `px-opsin-*` tokens, so this box tightens with
|
|
350
|
+
the rest of the card family when a reader chooses compact. At the
|
|
351
|
+
default density `--spacing` is 0.25rem, so these render 16px by 32px,
|
|
352
|
+
the same values the fixed tokens gave; under compact they scale down
|
|
353
|
+
with Card, ResultCard, Callout and AlertBanner. */
|
|
354
|
+
"@container flex w-full flex-col items-center gap-opsin-4 px-4 py-8 text-center", className), children: [illustration ? (_jsx("div", { "data-slot": "empty-state-illustration", "aria-hidden": "true", inert: true, className: "@max-[17rem]:hidden print:hidden", children: illustration })) : null, isError ? (_jsxs("p", { "data-slot": "empty-state-error-flag",
|
|
355
|
+
/* The non-colour cue. An error has to be told apart from an absence
|
|
356
|
+
by a reader in greyscale and a reader with low vision, so the state
|
|
357
|
+
is carried by a word and an icon rather than by a tint. The border
|
|
358
|
+
is the neutral `--border` and the ink is `--foreground`; this takes
|
|
359
|
+
no status colour and no category colour, because a failed fetch is
|
|
360
|
+
neither a clinical level nor a kind of measurement. The glyph is
|
|
361
|
+
`aria-hidden` because the word beside it already says the same
|
|
362
|
+
thing, and it is sized in `em` so it follows the reader's text. */
|
|
363
|
+
className: "m-0 inline-flex items-center gap-opsin-2 rounded-opsin-md border border-border px-opsin-3 py-opsin-1 text-opsin-subheadline text-foreground", children: [_jsx(TriangleAlert, { "aria-hidden": "true", className: "size-[1em]" }), "Could not load"] })) : null, _jsx(Heading, { "data-slot": "empty-state-title",
|
|
364
|
+
/* `text-balance` rather than a width: a two-line title that breaks
|
|
365
|
+
after one word looks like a defect, and the alternative is guessing a
|
|
366
|
+
character count that is wrong at every text size but one. */
|
|
367
|
+
className: "m-0 text-opsin-headline text-balance", children: titleMissing ? "This screen has no heading." : heading }), _jsx("p", { "data-slot": "empty-state-body",
|
|
368
|
+
/* Full-strength foreground rather than a muted role. For `not-enough`
|
|
369
|
+
this paragraph is the safety statement, and a safety statement set in
|
|
370
|
+
the colour the system uses for supporting detail is a safety
|
|
371
|
+
statement that reads as supporting detail.
|
|
372
|
+
|
|
373
|
+
The measure is capped because the body is centred: centred text past
|
|
374
|
+
about 45 characters loses the reader's return sweep, and an empty
|
|
375
|
+
state is read once, quickly, by somebody who is already unsure what
|
|
376
|
+
they are looking at. */
|
|
377
|
+
className: "m-0 max-w-(--opsin-measure-tight,45ch) text-opsin-body text-foreground", children: bodyMissing
|
|
378
|
+
? "There is nothing here yet, and this app does not say why."
|
|
379
|
+
: children }), primary ? _jsx("div", { "data-slot": "empty-state-action", children: primary }) : null, isError && primary === null ? (_jsx("p", { "data-slot": "empty-state-error-no-retry",
|
|
380
|
+
/* The retry was mandatory and it was not supplied. Rather than fake a
|
|
381
|
+
control with nothing behind it, the surface admits in words that no
|
|
382
|
+
way back was offered, the same admission the missing title and the
|
|
383
|
+
missing body make. It renders no digit, as nothing in this state
|
|
384
|
+
ever does. An author who sees it wires up the retry. */
|
|
385
|
+
className: "m-0 max-w-(--opsin-measure-tight,45ch) text-opsin-body text-foreground", children: "This app has not offered a way to try again." })) : null, alternative ? (_jsx("div", { "data-slot": "empty-state-secondary", children: alternative })) : null] }));
|
|
386
|
+
}
|
|
387
|
+
//# sourceMappingURL=empty-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"empty-state.js","sourceRoot":"","sources":["../../src/components/empty-state.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAEH,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,aAAc,CAAA;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAY,CAAA;AAEjC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;AAEhC,SAAS,OAAO,CAAC,GAAW,EAAE,OAAe;IAC3C,IAAI,CAAC,aAAa,EAAE,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAM;IAC/C,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACf,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AACvB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAS,QAAQ,CAAC,QAAmB;IACnC,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACxC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACnC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO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