@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,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callout is a short piece of set-apart information that carries no clinical
|
|
3
|
+
* level at all.
|
|
4
|
+
*
|
|
5
|
+
* WHAT IT REFUSES IS THE COMPONENT. There is no `status` prop, no `severity`
|
|
6
|
+
* prop, no `color` prop, and no fourth variant called "warning". AlertBanner is
|
|
7
|
+
* the component that carries a clinical level: it is counted against the
|
|
8
|
+
* escalation budget, it is answerable to the two-axis rule, and a reviewer
|
|
9
|
+
* looking at a screen can find every one of them. A Callout that could be
|
|
10
|
+
* tinted amber would inherit all of that attention and none of the obligations,
|
|
11
|
+
* and nothing in review catches the difference, because the two render
|
|
12
|
+
* identically. So the refusal is the API rather than a paragraph in the
|
|
13
|
+
* documentation.
|
|
14
|
+
*
|
|
15
|
+
* WHICH IS WHY THE THREE VARIANTS SHARE ONE TREATMENT AND DIFFER ONLY BY GLYPH.
|
|
16
|
+
* The temptation with an admonition component is a tint per variant: blue for a
|
|
17
|
+
* note, green for a tip, yellow for a caveat. Yellow-for-a-caveat is the exact
|
|
18
|
+
* colour a reader has been taught means *watch* by every status surface on the
|
|
19
|
+
* screen. The product theme has no non-axis accent to reach for anyway:
|
|
20
|
+
* `packages/react/styles/theme.css` bridges eleven neutral surface roles plus
|
|
21
|
+
* the two axes, and nothing else exists. One neutral fill for all three is
|
|
22
|
+
* therefore both the available answer and the correct one. A variant buys a
|
|
23
|
+
* distinct glyph, and that is the whole of what it buys.
|
|
24
|
+
*
|
|
25
|
+
* IT STAMPS NO `data-variant`, DELIBERATELY. The data-attribute vocabulary is
|
|
26
|
+
* closed at four: `data-slot`, `data-status`, `data-opsinjs-value` and
|
|
27
|
+
* `data-category`. Spending a fifth on a distinction the specification
|
|
28
|
+
* itself describes as one whose loss "loses nothing" would be the wrong trade.
|
|
29
|
+
* A product that needs to style the note case differently from the tip case has
|
|
30
|
+
* `className`, and the reason it should not is the paragraph above.
|
|
31
|
+
*
|
|
32
|
+
* IT IS A SERVER COMPONENT. No state, no timers, no event handlers, no Base UI
|
|
33
|
+
* primitive. There is no dismiss control. A dismissible callout needs a name,
|
|
34
|
+
* a target floor and a memory that outlives the render, and none of those three
|
|
35
|
+
* has been designed. Its absence is why this file has no client boundary.
|
|
36
|
+
*/
|
|
37
|
+
import { type ReactNode } from "react";
|
|
38
|
+
/**
|
|
39
|
+
* Three variants, chosen so that none of them maps onto a clinical status
|
|
40
|
+
* level.
|
|
41
|
+
*
|
|
42
|
+
* `warning` is deliberately absent. A warning about a person's health is an
|
|
43
|
+
* AlertBanner; a warning about anything else is a caveat, which is what that
|
|
44
|
+
* third member is for.
|
|
45
|
+
*
|
|
46
|
+
* DECLARED, NOT EXPORTED, and the specification page writes `export type` here.
|
|
47
|
+
* A component file exports exactly two public symbols, the props interface and
|
|
48
|
+
* the component, now that the zero-prop demo lives in
|
|
49
|
+
* `apps/www/registry/demos/callout.tsx`. A third would be a third name
|
|
50
|
+
* @opsinjs/react publishes and a third thing this system has to keep stable. A
|
|
51
|
+
* wrapper that needs to name the three values writes `CalloutProps["variant"]`,
|
|
52
|
+
* which is the same union and cannot drift from it. `button.tsx` declares its
|
|
53
|
+
* own variant union the same way for the same reason.
|
|
54
|
+
*/
|
|
55
|
+
type CalloutVariant = "note" | "tip" | "caveat";
|
|
56
|
+
export interface CalloutProps {
|
|
57
|
+
/**
|
|
58
|
+
* Which of the three the callout is. Changes the glyph and nothing else: the
|
|
59
|
+
* fill, the ink and the boundary are identical for all three, so the variant
|
|
60
|
+
* survives greyscale by never having depended on colour.
|
|
61
|
+
*
|
|
62
|
+
* @default "note"
|
|
63
|
+
*/
|
|
64
|
+
variant?: CalloutVariant;
|
|
65
|
+
/**
|
|
66
|
+
* An optional short heading. It renders as styled text and not as an `h1`-`h6`
|
|
67
|
+
* element, so it never appears in the page's outline: a component cannot know
|
|
68
|
+
* which level it is nested at, and one that guessed would produce an outline
|
|
69
|
+
* that skips a level on some screens and repeats one on others. If the
|
|
70
|
+
* callout is a section a reader needs to navigate to, it needs a real heading
|
|
71
|
+
* outside it. At that point it is probably a section rather than a callout.
|
|
72
|
+
*
|
|
73
|
+
* An empty or whitespace-only string is treated exactly like no title at
|
|
74
|
+
* all: the element leaves the DOM rather than rendering an empty line of
|
|
75
|
+
* heading-weight space.
|
|
76
|
+
*/
|
|
77
|
+
title?: string;
|
|
78
|
+
/**
|
|
79
|
+
* The body: one short paragraph. There is no actions slot and no `action`
|
|
80
|
+
* prop. A callout that needs a button is asking the reader to do something,
|
|
81
|
+
* and an instruction with somebody behind it is a CareCard.
|
|
82
|
+
*/
|
|
83
|
+
children: ReactNode;
|
|
84
|
+
/**
|
|
85
|
+
* Merged onto the root. Layout belongs here. A callout sets no width and no
|
|
86
|
+
* margin, because both are decisions of the content it sits in.
|
|
87
|
+
*
|
|
88
|
+
* A colour from either axis is the one thing it will not pass through. Such a
|
|
89
|
+
* utility is removed from the list before it reaches the root, in every
|
|
90
|
+
* environment, so a callout can never be drawn in a status fill; development
|
|
91
|
+
* additionally warns once per distinct offending class list, naming the
|
|
92
|
+
* component to use instead. Every other class the caller writes is passed
|
|
93
|
+
* through untouched.
|
|
94
|
+
*/
|
|
95
|
+
className?: string;
|
|
96
|
+
}
|
|
97
|
+
export declare function Callout({ variant, title, children, className, }: CalloutProps): import("react").JSX.Element;
|
|
98
|
+
export {};
|
|
99
|
+
//# sourceMappingURL=callout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callout.d.ts","sourceRoot":"","sources":["../../src/components/callout.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAKhD;;;;;;;;;;;;;;;;GAgBG;AACH,KAAK,cAAc,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAA;AAuG/C,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,QAAQ,EAAE,SAAS,CAAA;IACnB;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAoFD,wBAAgB,OAAO,CAAC,EACtB,OAAgB,EAChB,KAAK,EACL,QAAQ,EACR,SAAS,GACV,EAAE,YAAY,+BAwJd"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Callout is a short piece of set-apart information that carries no clinical
|
|
4
|
+
* level at all.
|
|
5
|
+
*
|
|
6
|
+
* WHAT IT REFUSES IS THE COMPONENT. There is no `status` prop, no `severity`
|
|
7
|
+
* prop, no `color` prop, and no fourth variant called "warning". AlertBanner is
|
|
8
|
+
* the component that carries a clinical level: it is counted against the
|
|
9
|
+
* escalation budget, it is answerable to the two-axis rule, and a reviewer
|
|
10
|
+
* looking at a screen can find every one of them. A Callout that could be
|
|
11
|
+
* tinted amber would inherit all of that attention and none of the obligations,
|
|
12
|
+
* and nothing in review catches the difference, because the two render
|
|
13
|
+
* identically. So the refusal is the API rather than a paragraph in the
|
|
14
|
+
* documentation.
|
|
15
|
+
*
|
|
16
|
+
* WHICH IS WHY THE THREE VARIANTS SHARE ONE TREATMENT AND DIFFER ONLY BY GLYPH.
|
|
17
|
+
* The temptation with an admonition component is a tint per variant: blue for a
|
|
18
|
+
* note, green for a tip, yellow for a caveat. Yellow-for-a-caveat is the exact
|
|
19
|
+
* colour a reader has been taught means *watch* by every status surface on the
|
|
20
|
+
* screen. The product theme has no non-axis accent to reach for anyway:
|
|
21
|
+
* `packages/react/styles/theme.css` bridges eleven neutral surface roles plus
|
|
22
|
+
* the two axes, and nothing else exists. One neutral fill for all three is
|
|
23
|
+
* therefore both the available answer and the correct one. A variant buys a
|
|
24
|
+
* distinct glyph, and that is the whole of what it buys.
|
|
25
|
+
*
|
|
26
|
+
* IT STAMPS NO `data-variant`, DELIBERATELY. The data-attribute vocabulary is
|
|
27
|
+
* closed at four: `data-slot`, `data-status`, `data-opsinjs-value` and
|
|
28
|
+
* `data-category`. Spending a fifth on a distinction the specification
|
|
29
|
+
* itself describes as one whose loss "loses nothing" would be the wrong trade.
|
|
30
|
+
* A product that needs to style the note case differently from the tip case has
|
|
31
|
+
* `className`, and the reason it should not is the paragraph above.
|
|
32
|
+
*
|
|
33
|
+
* IT IS A SERVER COMPONENT. No state, no timers, no event handlers, no Base UI
|
|
34
|
+
* primitive. There is no dismiss control. A dismissible callout needs a name,
|
|
35
|
+
* a target floor and a memory that outlives the render, and none of those three
|
|
36
|
+
* has been designed. Its absence is why this file has no client boundary.
|
|
37
|
+
*/
|
|
38
|
+
import { Asterisk, Info, Lightbulb } from "lucide-react";
|
|
39
|
+
import { Children } from "react";
|
|
40
|
+
import { isDevelopment } from "../opsinjs.js";
|
|
41
|
+
import { cn } from "../utils.js";
|
|
42
|
+
/**
|
|
43
|
+
* The glyph for each variant.
|
|
44
|
+
*
|
|
45
|
+
* Three distinct silhouettes rather than one glyph in three colours, for the
|
|
46
|
+
* same reason the four status levels are four distinct shapes: colour is the
|
|
47
|
+
* carrier that fails first, and here it is not carrying anything at all.
|
|
48
|
+
*
|
|
49
|
+
* None of the three is a status glyph. The status axis owns its own four
|
|
50
|
+
* shapes, `Circle`, `CircleDot`, `Diamond` and `Octagon`, one per clinical
|
|
51
|
+
* level as `../status.ts` binds them, with `Minus` for the unknown case, and
|
|
52
|
+
* not one of them appears on this component. A warning triangle is refused on
|
|
53
|
+
* its own separate ground, which stands whatever the status set happens to
|
|
54
|
+
* name: a triangle sets an alarm register before a word is read, so it can
|
|
55
|
+
* never sit on a component that carries no level. `Asterisk` is the printer's
|
|
56
|
+
* mark for a footnote, which is exactly what a caveat is, and it carries no
|
|
57
|
+
* alarm.
|
|
58
|
+
*
|
|
59
|
+
* Typed `Record<CalloutVariant, …>` so that adding a fourth variant without a
|
|
60
|
+
* glyph is a compile error rather than a callout with an empty gutter.
|
|
61
|
+
*/
|
|
62
|
+
const VARIANT_ICONS = {
|
|
63
|
+
note: Info,
|
|
64
|
+
tip: Lightbulb,
|
|
65
|
+
caveat: Asterisk,
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The one treatment, written out rather than built per variant.
|
|
69
|
+
*
|
|
70
|
+
* The fill is `--opsin-material-inset-tint` and `text-foreground` is the body
|
|
71
|
+
* ink. The fill reads the token-only `inset` rung in `tokens/material.json`
|
|
72
|
+
* directly rather than the `bg-muted` chrome role it used to take, and that
|
|
73
|
+
* choice is a requirement rather than a coincidence: a Callout is a recess, so
|
|
74
|
+
* its fill must sit below the card fill in both themes. `bg-muted` held that
|
|
75
|
+
* order in the light theme but inverted it in the dark one, where it resolved
|
|
76
|
+
* above the card and drew the note as the most raised box on the page, the
|
|
77
|
+
* opposite of the light layout. What the `inset` rung actually guarantees, and
|
|
78
|
+
* all the code needs, is narrower than "between the card and the page": the fill
|
|
79
|
+
* sits below the card fill in both themes, and in the light theme it sits below
|
|
80
|
+
* the page as well, because there the page and the card fall within 0.01 L of
|
|
81
|
+
* each other. Reading the rung directly means a later change to `--muted` cannot
|
|
82
|
+
* silently raise the callout again. The boundary is `border-border`, and it is
|
|
83
|
+
* never the only thing setting the callout apart on screen, because it is a
|
|
84
|
+
* hairline. The fill does the work; the border draws the edge.
|
|
85
|
+
*
|
|
86
|
+
* NO CONTRAST FIGURE IS QUOTED HERE, AND THAT IS DELIBERATE. `tokens/color.json`
|
|
87
|
+
* says the measured numbers "are never written by hand and never quoted in
|
|
88
|
+
* prose", and a figure typed into a comment drifts silently the next time the
|
|
89
|
+
* ramps are re-tuned. None of the pairs this component actually paints is in
|
|
90
|
+
* `lib/generated/contrast.json` at all. Those pairs are body ink on the fill,
|
|
91
|
+
* the fill against the page, and the hairline against the fill.
|
|
92
|
+
* The nearest measured neighbour is `neutral.hairline-on-page`, which is
|
|
93
|
+
* advisory-failing in both themes; it measures the neutral ramp against the
|
|
94
|
+
* neutral page rather than `--border` against `--opsin-material-inset-tint`, so
|
|
95
|
+
* it is a different pair and its figures are not this component's to borrow. The measured set
|
|
96
|
+
* for this component is what `<ContrastReport component="callout" />` prints on
|
|
97
|
+
* the specification page, and today that is empty.
|
|
98
|
+
*
|
|
99
|
+
* `rounded-opsin-md` is what `tokens/shape.json` publishes as the default for a
|
|
100
|
+
* box of this size, and `corner-shape` rides on it as a progressive
|
|
101
|
+
* enhancement. An engine without it drops the declaration and draws an ordinary
|
|
102
|
+
* rounded corner, which is the fallback that file specifies. It is written as a
|
|
103
|
+
* property rather than through the product theme's `data-opsin-shape`
|
|
104
|
+
* attribute, because that attribute is a fifth member of a closed vocabulary
|
|
105
|
+
* and a rule keyed on it would have to live in the opt-in
|
|
106
|
+
* `@opsinjs/react/base.css`, which a consumer may never load.
|
|
107
|
+
*/
|
|
108
|
+
const SURFACE = "bg-(--opsin-material-inset-tint) text-foreground border border-edge rounded-opsin-md print:border-border " +
|
|
109
|
+
"[corner-shape:var(--opsin-corner-shape)]";
|
|
110
|
+
/**
|
|
111
|
+
* Print, where the fill is gone and the boundary is the whole of the
|
|
112
|
+
* treatment.
|
|
113
|
+
*
|
|
114
|
+
* A browser drops background colours when it prints unless the reader has gone
|
|
115
|
+
* looking for the setting that keeps them, so a callout on paper is a box
|
|
116
|
+
* defined by its border alone. A hairline is not enough for that job, so the
|
|
117
|
+
* boundary steps up from the hairline role to the ink role. The fill is dropped
|
|
118
|
+
* explicitly rather than left to the browser, so the page looks the same
|
|
119
|
+
* whichever way that setting is left.
|
|
120
|
+
*
|
|
121
|
+
* THE PRINTED PALETTE IS THE THEME'S, AND IT NOW REACHES THE DARK THEME TOO.
|
|
122
|
+
* `--foreground` is near-black in the light theme and near-white in the dark
|
|
123
|
+
* one, so `print:border-foreground` on its own would draw a near-white boundary
|
|
124
|
+
* on white paper for a reader printing from the dark theme.
|
|
125
|
+
* `packages/react/styles/roles.css` closes that for every component at once.
|
|
126
|
+
* Its `@media print` block redeclares `--foreground` and `--border` as ink on
|
|
127
|
+
* paper in all four theme selectors, the two dark ones included, so this
|
|
128
|
+
* constant resolves to a line a printer can draw whichever theme the reader
|
|
129
|
+
* started from. The division of labour is the point. The theme layer owns the
|
|
130
|
+
* printed palette, because forcing ink to black needs a raw colour literal that
|
|
131
|
+
* `registry/**` forbids a component from writing; a component owns only whether
|
|
132
|
+
* its own boundary is drawn with a property a printer keeps, which is what
|
|
133
|
+
* stepping from the hairline role up to the ink role does. What stays open is
|
|
134
|
+
* physical rather than a matter of code: nobody has sent either theme to a real
|
|
135
|
+
* printer, so the dark case is right by construction rather than confirmed on a
|
|
136
|
+
* printed sheet. That residual is recorded on the specification page.
|
|
137
|
+
*/
|
|
138
|
+
const PRINT = "print:bg-transparent print:border-foreground";
|
|
139
|
+
/**
|
|
140
|
+
* The axis names, and the pattern that finds one in a class list.
|
|
141
|
+
*
|
|
142
|
+
* Built from two pieces on purpose. `scripts/check-a11y.mts` reads this file as
|
|
143
|
+
* text and treats any file that spells a complete axis utility as a status
|
|
144
|
+
* surface owing a word, a glyph and a `data-status`; a detector written the
|
|
145
|
+
* obvious way would report itself and there would be no repair short of
|
|
146
|
+
* deleting the check. Split like this, the file contains the axis names and the
|
|
147
|
+
* axis prefixes and never the two joined, which is the thing the gate looks
|
|
148
|
+
* for. The pattern still matches every joined form at runtime.
|
|
149
|
+
*/
|
|
150
|
+
const AXIS_NAMES = "steady|watch|attention|urgent|unknown|sleep|heart|activity|nutrition|mind|labs";
|
|
151
|
+
const AXIS_TINT = new RegExp(`(?:^|[\\s:-])(?:status|category)-(?:${AXIS_NAMES})(?![a-z])`);
|
|
152
|
+
/**
|
|
153
|
+
* The escape hatch, closed for colour and open for everything else.
|
|
154
|
+
*
|
|
155
|
+
* Not an OPSIN code: `tokens/errors.json` has no entry for a component outside
|
|
156
|
+
* both axes being handed a colour from one of them, and a component may not
|
|
157
|
+
* mint one. The codes are a versioned contract and the table on the errors
|
|
158
|
+
* page is generated from that file. A development warning is the honest channel
|
|
159
|
+
* until an entry exists.
|
|
160
|
+
*
|
|
161
|
+
* Not having a code costs the substrate's `warnOnce`, which is keyed on one.
|
|
162
|
+
* It does not cost deduplication: this warning lives in a render body, so a
|
|
163
|
+
* bare `console.warn` would print on every render and twice again under Strict
|
|
164
|
+
* Mode, and a Callout inside a list that re-renders on scroll would fill the
|
|
165
|
+
* console until an author filters it. At that point the channel no longer
|
|
166
|
+
* carries its one real finding. A module-local set keyed on the offending class
|
|
167
|
+
* list says it once per distinct offence, which is as close to the policy's
|
|
168
|
+
* "once per offending call site" as a function that cannot see its own call
|
|
169
|
+
* site can get, and is what `card.tsx` and `dialog.tsx` do for the same reason.
|
|
170
|
+
* Allocating a code in `tokens/errors.json` and deleting the set is a strict
|
|
171
|
+
* improvement.
|
|
172
|
+
*
|
|
173
|
+
* The key is the class list rather than a constant, because two different
|
|
174
|
+
* offending class lists are two different mistakes in two different places and
|
|
175
|
+
* an author fixing the first still needs to be told about the second.
|
|
176
|
+
*
|
|
177
|
+
* It strips and renders. The axis tint is dropped from the class list in every
|
|
178
|
+
* environment, so twMerge never sees it and the component's own inset fill
|
|
179
|
+
* survives; the rest of the caller's classes pass through untouched and still
|
|
180
|
+
* win where they collide with the component's own. Development additionally
|
|
181
|
+
* warns once per distinct offending class list. The content stays on the
|
|
182
|
+
* screen, because taking a paragraph off it over a styling mistake would be the
|
|
183
|
+
* larger error, and a Callout drawn in its own neutral clothes still says what
|
|
184
|
+
* it says.
|
|
185
|
+
*/
|
|
186
|
+
const warnedAxisTints = new Set();
|
|
187
|
+
function withoutAxisTints(className) {
|
|
188
|
+
if (className === undefined)
|
|
189
|
+
return undefined;
|
|
190
|
+
if (!AXIS_TINT.test(className))
|
|
191
|
+
return className;
|
|
192
|
+
/* Tailwind spells a space inside brackets as an underscore, so no token
|
|
193
|
+
contains whitespace and splitting on runs of it is safe against arbitrary
|
|
194
|
+
values. The per-token test reuses AXIS_TINT: its `(?:^|[\s:-])` prefix
|
|
195
|
+
anchors a bare `status-urgent-surface` at the start of the token and still
|
|
196
|
+
matches the hyphen in a `bg-` prefix and the colon in a `dark:` variant. */
|
|
197
|
+
const kept = className
|
|
198
|
+
.split(/\s+/)
|
|
199
|
+
.filter((token) => token !== "" && !AXIS_TINT.test(token));
|
|
200
|
+
if (isDevelopment() && !warnedAxisTints.has(className)) {
|
|
201
|
+
warnedAxisTints.add(className);
|
|
202
|
+
console.warn(`[opsinjs] <Callout className="${className}"> takes a colour from one of the ` +
|
|
203
|
+
"two axes. Callout sits outside both, and that is the component: a callout " +
|
|
204
|
+
"that can be tinted from the status ramps hands a product a second, " +
|
|
205
|
+
"ungoverned way to raise the level of a reading, and a reader has no way to " +
|
|
206
|
+
"tell it apart from the component that is answerable for saying so. If the " +
|
|
207
|
+
"message is about this reader's own data and carries a level, the component " +
|
|
208
|
+
"is <AlertBanner> or <StatusPill>. If it is about the category a reading " +
|
|
209
|
+
"belongs to, the tint goes on the surface around the callout and not on the " +
|
|
210
|
+
"callout. See /docs/health/two-colour-axes.");
|
|
211
|
+
}
|
|
212
|
+
return kept.length === 0 ? undefined : kept.join(" ");
|
|
213
|
+
}
|
|
214
|
+
export function Callout({ variant = "note", title, children, className, }) {
|
|
215
|
+
const safeClassName = withoutAxisTints(className);
|
|
216
|
+
const Icon = VARIANT_ICONS[variant];
|
|
217
|
+
/* An empty or whitespace-only title is the ABSENCE of a title, not a title
|
|
218
|
+
with nothing in it. `""` is what a caller gets from an empty field or a
|
|
219
|
+
lookup that missed, and testing `!== undefined` rendered it as a
|
|
220
|
+
headline-sized empty paragraph with a row of gap above the body. That is an
|
|
221
|
+
absence drawn as a blank space, which is the one shape this system's
|
|
222
|
+
absences may never take. The element leaves the DOM instead, which is the
|
|
223
|
+
`0..1` cardinality the anatomy publishes. */
|
|
224
|
+
const hasTitle = title !== undefined && title.trim() !== "";
|
|
225
|
+
/* A text body is a paragraph so that two adjacent callouts do not fuse into
|
|
226
|
+
one text run for a screen reader; an element body keeps the div so a
|
|
227
|
+
caller's own `<p>` is not nested inside a paragraph, which is invalid HTML
|
|
228
|
+
that browsers silently unnest. The everyday form `<Callout>text {value}
|
|
229
|
+
text</Callout>` arrives as an array of strings, so the test is over the
|
|
230
|
+
array rather than `typeof children`, which would keep the div and keep the
|
|
231
|
+
defect. */
|
|
232
|
+
const bodyIsText = Children.toArray(children).every((child) => typeof child === "string" || typeof child === "number");
|
|
233
|
+
const Body = bodyIsText ? "p" : "div";
|
|
234
|
+
return (
|
|
235
|
+
/* A grid rather than a flex row with a wrapper around the text, because the
|
|
236
|
+
anatomy has Icon, Title and Body as three siblings under the root and a
|
|
237
|
+
wrapper would be a fourth element that the part tree does not name. The
|
|
238
|
+
glyph is placed explicitly at row 1 of column 1; the title and the body
|
|
239
|
+
are placed in column 2 and fall into successive rows, so a callout with
|
|
240
|
+
no title puts its body on row 1 beside the glyph and needs no second
|
|
241
|
+
layout.
|
|
242
|
+
|
|
243
|
+
`px-3 py-4` is the density-scaled step and not `p-opsin-*`.
|
|
244
|
+
packages/react/styles/theme.css names the inside of a box as the
|
|
245
|
+
canonical use of the scaled scale, so a reader who has asked for a
|
|
246
|
+
denser interface gets one here. Padding
|
|
247
|
+
is the measurement that may tighten, unlike the gutter below. The two axes
|
|
248
|
+
differ on purpose: at 200% text on a phone the horizontal axis is the one
|
|
249
|
+
competing with the reader's text column, so it comes down a step to `px-3`,
|
|
250
|
+
while the vertical axis is under no such pressure and stays at `py-4`, so
|
|
251
|
+
the vertical rhythm the reader feels is unchanged.
|
|
252
|
+
|
|
253
|
+
`role="note"`, and the cost of that is real rather than nil. Note is the
|
|
254
|
+
WAI-ARIA role for content parenthetic or ancillary to the main content,
|
|
255
|
+
which is exactly this component's definition. It is not `role="alert"`,
|
|
256
|
+
it adds no `aria-live`, it publishes no landmark and it adds no tab stop,
|
|
257
|
+
so none of the restraint this file keeps is spent. `role="alert"` is the
|
|
258
|
+
thing this component exists not to be. What the role buys is the boundary
|
|
259
|
+
a plain element withheld: a start, an end, and an accessible name, so two
|
|
260
|
+
adjacent callouts no longer read as one continuous text run and a titled
|
|
261
|
+
callout announces what it is a note about.
|
|
262
|
+
|
|
263
|
+
The name is the title, supplied through `aria-label` rather than
|
|
264
|
+
`aria-labelledby`. Pointing at the title needs an id this component
|
|
265
|
+
cannot mint, and `useId` is a hook that would put every callout in the
|
|
266
|
+
system into the client bundle to buy one string. That is the trade
|
|
267
|
+
`result-card.tsx` and `care-card.tsx` both refuse for this same
|
|
268
|
+
attribute, and this file's header records that its lack of a client
|
|
269
|
+
boundary is the point. `aria-label` buys the same linkage with no hook,
|
|
270
|
+
and because a note is not a live region the name cannot displace the
|
|
271
|
+
content the way a live region's would. The cost to state plainly: the
|
|
272
|
+
title is announced as the note's name and then read again as the title
|
|
273
|
+
paragraph, and a screen a product fills with callouts now announces a
|
|
274
|
+
container per callout. */
|
|
275
|
+
_jsxs("div", { "data-slot": "callout", role: "note", "aria-label": hasTitle ? title : undefined, className: cn("grid grid-cols-[auto_1fr] items-start px-3 py-4",
|
|
276
|
+
/* The gutter and the line gap are FIXED steps, not scaled ones. Their
|
|
277
|
+
job is to keep the glyph out of the text and the title off the body,
|
|
278
|
+
and neither should close up because somebody asked for a denser list.
|
|
279
|
+
The gutter is step 1, the step tokens/space.json names for an icon
|
|
280
|
+
beside its label, so the text column keeps that much more width at
|
|
281
|
+
200% text; the line gap is step 2, the step it names for tightly
|
|
282
|
+
related lines. */
|
|
283
|
+
"gap-x-opsin-1 gap-y-opsin-2", SURFACE, PRINT, safeClassName), children: [_jsx(Icon, { "data-slot": "callout-icon", "aria-hidden": "true", className: "col-start-1 row-start-1 mt-[0.2em] size-[1em] shrink-0" }), hasTitle ? (_jsx("p", { "data-slot": "callout-title", className: "col-start-2 m-0 min-w-0 text-opsin-headline", children: title })) : null, _jsx(Body, { "data-slot": "callout-body", className: "col-start-2 m-0 min-w-0 wrap-break-word text-opsin-body *:first:mt-0 *:last:mb-0", children: children })] }));
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=callout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callout.js","sourceRoot":"","sources":["../../src/components/callout.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAEhD,OAAO,EAAE,aAAa,EAAE,MAA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C,CAAC,CAAC,CACV,yBACY,eAAe,EACzB,SAAS,EAAC,6CAA6C,YAEtD,KAAK,GACJ,CACL,CAAC,CAAC,CAAC,IAAI,EA+BR,KAAC,IAAI,iBACO,cAAc,EACxB,SAAS,EAAC,kFAAkF,YAE3F,QAAQ,GACJ,IACH,CACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Card is a boundary, some padding, and one rung of the material ladder.
|
|
3
|
+
*
|
|
4
|
+
* Card is the most-used component in any design system and the one that most
|
|
5
|
+
* often becomes a dumping ground, so the interesting work here is what it
|
|
6
|
+
* refuses. There is no `status`, no `variant` and no `color`: a Card that could
|
|
7
|
+
* be tinted from the clinical axis would be a ResultCard with none of a
|
|
8
|
+
* ResultCard's obligations. It would have no staleness treatment, no
|
|
9
|
+
* attribution and no axis discipline, and nothing in review catches the
|
|
10
|
+
* difference, because the two render identically.
|
|
11
|
+
*
|
|
12
|
+
* THE DEFAULT RUNG IS `card`, AND THE SPECIFICATION SAID `raised`. That page was
|
|
13
|
+
* written against the retired rung vocabulary, where `raised` was the name for
|
|
14
|
+
* the rung a resting block of content sits on. On the ladder the tokens
|
|
15
|
+
* actually publish, `raised` is one rung higher. `tokens/material.json` gives
|
|
16
|
+
* it a drop shadow and describes it as "menus, popovers, tooltips, a dragged
|
|
17
|
+
* card". The rung named `card` is "the default home for a health value",
|
|
18
|
+
* opaque and deliberately shadowless. Taking the old word literally would have
|
|
19
|
+
* put a shadow under every resting card in the system, which is the exact
|
|
20
|
+
* clutter that rung's note exists to prevent. So the default is `card` and the
|
|
21
|
+
* page has been corrected rather than implemented. See ADR 0014.
|
|
22
|
+
*
|
|
23
|
+
* "Products may move a card down the ladder, never off it" survives that
|
|
24
|
+
* correction and means what it says: `canvas` for a card that should read as
|
|
25
|
+
* part of the page, `raised` while a card is being lifted, and never above
|
|
26
|
+
* `raised`, because a number a reader is trying to read must not sit over a
|
|
27
|
+
* moving backdrop. A card is being lifted when it is dragged or opened as a
|
|
28
|
+
* menu.
|
|
29
|
+
*
|
|
30
|
+
* IT IS ONE OF EXACTLY THREE COMPONENTS WITH REAL COMPOUND PARTS. `Card.Header`,
|
|
31
|
+
* `Card.Body` and `Card.Footer` are exported functions rather than `data-slot`
|
|
32
|
+
* names, because the consumer supplies their content and no prop could carry
|
|
33
|
+
* three ordered slots of arbitrary children. Everything else in the anatomy is
|
|
34
|
+
* a `data-slot`, which is enough to style and not enough to take apart. That
|
|
35
|
+
* covers the root, the title and the description. All three parts are optional:
|
|
36
|
+
* a Card with only children is the common case and takes no ceremony at all.
|
|
37
|
+
*
|
|
38
|
+
* IT IS A SERVER COMPONENT. It holds no state, listens for nothing, and every
|
|
39
|
+
* decision it makes is made from props at render time. The one thing a reader
|
|
40
|
+
* can change underneath it is the density of the interface, and it arrives as a
|
|
41
|
+
* CSS custom property on the document, not as a value this component reads.
|
|
42
|
+
*/
|
|
43
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
44
|
+
import { type MaterialRung } from "../opsinjs.ts";
|
|
45
|
+
export interface CardProps {
|
|
46
|
+
/**
|
|
47
|
+
* Which rung of the material ladder. Defaults to `"card"`. That rung is named
|
|
48
|
+
* for this component, opaque and deliberately shadowless. Products may move a
|
|
49
|
+
* card down the ladder to `"canvas"`, or up to `"raised"` while it is being
|
|
50
|
+
* lifted, and never above that: a value a reader is trying to read must not
|
|
51
|
+
* sit over a moving backdrop.
|
|
52
|
+
*
|
|
53
|
+
* @default "card"
|
|
54
|
+
*/
|
|
55
|
+
rung?: MaterialRung;
|
|
56
|
+
/**
|
|
57
|
+
* Padding scale. Affects space only, never type size. `"compact"` drops the
|
|
58
|
+
* padding to 0.875 of the comfortable padding, the same fraction
|
|
59
|
+
* `tokens/space.json` publishes for the compact density, on the density-scaled
|
|
60
|
+
* spacing scale. It does not shrink the type, the separation between two
|
|
61
|
+
* controls in the footer, or the card's touch target.
|
|
62
|
+
*
|
|
63
|
+
* @default "comfortable"
|
|
64
|
+
*/
|
|
65
|
+
density?: "comfortable" | "compact";
|
|
66
|
+
/**
|
|
67
|
+
* Makes the whole card a single link. A card that is a link may hold no other
|
|
68
|
+
* interactive element: a reader cannot tell what tapping the gap between two
|
|
69
|
+
* buttons will do, and a keyboard user reaches controls that are nested
|
|
70
|
+
* inside a control. TypeScript cannot express that exclusion, because
|
|
71
|
+
* `children` is a `ReactNode` and an element's interactivity is not in its
|
|
72
|
+
* type. So it is a rule this component states and does not enforce.
|
|
73
|
+
*
|
|
74
|
+
* A link card carries a resting cue the whole audience can read: a trailing
|
|
75
|
+
* chevron in the material's content row, visible with no pointer and no
|
|
76
|
+
* focus. It is `aria-hidden`, because the anchor's accessible name is already
|
|
77
|
+
* its whole text content. The hover, focus-visible and press title underline
|
|
78
|
+
* stays as well, now an addition rather than the only signal. `group-active`
|
|
79
|
+
* is what holds it through the press instead of dropping when an engine stops
|
|
80
|
+
* matching `:hover` on pointerdown.
|
|
81
|
+
*/
|
|
82
|
+
href?: string;
|
|
83
|
+
/**
|
|
84
|
+
* The product's own router link element, rendered in place of the plain
|
|
85
|
+
* anchor while the card keeps its `data-slot`, its shape, the target floor and
|
|
86
|
+
* the `group/card` hover relationship on it. Pass a Next or React Router link
|
|
87
|
+
* here so a linked card navigates client-side rather than reloading the whole
|
|
88
|
+
* page. It takes the element itself and not the function form Base UI parts
|
|
89
|
+
* accept, and it is only meaningful alongside `href`. In development a
|
|
90
|
+
* `render` passed without `href`, or one that is not a React element, warns
|
|
91
|
+
* once and the card falls back to the plain anchor.
|
|
92
|
+
*
|
|
93
|
+
* This is the escape hatch `Link` offers, and it is the only half of that
|
|
94
|
+
* component a card takes. Five components that shipped a private anchor moved
|
|
95
|
+
* to `Link` outright, because their anchor was a control inside the card: an
|
|
96
|
+
* action a reader chooses among others. A card's anchor is not that. The
|
|
97
|
+
* whole card is the target, so the element is the card rather than a control
|
|
98
|
+
* inside it, and it carries `data-slot="card"`. Wrapping it in a `Link` would
|
|
99
|
+
* move `data-slot` onto a foreign root and put an action link's box and
|
|
100
|
+
* underline around a whole card, which is why this file keeps its own anchor
|
|
101
|
+
* and borrows only the `render` slot.
|
|
102
|
+
*/
|
|
103
|
+
render?: ReactElement;
|
|
104
|
+
/**
|
|
105
|
+
* Merged onto the root. Layout belongs here: a card sets no width, no
|
|
106
|
+
* position and no place in a grid, because those are decisions of the screen
|
|
107
|
+
* it is on rather than of the card.
|
|
108
|
+
*/
|
|
109
|
+
className?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Everything the card holds. Usually that is `Card.Header`, `Card.Body` and
|
|
112
|
+
* `Card.Footer`, and equally correctly it is a single paragraph.
|
|
113
|
+
*/
|
|
114
|
+
children: ReactNode;
|
|
115
|
+
}
|
|
116
|
+
export declare function Card({ rung, density, href, render, className, children, }: CardProps): import("react").JSX.Element;
|
|
117
|
+
export declare namespace Card {
|
|
118
|
+
var Header: typeof CardHeader;
|
|
119
|
+
var Body: typeof CardBody;
|
|
120
|
+
var Footer: typeof CardFooter;
|
|
121
|
+
}
|
|
122
|
+
export interface CardHeaderProps {
|
|
123
|
+
/**
|
|
124
|
+
* The card's title. Pass the heading element the page's outline needs, and
|
|
125
|
+
* the slot takes care of how it looks. `<h3>Recent readings</h3>` is the
|
|
126
|
+
* shape it takes. Pass a string instead and the title is styled text with no
|
|
127
|
+
* place in the outline, which is a legitimate choice for a card nobody needs
|
|
128
|
+
* to navigate to and a mistake for one they do.
|
|
129
|
+
*/
|
|
130
|
+
title: ReactNode;
|
|
131
|
+
/**
|
|
132
|
+
* One supporting line under the title. It renders a paragraph, so it takes
|
|
133
|
+
* text or inline content rather than a block element.
|
|
134
|
+
*/
|
|
135
|
+
description?: ReactNode;
|
|
136
|
+
/** Anything else the header holds, after the title and the description. */
|
|
137
|
+
children?: ReactNode;
|
|
138
|
+
/** Merged onto the header. */
|
|
139
|
+
className?: string;
|
|
140
|
+
}
|
|
141
|
+
export declare function CardHeader({ title, description, children, className, }: CardHeaderProps): import("react").JSX.Element;
|
|
142
|
+
export interface CardBodyProps {
|
|
143
|
+
/** The content. */
|
|
144
|
+
children: ReactNode;
|
|
145
|
+
/** Merged onto the body. */
|
|
146
|
+
className?: string;
|
|
147
|
+
}
|
|
148
|
+
export declare function CardBody({ children, className }: CardBodyProps): import("react").JSX.Element;
|
|
149
|
+
export interface CardFooterProps {
|
|
150
|
+
/** Actions or metadata. */
|
|
151
|
+
children: ReactNode;
|
|
152
|
+
/** Merged onto the footer. */
|
|
153
|
+
className?: string;
|
|
154
|
+
}
|
|
155
|
+
export declare function CardFooter({ children, className }: CardFooterProps): import("react").JSX.Element;
|
|
156
|
+
//# sourceMappingURL=card.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../src/components/card.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAgC,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAIvF,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,eAAe,CAAA;AAkJhE,MAAM,WAAW,SAAS;IACxB;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,YAAY,CAAA;IACnB;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAA;IACnC;;;;;;;;;;;;;;;OAeG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,wBAAgB,IAAI,CAAC,EACnB,IAAa,EACb,OAAuB,EACvB,IAAI,EACJ,MAAM,EACN,SAAS,EACT,QAAQ,GACT,EAAE,SAAS,+BA6OX;yBApPe,IAAI;;;;;AAi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