-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
import { attr, className, el } from "../../dom";
import { compute, Signal } from "../../signal";
export const styles = /* css */ `
.ii-list {
padding: 0;
margin: 0;
user-select: text;
}
.ii-label {
padding: 0;
margin: 0;
margin-bottom: 4px;
font-size: calc(var(--font-size) * 0.8);
font-weight: bold;
color: var(--subtle-fg);
}
.ii-content {
padding: 0;
margin: 0;
margin-bottom: 24px;
font-size: var(--font-size);
font-weight: normal;
color: var(--fg);
}
`;
type Children = NonNullable<Parameters<typeof el>[2]>;
interface Item {
label: Children[number];
content: Children;
}
export function infoItems(
items: readonly (Item | Signal<Item | null> | null)[],
): HTMLElement {
return el(
"dl",
[className("ii-list")],
items
.map((item) => {
if (!item) {
return [];
}
if (item instanceof Signal) {
return [map(label, item), map(content, item)];
}
return [label(item), content(item)];
})
.flat(),
);
}
function map<T, P>(f: (v: T) => P, s: Signal<T | null>): Signal<P | null> {
return compute(() => {
const v = s.get();
if (v === null) {
return null;
}
return f(v);
});
}
function label(item: Item): HTMLElement {
return el(
"dt",
[className("ii-label")],
[item.label, el("span", [attr("aria-hidden", "true")], [":"])],
);
}
function content(item: Item): HTMLElement {
return el("dd", [className("ii-content")], item.content);
}