@grafctory/clay-widgets 0.0.0-stage → 0.5.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/LICENSE +201 -0
- package/README.md +56 -2
- package/dist/content/empty.css +107 -0
- package/dist/content/empty.d.ts +40 -0
- package/dist/content/empty.d.ts.map +1 -0
- package/dist/content/empty.js +42 -0
- package/dist/content/empty.js.map +1 -0
- package/dist/content/heading.css +34 -0
- package/dist/content/heading.d.ts +45 -0
- package/dist/content/heading.d.ts.map +1 -0
- package/dist/content/heading.js +49 -0
- package/dist/content/heading.js.map +1 -0
- package/dist/content/image.css +198 -0
- package/dist/content/image.d.ts +77 -0
- package/dist/content/image.d.ts.map +1 -0
- package/dist/content/image.js +67 -0
- package/dist/content/image.js.map +1 -0
- package/dist/content/infobox.css +186 -0
- package/dist/content/infobox.d.ts +72 -0
- package/dist/content/infobox.d.ts.map +1 -0
- package/dist/content/infobox.js +63 -0
- package/dist/content/infobox.js.map +1 -0
- package/dist/content/pill.css +76 -0
- package/dist/content/pill.d.ts +57 -0
- package/dist/content/pill.d.ts.map +1 -0
- package/dist/content/pill.js +48 -0
- package/dist/content/pill.js.map +1 -0
- package/dist/content/text.css +44 -0
- package/dist/content/text.d.ts +30 -0
- package/dist/content/text.d.ts.map +1 -0
- package/dist/content/text.js +42 -0
- package/dist/content/text.js.map +1 -0
- package/dist/controls/button.css +469 -0
- package/dist/controls/button.d.ts +116 -0
- package/dist/controls/button.d.ts.map +1 -0
- package/dist/controls/button.js +61 -0
- package/dist/controls/button.js.map +1 -0
- package/dist/controls/checkbox.css +23 -0
- package/dist/controls/checkbox.d.ts +54 -0
- package/dist/controls/checkbox.d.ts.map +1 -0
- package/dist/controls/checkbox.js +49 -0
- package/dist/controls/checkbox.js.map +1 -0
- package/dist/controls/choice.css +288 -0
- package/dist/controls/choice.d.ts +63 -0
- package/dist/controls/choice.d.ts.map +1 -0
- package/dist/controls/choice.js +52 -0
- package/dist/controls/choice.js.map +1 -0
- package/dist/controls/fieldset.css +37 -0
- package/dist/controls/fieldset.d.ts +49 -0
- package/dist/controls/fieldset.d.ts.map +1 -0
- package/dist/controls/fieldset.js +51 -0
- package/dist/controls/fieldset.js.map +1 -0
- package/dist/controls/form.css +50 -0
- package/dist/controls/form.d.ts +64 -0
- package/dist/controls/form.d.ts.map +1 -0
- package/dist/controls/form.js +62 -0
- package/dist/controls/form.js.map +1 -0
- package/dist/controls/input.css +57 -0
- package/dist/controls/input.d.ts +129 -0
- package/dist/controls/input.d.ts.map +1 -0
- package/dist/controls/input.js +71 -0
- package/dist/controls/input.js.map +1 -0
- package/dist/controls/label.css +73 -0
- package/dist/controls/label.d.ts +76 -0
- package/dist/controls/label.d.ts.map +1 -0
- package/dist/controls/label.js +73 -0
- package/dist/controls/label.js.map +1 -0
- package/dist/controls/radio.css +23 -0
- package/dist/controls/radio.d.ts +60 -0
- package/dist/controls/radio.d.ts.map +1 -0
- package/dist/controls/radio.js +50 -0
- package/dist/controls/radio.js.map +1 -0
- package/dist/controls/select.css +37 -0
- package/dist/controls/select.d.ts +71 -0
- package/dist/controls/select.d.ts.map +1 -0
- package/dist/controls/select.js +59 -0
- package/dist/controls/select.js.map +1 -0
- package/dist/controls/switch.css +154 -0
- package/dist/controls/switch.d.ts +44 -0
- package/dist/controls/switch.d.ts.map +1 -0
- package/dist/controls/switch.js +48 -0
- package/dist/controls/switch.js.map +1 -0
- package/dist/controls/textarea.css +50 -0
- package/dist/controls/textarea.d.ts +106 -0
- package/dist/controls/textarea.d.ts.map +1 -0
- package/dist/controls/textarea.js +68 -0
- package/dist/controls/textarea.js.map +1 -0
- package/dist/glyphs/icon.core.d.ts +52 -0
- package/dist/glyphs/icon.core.d.ts.map +1 -0
- package/dist/glyphs/icon.core.js +67 -0
- package/dist/glyphs/icon.core.js.map +1 -0
- package/dist/glyphs/icon.css +32 -0
- package/dist/glyphs/icon.d.ts +152 -0
- package/dist/glyphs/icon.d.ts.map +1 -0
- package/dist/glyphs/icon.js +167 -0
- package/dist/glyphs/icon.js.map +1 -0
- package/dist/glyphs/icon.md +76 -0
- package/dist/glyphs/logo.css +73 -0
- package/dist/glyphs/logo.d.ts +27 -0
- package/dist/glyphs/logo.d.ts.map +1 -0
- package/dist/glyphs/logo.js +49 -0
- package/dist/glyphs/logo.js.map +1 -0
- package/dist/index.core.d.ts +18 -0
- package/dist/index.core.d.ts.map +1 -0
- package/dist/index.core.js +36 -0
- package/dist/index.core.js.map +1 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/dist/layouts/card.css +190 -0
- package/dist/layouts/card.d.ts +75 -0
- package/dist/layouts/card.d.ts.map +1 -0
- package/dist/layouts/card.js +62 -0
- package/dist/layouts/card.js.map +1 -0
- package/dist/layouts/stack.css +58 -0
- package/dist/layouts/stack.d.ts +64 -0
- package/dist/layouts/stack.d.ts.map +1 -0
- package/dist/layouts/stack.js +69 -0
- package/dist/layouts/stack.js.map +1 -0
- package/dist/layouts/strip.css +58 -0
- package/dist/layouts/strip.d.ts +72 -0
- package/dist/layouts/strip.d.ts.map +1 -0
- package/dist/layouts/strip.js +73 -0
- package/dist/layouts/strip.js.map +1 -0
- package/dist/layouts/tabs.core.d.ts +73 -0
- package/dist/layouts/tabs.core.d.ts.map +1 -0
- package/dist/layouts/tabs.core.js +65 -0
- package/dist/layouts/tabs.core.js.map +1 -0
- package/dist/layouts/tabs.css +260 -0
- package/dist/layouts/tabs.d.ts +57 -0
- package/dist/layouts/tabs.d.ts.map +1 -0
- package/dist/layouts/tabs.js +128 -0
- package/dist/layouts/tabs.js.map +1 -0
- package/dist/layouts/tree.css +138 -0
- package/dist/layouts/tree.d.ts +46 -0
- package/dist/layouts/tree.d.ts.map +1 -0
- package/dist/layouts/tree.js +69 -0
- package/dist/layouts/tree.js.map +1 -0
- package/dist/navigation/link.css +229 -0
- package/dist/navigation/link.d.ts +89 -0
- package/dist/navigation/link.d.ts.map +1 -0
- package/dist/navigation/link.js +91 -0
- package/dist/navigation/link.js.map +1 -0
- package/dist/navigation/path.css +122 -0
- package/dist/navigation/path.d.ts +42 -0
- package/dist/navigation/path.d.ts.map +1 -0
- package/dist/navigation/path.js +49 -0
- package/dist/navigation/path.js.map +1 -0
- package/dist/navigation/toc.core.d.ts +111 -0
- package/dist/navigation/toc.core.d.ts.map +1 -0
- package/dist/navigation/toc.core.js +60 -0
- package/dist/navigation/toc.core.js.map +1 -0
- package/dist/navigation/toc.css +53 -0
- package/dist/navigation/toc.d.ts +112 -0
- package/dist/navigation/toc.d.ts.map +1 -0
- package/dist/navigation/toc.js +321 -0
- package/dist/navigation/toc.js.map +1 -0
- package/dist/scopes/guard.css +26 -0
- package/dist/scopes/guard.d.ts +37 -0
- package/dist/scopes/guard.d.ts.map +1 -0
- package/dist/scopes/guard.js +60 -0
- package/dist/scopes/guard.js.map +1 -0
- package/dist/scopes/style.css +26 -0
- package/dist/scopes/style.d.ts +68 -0
- package/dist/scopes/style.d.ts.map +1 -0
- package/dist/scopes/style.js +108 -0
- package/dist/scopes/style.js.map +1 -0
- package/dist/shells/tool.css +770 -0
- package/dist/shells/tool.d.ts +167 -0
- package/dist/shells/tool.d.ts.map +1 -0
- package/dist/shells/tool.js +286 -0
- package/dist/shells/tool.js.map +1 -0
- package/dist/signals/more.css +42 -0
- package/dist/signals/more.d.ts +28 -0
- package/dist/signals/more.d.ts.map +1 -0
- package/dist/signals/more.js +61 -0
- package/dist/signals/more.js.map +1 -0
- package/dist/signals/note.css +221 -0
- package/dist/signals/note.d.ts +83 -0
- package/dist/signals/note.d.ts.map +1 -0
- package/dist/signals/note.js +72 -0
- package/dist/signals/note.js.map +1 -0
- package/dist/signals/toasts.css +463 -0
- package/dist/signals/toasts.d.ts +68 -0
- package/dist/signals/toasts.d.ts.map +1 -0
- package/dist/signals/toasts.js +160 -0
- package/dist/signals/toasts.js.map +1 -0
- package/package.json +331 -4
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2026 Metreeca srl
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* An image is a block as wide as its picture and scaled down to the room it is given, adding no spacing of its own,
|
|
19
|
+
* so it sits in a card, a stack or a column exactly as the bare picture would, with its caption held beneath it.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/* The look of an image stating none, which an area assigns to every image it holds. */
|
|
23
|
+
|
|
24
|
+
@property --clay-image-look {
|
|
25
|
+
syntax: "subtle | normal | strong";
|
|
26
|
+
inherits: true;
|
|
27
|
+
initial-value: normal;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
* The box the picture is scaled down to fit within, as set by the image. A width CSS does not accept, `none` included,
|
|
32
|
+
* leaves the width knob at its initial value, so the picture is then bounded by the column alone.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
@property --clay-image-max-width {
|
|
36
|
+
syntax: "<length-percentage>";
|
|
37
|
+
inherits: false;
|
|
38
|
+
initial-value: 100%;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@property --clay-image-max-height {
|
|
42
|
+
syntax: "<length-percentage> | none";
|
|
43
|
+
inherits: true; /* Read by the picture inside the image, not by the image that sets it. */
|
|
44
|
+
initial-value: none;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
clay-image {
|
|
48
|
+
|
|
49
|
+
display: block;
|
|
50
|
+
width: fit-content;
|
|
51
|
+
max-width: min(100%, var(--clay-image-max-width));
|
|
52
|
+
|
|
53
|
+
& > figure {
|
|
54
|
+
margin: 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/*
|
|
58
|
+
* A picture is never stretched past its own size, and keeps its proportions when scaled down. An enlarged picture
|
|
59
|
+
* is left alone, since this rule would otherwise beat the design system one showing it over the viewport.
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
& img:not([active]) {
|
|
63
|
+
display: block;
|
|
64
|
+
max-width: 100%;
|
|
65
|
+
max-height: var(--clay-image-max-height);
|
|
66
|
+
height: auto;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
* The caption takes no width of its own, so a long caption wraps within the width of the picture rather than
|
|
71
|
+
* widening the block. Its size, colour and distance from the picture come from the design system figure rules.
|
|
72
|
+
*
|
|
73
|
+
* Small wording flush with the hard edge of a picture reads as standing to its left, so the caption is nudged
|
|
74
|
+
* right, shifting its rendering alone and leaving the line its wording wraps in intact.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
& figcaption {
|
|
78
|
+
box-sizing: border-box;
|
|
79
|
+
width: 0;
|
|
80
|
+
min-width: 100%;
|
|
81
|
+
translate: var(--skin--border-width) 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/*
|
|
85
|
+
* Floated, the image is the one place it takes spacing of its own: the text wrapping around it keeps off the
|
|
86
|
+
* picture on the side it faces and off its bottom edge, so a column of wrapped lines, ragged against the picture,
|
|
87
|
+
* still reads as standing clear of it however its lines happen to break against it.
|
|
88
|
+
*
|
|
89
|
+
* The image is sized against the column rather than against the room the clearance leaves beside it, so a clearance
|
|
90
|
+
* taking the whole column moves the text below the picture without shrinking the picture to nothing.
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
&[float] {
|
|
94
|
+
width: max-content;
|
|
95
|
+
max-width: min(100% - var(--skin--spacing-200), var(--clay-image-max-width));
|
|
96
|
+
margin-bottom: var(--skin--spacing-200);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
&[float="start"] {
|
|
100
|
+
float: inline-start;
|
|
101
|
+
margin-inline-end: var(--clay-image-clearance, var(--skin--spacing-200));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
&[float="end"] {
|
|
105
|
+
float: inline-end;
|
|
106
|
+
margin-inline-start: var(--clay-image-clearance, var(--skin--spacing-200));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/*
|
|
110
|
+
* A floated image of bounded width leaves the text at least 20rem beside its bound, about forty characters, below
|
|
111
|
+
* which wrapped lines break into a word or two each; the design system names no text measure to read instead. Where
|
|
112
|
+
* the column is narrower, the clearance on the text side snaps to the whole column, leaving no room beside the
|
|
113
|
+
* picture, so the text resumes below it as it would under an image floating to no side.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
&[sized] {
|
|
117
|
+
--clay-image-clearance: clamp(
|
|
118
|
+
var(--skin--spacing-200),
|
|
119
|
+
(var(--clay-image-max-width) + 20rem - 100%) * 1000, /* a step rather than a ramp */
|
|
120
|
+
100%
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/*
|
|
125
|
+
* Normal, the picture is outlined with the quiet border the design system draws around content, and the caption
|
|
126
|
+
* is inset by the width of the border as well, so its wording keeps to the picture rather than to the outline.
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
&[look="normal"] {
|
|
130
|
+
|
|
131
|
+
& img {
|
|
132
|
+
border: var(--skin--border-width) var(--skin--border-style) var(--skin--border-color);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
& figcaption {
|
|
136
|
+
padding-inline: var(--skin--border-width);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/*
|
|
142
|
+
* Strong, picture and caption sit in a rounded box, the picture rounded tighter than the box, so its corners follow
|
|
143
|
+
* the corners of the box around it rather than meeting them at a sharper angle.
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
&[look="strong"] {
|
|
147
|
+
|
|
148
|
+
padding: var(--skin--spacing-050);
|
|
149
|
+
|
|
150
|
+
border: var(--skin--border-width) var(--skin--border-style) var(--skin--border-color);
|
|
151
|
+
border-radius: var(--skin--border-radius-050);
|
|
152
|
+
|
|
153
|
+
& img {
|
|
154
|
+
border-radius: var(--skin--border-radius-025);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/*
|
|
160
|
+
* An image stating no look of its own takes the one the area around it sets, read off the `--clay-image-look`
|
|
161
|
+
* knob through a style query, as buttons and links do: the attribute has to be absent for the container to have
|
|
162
|
+
* a say, so each rule here holds itself to an image carrying none, restating the declarations of the rules above.
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
@container style(--clay-image-look: normal) {
|
|
166
|
+
|
|
167
|
+
&:not([look]) {
|
|
168
|
+
|
|
169
|
+
& img {
|
|
170
|
+
border: var(--skin--border-width) var(--skin--border-style) var(--skin--border-color);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
& figcaption {
|
|
174
|
+
padding-inline: var(--skin--border-width);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
@container style(--clay-image-look: strong) {
|
|
182
|
+
|
|
183
|
+
&:not([look]) {
|
|
184
|
+
|
|
185
|
+
padding: var(--skin--spacing-050);
|
|
186
|
+
|
|
187
|
+
border: var(--skin--border-width) var(--skin--border-style) var(--skin--border-color);
|
|
188
|
+
border-radius: var(--skin--border-radius-050);
|
|
189
|
+
|
|
190
|
+
& img {
|
|
191
|
+
border-radius: var(--skin--border-radius-025);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Captioned image.
|
|
3
|
+
*
|
|
4
|
+
* Sets a picture together with what is said about it, such as its credits, as one block held to the width of the
|
|
5
|
+
* picture, so a card, a stack or a page places an image, or floats it beside the text, with no layout of its own.
|
|
6
|
+
*
|
|
7
|
+
* @module image
|
|
8
|
+
*/
|
|
9
|
+
import { type ComponentChildren } from "preact";
|
|
10
|
+
import "./image.css";
|
|
11
|
+
/**
|
|
12
|
+
* Creates an image.
|
|
13
|
+
*
|
|
14
|
+
* Shows the picture scaled down to the room it is given, or to a smaller box where one is set, and never stretched
|
|
15
|
+
* past its own size. A caption is set under the picture and wraps within its width rather than widening the block.
|
|
16
|
+
* Picture and caption are then exposed to assistive technology as one figure named by its caption.
|
|
17
|
+
*
|
|
18
|
+
* A picture is decorative unless given a text alternative: it is left out of the accessibility tree, and out of the
|
|
19
|
+
* layout if it fails to load. An alternative is owed wherever the picture tells something its surroundings do not.
|
|
20
|
+
*
|
|
21
|
+
* A caption is left out when it is `undefined`, `null`, an empty string or a boolean, as left by a conditional such as
|
|
22
|
+
* `credits && <span/>`, so a screen hands over whatever it knows about the picture without checking first.
|
|
23
|
+
*
|
|
24
|
+
* @param options The widget configuration
|
|
25
|
+
*
|
|
26
|
+
* @returns The image
|
|
27
|
+
*/
|
|
28
|
+
export declare function Image({ look, // deliberately left undefaulted, so an unstated look falls through to the one the area assigns
|
|
29
|
+
float, within, src, alt, caption }: {
|
|
30
|
+
/**
|
|
31
|
+
* How loud the image appears: `subtle` sets the picture bare, `normal` outlines it with a quiet border, and
|
|
32
|
+
* `strong` holds picture and caption in a rounded box, the picture rounded to match.
|
|
33
|
+
*
|
|
34
|
+
* An image stating nothing takes the look the {@link style!Style styled area} around it assigns as `imageLook`,
|
|
35
|
+
* which is `normal` where nothing assigns it. Stating a look here answers to that alone, whatever the area says.
|
|
36
|
+
*/
|
|
37
|
+
look?: "subtle" | "normal" | "strong";
|
|
38
|
+
/**
|
|
39
|
+
* The side of the column the image floats to, in the writing direction.
|
|
40
|
+
*
|
|
41
|
+
* The text that follows a floating image wraps around it and keeps clear of it by the design system spacing. An
|
|
42
|
+
* image floating to no side stands in the column as a block of its own, with the text resuming below it.
|
|
43
|
+
*
|
|
44
|
+
* An image with a width bound set by `within` floats only where the column leaves the text at least `20rem` beside
|
|
45
|
+
* it. In a narrower column it stands as a block, with the text resuming below, so the text is never squeezed to a
|
|
46
|
+
* word or two per line. An image with no width bound floats in any column, however narrow.
|
|
47
|
+
*/
|
|
48
|
+
float?: "start" | "end";
|
|
49
|
+
/**
|
|
50
|
+
* The box the picture is scaled down to fit within, as CSS lengths.
|
|
51
|
+
*
|
|
52
|
+
* A single length bounds both sides alike, and a pair bounds the width and then the height. A side given as `none`,
|
|
53
|
+
* or as a value CSS does not accept, takes no bound beyond the column, which limits the width but not the height.
|
|
54
|
+
*
|
|
55
|
+
* Percentages are relative to the column, and a percentage height has no effect because the column sets no height.
|
|
56
|
+
* A width bound also lets a floating image stand as a block in a narrow column, as described under `float`.
|
|
57
|
+
*/
|
|
58
|
+
within?: string | readonly [width: string, height: string];
|
|
59
|
+
/**
|
|
60
|
+
* The URL of the picture.
|
|
61
|
+
*/
|
|
62
|
+
src: string;
|
|
63
|
+
/**
|
|
64
|
+
* The text alternative standing for the picture where it is not seen; the picture is taken as decorative if empty.
|
|
65
|
+
*/
|
|
66
|
+
alt?: string;
|
|
67
|
+
/**
|
|
68
|
+
* The caption set under the picture, in the label colour, such as its credits.
|
|
69
|
+
*/
|
|
70
|
+
caption?: ComponentChildren;
|
|
71
|
+
}): import("preact").VNode<{
|
|
72
|
+
look: "subtle" | "normal" | "strong" | undefined;
|
|
73
|
+
float: "start" | "end" | undefined;
|
|
74
|
+
sized: boolean;
|
|
75
|
+
style: Readonly<Record<string, string>> | undefined;
|
|
76
|
+
}>;
|
|
77
|
+
//# sourceMappingURL=image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/content/image.tsx"],"names":[],"mappings":"AAgBA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,iBAAiB,EAAiB,MAAM,QAAQ,CAAC;AAE/D,OAAO,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CAAC,EAErB,IAAI,EAAE,+FAA+F;AACrG,KAAK,EACL,MAAM,EAEN,GAAG,EACH,GAAQ,EAER,OAAO,EAEP,EAAE;IAEF;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAA;IAErC;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,KAAK,CAAA;IAEvB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IAG1D;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IAEX;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAGZ;;OAEG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAA;CAE3B;;;;;GAmCA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright © 2026 Metreeca srl
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Captioned image.
|
|
19
|
+
*
|
|
20
|
+
* Sets a picture together with what is said about it, such as its credits, as one block held to the width of the
|
|
21
|
+
* picture, so a card, a stack or a page places an image, or floats it beside the text, with no layout of its own.
|
|
22
|
+
*
|
|
23
|
+
* @module image
|
|
24
|
+
*/
|
|
25
|
+
import { createElement } from "preact";
|
|
26
|
+
import { isContent } from "../index.js";
|
|
27
|
+
import "./image.css";
|
|
28
|
+
/**
|
|
29
|
+
* Creates an image.
|
|
30
|
+
*
|
|
31
|
+
* Shows the picture scaled down to the room it is given, or to a smaller box where one is set, and never stretched
|
|
32
|
+
* past its own size. A caption is set under the picture and wraps within its width rather than widening the block.
|
|
33
|
+
* Picture and caption are then exposed to assistive technology as one figure named by its caption.
|
|
34
|
+
*
|
|
35
|
+
* A picture is decorative unless given a text alternative: it is left out of the accessibility tree, and out of the
|
|
36
|
+
* layout if it fails to load. An alternative is owed wherever the picture tells something its surroundings do not.
|
|
37
|
+
*
|
|
38
|
+
* A caption is left out when it is `undefined`, `null`, an empty string or a boolean, as left by a conditional such as
|
|
39
|
+
* `credits && <span/>`, so a screen hands over whatever it knows about the picture without checking first.
|
|
40
|
+
*
|
|
41
|
+
* @param options The widget configuration
|
|
42
|
+
*
|
|
43
|
+
* @returns The image
|
|
44
|
+
*/
|
|
45
|
+
export function Image({ look, // deliberately left undefaulted, so an unstated look falls through to the one the area assigns
|
|
46
|
+
float, within, src, alt = "", caption }) {
|
|
47
|
+
const picture = _jsx("img", { alt: alt, src: src });
|
|
48
|
+
return createElement("clay-image", {
|
|
49
|
+
look,
|
|
50
|
+
float,
|
|
51
|
+
sized: within !== undefined && sides(within)[0] !== "none",
|
|
52
|
+
style: within === undefined ? undefined : bounds(within)
|
|
53
|
+
}, isContent(caption)
|
|
54
|
+
? _jsxs("figure", { children: [picture, _jsx("figcaption", { children: caption })] })
|
|
55
|
+
: picture);
|
|
56
|
+
function sides(within) {
|
|
57
|
+
return typeof within === "string" ? [within, within] : within;
|
|
58
|
+
}
|
|
59
|
+
function bounds(within) {
|
|
60
|
+
const [width, height] = sides(within);
|
|
61
|
+
return {
|
|
62
|
+
"--clay-image-max-width": width,
|
|
63
|
+
"--clay-image-max-height": height
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../src/content/image.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAA0B,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,KAAK,CAAC,EAErB,IAAI,EAAE,+FAA+F;AACrG,KAAK,EACL,MAAM,EAEN,GAAG,EACH,GAAG,GAAG,EAAE,EAER,OAAO,EAqDP;IAEA,MAAM,OAAO,GAAG,cAAK,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;IAE3C,OAAO,aAAa,CAAC,YAAY,EAAE;QAEjC,IAAI;QACJ,KAAK;QAEL,KAAK,EAAE,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM;QAC1D,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;KAExD,EAAE,SAAS,CAAC,OAAO,CAAC;QACpB,CAAC,CAAC,6BAAS,OAAO,EACjB,+BAAa,OAAO,GAAc,IAC1B;QACT,CAAC,CAAC,OAAO,CACV,CAAC;IAGF,SAAS,KAAK,CAAC,MAA0C;QACxD,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC/D,CAAC;IAED,SAAS,MAAM,CAAC,MAA0C;QAEzD,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QAEtC,OAAO;YACN,wBAAwB,EAAE,KAAK;YAC/B,yBAAyB,EAAE,MAAM;SACjC,CAAC;IAEH,CAAC;AAEF,CAAC"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2026 Metreeca srl
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* An infobox lays its sections out on a single two-column grid, labels in the first column and values in the second.
|
|
19
|
+
* Each section, a definition list of its own, spans both columns on a subgrid, so labels and values line up across
|
|
20
|
+
* sections. At the start, labels keep to the leading edge of their column as values do, so both columns read as
|
|
21
|
+
* aligned text; at the end, they sit flush against the values they introduce, so each label reads as their caption.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
clay-infobox {
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
* Labels take the width they need up to what the values leave them, so a long label is clipped rather than
|
|
28
|
+
* crowding out the values it is there to introduce, which keep the larger share of the width whatever the labels
|
|
29
|
+
* ask for. Labels and values have no edge between them to tell the two columns apart, so they are set well apart
|
|
30
|
+
* to read as two columns rather than as one run of text, whichever edge of their column the labels keep to.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
display: grid;
|
|
34
|
+
grid-template-columns: minmax(0, min-content) minmax(50%, 1fr);
|
|
35
|
+
column-gap: var(--skin--spacing-100);
|
|
36
|
+
|
|
37
|
+
/* An infobox leaves the room a plain definition list leaves below it, so it is spaced as one in a page flow. */
|
|
38
|
+
|
|
39
|
+
margin-bottom: var(--skin--spacing-100);
|
|
40
|
+
|
|
41
|
+
& > dl {
|
|
42
|
+
|
|
43
|
+
display: grid;
|
|
44
|
+
grid-column: 1 / -1;
|
|
45
|
+
grid-template-columns: subgrid;
|
|
46
|
+
align-items: baseline;
|
|
47
|
+
row-gap: var(--skin--spacing-010);
|
|
48
|
+
|
|
49
|
+
margin: 0;
|
|
50
|
+
|
|
51
|
+
/* Sections are set apart by a rule, so a screen groups related properties by section. */
|
|
52
|
+
|
|
53
|
+
& + dl {
|
|
54
|
+
margin-top: var(--skin--spacing-075);
|
|
55
|
+
padding-top: var(--skin--spacing-075);
|
|
56
|
+
border-top-style: var(--skin--border-style);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
* Spacing between entries comes from the grid gap, replacing the margins the base list rules set. Labels and
|
|
61
|
+
* values are kept to one line each, clipped with an ellipsis where they outrun their column, so one long value
|
|
62
|
+
* neither wraps the row nor widens the infobox; wrapping infoboxes release values from this rule, as set below.
|
|
63
|
+
*
|
|
64
|
+
* The clip reaches past the box, clear of the focus mark of any link the cell holds, so the mark
|
|
65
|
+
* shows whole while the ellipsis still cuts text at the edge of the box, where the column ends for the reader.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
& > dt,
|
|
69
|
+
& > dd {
|
|
70
|
+
overflow: clip;
|
|
71
|
+
overflow-clip-margin: var(--skin--spacing-050);
|
|
72
|
+
text-overflow: ellipsis;
|
|
73
|
+
white-space: nowrap;
|
|
74
|
+
margin: 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/*
|
|
78
|
+
* Labels are guidance rather than text, so they differ from their values by colour alone: they take the size
|
|
79
|
+
* and weight of the values beside them, sharing their line, in the label colour the base list rules give a
|
|
80
|
+
* term, which holds the 4.5:1 a text role owes in both schemes.
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
& > dt {
|
|
84
|
+
text-transform: capitalize;
|
|
85
|
+
font-size: inherit;
|
|
86
|
+
font-weight: inherit;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
& > dd {
|
|
90
|
+
|
|
91
|
+
/* Nothing in a value grows wider than its column, so a widget there is clipped by its own rules. */
|
|
92
|
+
|
|
93
|
+
& > *,
|
|
94
|
+
& > ul > li > * {
|
|
95
|
+
max-width: 100%;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
* A value listing several items sets them one per line, marked as any list, with no step between items, so
|
|
100
|
+
* the list reads as a single value rather than as a run of separate entries. Markers hang in the gap before
|
|
101
|
+
* the column, so items keep to the edge the values of other properties start from.
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
&:has(> ul) {
|
|
105
|
+
|
|
106
|
+
/*
|
|
107
|
+
* A value holding a list stops clipping, which would hide the hanging markers; the list clips instead,
|
|
108
|
+
* at the trailing edge, leaving the width of the column gap to the markers at the leading one, and room
|
|
109
|
+
* for the focus mark of a link above and below, as the value would.
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
overflow: visible;
|
|
113
|
+
|
|
114
|
+
& > ul {
|
|
115
|
+
|
|
116
|
+
/* Physical, as the base list rule this undoes sets the leading room on the left. */
|
|
117
|
+
|
|
118
|
+
padding-left: 0;
|
|
119
|
+
|
|
120
|
+
clip-path: inset(
|
|
121
|
+
calc(-1 * var(--skin--spacing-050)) 0 calc(-1 * var(--skin--spacing-050)) calc(-1 * var(--skin--spacing-100))
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
/*
|
|
125
|
+
* Items are marked by a small grey dot, telling a value made of several items from a single one
|
|
126
|
+
* without competing with the items themselves. Markers carry no meaning a colour role would name,
|
|
127
|
+
* so the grey is mixed from text and page as the grey scale is, at the lightest shares holding the
|
|
128
|
+
* 3:1 a graphic conveying content owes on the page, the stripe and the raised, overlay and sunken
|
|
129
|
+
* surfaces. The tightest is the sunken one in the light scheme, at 3.08:1, and the overlay in the
|
|
130
|
+
* dark one, at 3.09:1; half a point less brings either to the very threshold.
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
list-style-type: "· ";
|
|
134
|
+
|
|
135
|
+
& > li::marker {
|
|
136
|
+
color: light-dark(
|
|
137
|
+
color-mix(in oklab, var(--skin--color) 36%, var(--skin--background-color)),
|
|
138
|
+
color-mix(in oklab, var(--skin--color) 47%, var(--skin--background-color))
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/* A single item reads as a plain value, so it takes no marker. */
|
|
143
|
+
|
|
144
|
+
& > li:only-child {
|
|
145
|
+
list-style-type: none;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
& > li + li {
|
|
149
|
+
margin-top: 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/*
|
|
161
|
+
* Wrapping, a long value wraps within its column rather than being clipped, so a value is shown in full however
|
|
162
|
+
* long it runs, and a word outrunning the column alone, as a long address, breaks wherever needed to fit it.
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
&[wrap] > dl > dd {
|
|
166
|
+
white-space: normal;
|
|
167
|
+
overflow-wrap: anywhere;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/*
|
|
171
|
+
* Wrapping values may run over several lines, so labels are set strong in the label colour, standing out from
|
|
172
|
+
* the values beside them as headings of their rows rather than by colour alone.
|
|
173
|
+
*/
|
|
174
|
+
|
|
175
|
+
&[wrap] > dl > dt {
|
|
176
|
+
font-weight: var(--skin--font-weight-strong);
|
|
177
|
+
color: var(--skin--color-label);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/* At the end, labels sit flush against the values they introduce. */
|
|
181
|
+
|
|
182
|
+
&[align="end"] > dl > dt {
|
|
183
|
+
text-align: end;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type Some } from "@grafctory/core/arrays";
|
|
2
|
+
import { type ComponentChildren } from "preact";
|
|
3
|
+
import "./infobox.css";
|
|
4
|
+
/**
|
|
5
|
+
* Infobox section keyed by labels.
|
|
6
|
+
*
|
|
7
|
+
* Maps each plain string label to the value it names, so a section is written as a single object literal. Properties
|
|
8
|
+
* are shown in the order their labels appear in the object, but labels reading as non-negative integers, such as
|
|
9
|
+
* `2026`, always come first in ascending order: a section needing them elsewhere takes {@link InfoboxProperty} entries.
|
|
10
|
+
*/
|
|
11
|
+
export type InfoboxProperties = {
|
|
12
|
+
readonly [label: string]: ComponentChildren;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Infobox entry.
|
|
16
|
+
*
|
|
17
|
+
* Pairs a value with the label naming it. Entries serve labels that are not plain strings, such as links or emphasised
|
|
18
|
+
* text, and sections whose properties have to be shown in a given order, numeric labels included.
|
|
19
|
+
*/
|
|
20
|
+
export type InfoboxProperty = {
|
|
21
|
+
/**
|
|
22
|
+
* The label naming the value.
|
|
23
|
+
*/
|
|
24
|
+
readonly label: ComponentChildren;
|
|
25
|
+
/**
|
|
26
|
+
* The value shown beside the label; an empty value leaves the whole entry out, as {@link Infobox} defines it.
|
|
27
|
+
*/
|
|
28
|
+
readonly value: ComponentChildren;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Creates an infobox.
|
|
32
|
+
*
|
|
33
|
+
* Lists properties as label and value pairs, grouped into sections. Assistive technology reads each section as the
|
|
34
|
+
* terms and definitions of a list of its own, so each group of related properties is announced apart from the next.
|
|
35
|
+
*
|
|
36
|
+
* Properties with an empty value are left out, and so are sections left with none. An infobox left with no section
|
|
37
|
+
* renders nothing, so a screen hands over whatever it knows about an item without checking what is missing. A value
|
|
38
|
+
* is empty when it is `undefined`, `null` or an empty string. Any other value is shown, `0` included, and a boolean
|
|
39
|
+
* reads as its name, `true` or `false`, rather than vanishing as it would in plain markup.
|
|
40
|
+
*
|
|
41
|
+
* Sections are set apart by a rule and share the label and value columns, so a screen groups related properties by
|
|
42
|
+
* giving each group its own section, without drawing a separator of its own or aligning one group with the next.
|
|
43
|
+
*
|
|
44
|
+
* @param options The widget configuration
|
|
45
|
+
*
|
|
46
|
+
* @returns The infobox, or `null` if no property carries a value
|
|
47
|
+
*/
|
|
48
|
+
export declare function Infobox({ wrap, align, children }: {
|
|
49
|
+
/**
|
|
50
|
+
* Whether long values wrap across lines, so each is shown in full, as fits the body of a page. A word too long for
|
|
51
|
+
* its column breaks wherever needed. By default each value is clipped to a single line with an ellipsis, so a long
|
|
52
|
+
* value never stretches its row and a list of properties stays compact, as fits a narrow sidebar.
|
|
53
|
+
*/
|
|
54
|
+
wrap?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Where labels sit within their column. At the `start`, the default, labels keep to the leading edge as values
|
|
57
|
+
* do, so both columns read as aligned text. At the `end`, labels sit flush against the values they introduce, so
|
|
58
|
+
* each label reads as the caption of its value rather than as an entry of a column of its own.
|
|
59
|
+
*/
|
|
60
|
+
align?: "start" | "end";
|
|
61
|
+
/**
|
|
62
|
+
* The properties to show, as one section or as an array of sections. A section holds either values keyed by their
|
|
63
|
+
* labels, or an array of entries where labels are not plain strings or have to be shown in a given order. An array
|
|
64
|
+
* whose elements hold no keys but `label` and `value` is read as a single section of entries, so a section keyed by
|
|
65
|
+
* those two labels alone is given as an array of entries instead. Nothing is rendered if omitted.
|
|
66
|
+
*/
|
|
67
|
+
children?: Some<InfoboxProperties | readonly InfoboxProperty[]>;
|
|
68
|
+
}): import("preact").VNode<{
|
|
69
|
+
wrap: boolean;
|
|
70
|
+
align: "start" | "end";
|
|
71
|
+
}> | null;
|
|
72
|
+
//# sourceMappingURL=infobox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infobox.d.ts","sourceRoot":"","sources":["../../src/content/infobox.tsx"],"names":[],"mappings":"AA0BA,OAAO,EAAE,KAAK,IAAI,EAAQ,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,KAAK,iBAAiB,EAA2B,MAAM,QAAQ,CAAC;AACzE,OAAO,eAAe,CAAC;AAGvB;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAE/B,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAAA;CAE3C,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAE7B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAA;IAEjC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAA;CAEjC,CAAA;AAKD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,OAAO,CAAC,EAEvB,IAAY,EACZ,KAAe,EAEf,QAAQ,EAER,EAAE;IAEF;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IAEd;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,KAAK,CAAA;IAGvB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,IAAI,CAAC,iBAAiB,GAAG,SAAS,eAAe,EAAE,CAAC,CAAA;CAE/D;;;UAmCA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright © 2026 Metreeca srl
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Infobox.
|
|
19
|
+
*
|
|
20
|
+
* Lists the properties of an item in sections of related properties, each value beside the label naming it. A sidebar
|
|
21
|
+
* or the body of a page then shows what is known about an item, without a layout written for the purpose.
|
|
22
|
+
*
|
|
23
|
+
* @module infobox
|
|
24
|
+
*/
|
|
25
|
+
import { isBoolean, isObject } from "@grafctory/core";
|
|
26
|
+
import { some } from "@grafctory/core/arrays";
|
|
27
|
+
import { createElement, Fragment } from "preact";
|
|
28
|
+
import "./infobox.css";
|
|
29
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
30
|
+
/**
|
|
31
|
+
* Creates an infobox.
|
|
32
|
+
*
|
|
33
|
+
* Lists properties as label and value pairs, grouped into sections. Assistive technology reads each section as the
|
|
34
|
+
* terms and definitions of a list of its own, so each group of related properties is announced apart from the next.
|
|
35
|
+
*
|
|
36
|
+
* Properties with an empty value are left out, and so are sections left with none. An infobox left with no section
|
|
37
|
+
* renders nothing, so a screen hands over whatever it knows about an item without checking what is missing. A value
|
|
38
|
+
* is empty when it is `undefined`, `null` or an empty string. Any other value is shown, `0` included, and a boolean
|
|
39
|
+
* reads as its name, `true` or `false`, rather than vanishing as it would in plain markup.
|
|
40
|
+
*
|
|
41
|
+
* Sections are set apart by a rule and share the label and value columns, so a screen groups related properties by
|
|
42
|
+
* giving each group its own section, without drawing a separator of its own or aligning one group with the next.
|
|
43
|
+
*
|
|
44
|
+
* @param options The widget configuration
|
|
45
|
+
*
|
|
46
|
+
* @returns The infobox, or `null` if no property carries a value
|
|
47
|
+
*/
|
|
48
|
+
export function Infobox({ wrap = false, align = "start", children }) {
|
|
49
|
+
const sections = (isEntries(children) ? [children] : some(children))
|
|
50
|
+
.map(section => entries(section).filter(({ value }) => value !== undefined && value !== null && value !== ""))
|
|
51
|
+
.filter(section => section.length > 0);
|
|
52
|
+
return sections.length > 0 ? createElement("clay-infobox", {
|
|
53
|
+
wrap,
|
|
54
|
+
align
|
|
55
|
+
}, sections.map((section, index) => _jsx("dl", { children: section.map(({ label, value }, index) => _jsxs(Fragment, { children: [_jsx("dt", { children: label }), _jsx("dd", { children: isBoolean(value) ? String(value) : value })] }, index)) }, index))) : null;
|
|
56
|
+
function isEntries(children) {
|
|
57
|
+
return Array.isArray(children) && children.every(child => isObject(child, { label: () => true, value: () => true }));
|
|
58
|
+
}
|
|
59
|
+
function entries(section) {
|
|
60
|
+
return Array.isArray(section) ? section : Object.entries(section).map(([label, value]) => ({ label, value }));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=infobox.js.map
|