@wyattjoh/herdr-ui 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.
@@ -0,0 +1,305 @@
1
+ // Bordered cards with an external header, their rows, collapsible groups of rows, and the
2
+ // progress bar a row can end with. A card clips its rectangle, not its corners, so a band
3
+ // painted in a corner (a header, a closed last group, a hovered last row) rounds that corner
4
+ // itself.
5
+ import { div, svg, type Color, type Context, type Element } from "gpui-kit";
6
+ import { h_flex, v_flex } from "gpui-base";
7
+ import { HERDR_ICONS } from "../icons";
8
+ import { CARD, FOLD_MOTION, PROGRESS, ROW, TEXT, TONES } from "../tokens";
9
+ import { role, type Theme } from "./theme";
10
+
11
+ /**
12
+ * A card's outline and the rules between its groups. `border` is a translucent white that reads
13
+ * light over a group's `popover` band but faint over the darker card; `input`, a stronger one,
14
+ * matches that light line over both.
15
+ * @param t The theme.
16
+ * @returns The line color.
17
+ */
18
+ export const cardLine = (t: Theme): Color => t.input;
19
+
20
+ /**
21
+ * A bordered card on `canvas`, so its body and rows take that color with its rounded corners.
22
+ * @param t The theme.
23
+ * @param id The card's id.
24
+ * @returns The card; add a body or groups as children.
25
+ */
26
+ export const card = (t: Theme, id: string): Element =>
27
+ v_flex()
28
+ .id(id)
29
+ .flex_none()
30
+ .bg(t.canvas)
31
+ .border(1)
32
+ .border_color(cardLine(t))
33
+ .rounded(CARD.radius)
34
+ .overflow_hidden();
35
+
36
+ /**
37
+ * A fold's chevron, just after the label it folds.
38
+ * @param t The theme.
39
+ * @param open Whether the fold is open.
40
+ * @returns The chevron.
41
+ */
42
+ export const foldChevron = (t: Theme, open: boolean): Element =>
43
+ svg(open ? HERDR_ICONS.chevronDown : HERDR_ICONS.chevronRight)
44
+ .size(CARD.chevronSize)
45
+ .flex_none()
46
+ .text_color(t.dim);
47
+
48
+ /**
49
+ * A section's muted title on the panel background, outside its card.
50
+ * @param t The theme.
51
+ * @param id The header's id.
52
+ * @param name The section's name.
53
+ * @param open When the section folds, whether it is open (draws the chevron).
54
+ * @returns The header.
55
+ */
56
+ export const cardHeader = (
57
+ t: Theme,
58
+ id: string,
59
+ name: string,
60
+ open: boolean | undefined = undefined,
61
+ ): Element =>
62
+ h_flex()
63
+ .id(id)
64
+ .h(CARD.headerHeight)
65
+ .flex_none()
66
+ .px(CARD.paddingX)
67
+ .gap(CARD.headerGap)
68
+ .items_center()
69
+ .child(div().text_size(TEXT.body).font_medium().text_color(t.muted).child(name))
70
+ .when(open !== undefined, (el) => el.child(foldChevron(t, open!)));
71
+
72
+ /**
73
+ * A section: its header close above its card.
74
+ * @param header The {@link cardHeader}.
75
+ * @param content The {@link card}.
76
+ * @returns The section.
77
+ */
78
+ export const cardSection = (header: Element, content: Element): Element =>
79
+ v_flex().flex_none().gap(CARD.sectionGap).child(header).child(content);
80
+
81
+ /**
82
+ * Content padding inside a card, which supplies the outline and corners.
83
+ * @returns The padded body.
84
+ */
85
+ export const cardBody = (): Element => div().px(CARD.paddingX).py(CARD.paddingY);
86
+
87
+ /**
88
+ * A card's dimmed note, for an empty card or a "N more." footer.
89
+ * @param text The note.
90
+ * @returns The padded note.
91
+ */
92
+ export const cardNote = (t: Theme, text: string): Element =>
93
+ cardBody().text_size(TEXT.label).text_color(t.dim).child(text);
94
+
95
+ /**
96
+ * A row of a card, ruled off from the one above; it highlights on hover.
97
+ * @param t The theme.
98
+ * @param id The row's id.
99
+ * @param hover The hover fill; default `hover`.
100
+ * @returns The row; set its height and add its parts.
101
+ */
102
+ export const cardRow = (t: Theme, id: string, hover: Color = t.hover): Element =>
103
+ h_flex()
104
+ .id(id)
105
+ .flex_none()
106
+ .px(CARD.paddingX)
107
+ .gap(CARD.rowGap)
108
+ .items_center()
109
+ .cursor_pointer()
110
+ .hover((s) => s.bg(hover))
111
+ .border_t(1)
112
+ .border_color(t.border);
113
+
114
+ /**
115
+ * What a {@link listRow} shows and does.
116
+ */
117
+ export type ListRowOptions = {
118
+ id: string;
119
+ title: string;
120
+ /**
121
+ * A leading mark, such as a status icon.
122
+ */
123
+ mark?: Element;
124
+ /**
125
+ * A key or number, drawn muted before the title.
126
+ */
127
+ label?: string;
128
+ /**
129
+ * The title's theme role; default `foreground` (the Tasks panel dims a canceled row).
130
+ */
131
+ titleRole?: string;
132
+ /**
133
+ * Items after the title: chips, a dimmed note, a progress bar.
134
+ */
135
+ trailing?: readonly Element[];
136
+ /**
137
+ * The row's height; default {@link ROW.list}.
138
+ */
139
+ height?: number;
140
+ tooltip?: string;
141
+ onClick: (cx: Context) => void;
142
+ };
143
+
144
+ /**
145
+ * A row of a list card: its mark, key and title, then what else it says.
146
+ * @param t The theme.
147
+ * @param options What it shows and does.
148
+ * @returns The row.
149
+ */
150
+ export function listRow(t: Theme, options: ListRowOptions): Element {
151
+ return cardRow(t, options.id)
152
+ .h(options.height ?? ROW.list)
153
+ .when(options.tooltip !== undefined, (el) => el.tooltip(options.tooltip!))
154
+ .on_click((_event, cx) => options.onClick(cx))
155
+ .when(options.mark !== undefined, (el) => el.child(options.mark!))
156
+ .when(options.label !== undefined && options.label !== "", (el) =>
157
+ el.child(div().flex_none().text_size(TEXT.label).text_color(t.muted).child(options.label!)),
158
+ )
159
+ .child(
160
+ div()
161
+ .flex_1()
162
+ .min_w_0()
163
+ .truncate()
164
+ .text_size(TEXT.body)
165
+ .text_color(role(t, options.titleRole ?? "foreground"))
166
+ .child(options.title),
167
+ )
168
+ .children([...(options.trailing ?? [])]);
169
+ }
170
+
171
+ /**
172
+ * A dimmed note at a row's end, like the Project a listing row belongs to.
173
+ * @param t The theme.
174
+ * @param text The note.
175
+ * @returns The note.
176
+ */
177
+ export const rowNote = (t: Theme, text: string): Element =>
178
+ div().flex_none().text_size(TEXT.label).text_color(t.dim).child(text);
179
+
180
+ /**
181
+ * A status mark at the size list rows give their icons.
182
+ * @param t The theme.
183
+ * @param icon The `svg()` path.
184
+ * @param tone The theme role tinting it.
185
+ * @returns The mark.
186
+ */
187
+ export const statusMark = (t: Theme, icon: string, tone: string): Element =>
188
+ svg(icon).size(14).flex_none().text_color(role(t, tone));
189
+
190
+ /**
191
+ * One collapsible group of a card: a header band with its label in its tone, the chevron and its
192
+ * count, then its rows while it's open.
193
+ */
194
+ export type GroupBlockOptions = {
195
+ id: string;
196
+ label: string;
197
+ /**
198
+ * The label's theme role.
199
+ */
200
+ tone: string;
201
+ count: number;
202
+ rows: readonly Element[];
203
+ /**
204
+ * Every row's fixed height, which the fold animates to and from.
205
+ */
206
+ rowHeight: number;
207
+ open: boolean;
208
+ /**
209
+ * The card's first group: rounds its top corners, with no top rule.
210
+ */
211
+ first: boolean;
212
+ /**
213
+ * The card's last group: rounds its bottom band (the header while closed, the last row while
214
+ * open).
215
+ */
216
+ last: boolean;
217
+ toggle: (cx: Context) => void;
218
+ /**
219
+ * Passive size measurement.
220
+ */
221
+ measure?: (size: { width: number; height: number }) => void;
222
+ };
223
+
224
+ /**
225
+ * A group of rows. The band is `popover`, `raised` on hover, above the card's `canvas` rows.
226
+ * @param t The theme.
227
+ * @param motionScope Qualifies the animated body's id: native motion can be sampled before
228
+ * parent id scopes apply, so retained screens with different height targets need their own.
229
+ * @param group The group.
230
+ * @returns The group.
231
+ */
232
+ export function groupBlock(t: Theme, motionScope: string, group: GroupBlockOptions): Element {
233
+ const { open, first, last } = group;
234
+ return v_flex()
235
+ .id(group.id)
236
+ .when(group.measure !== undefined, (el) => el.on_size_change((size) => group.measure!(size)))
237
+ .child(
238
+ cardRow(t, `${group.id}-toggle`, t.raised)
239
+ .h(CARD.groupHeaderHeight)
240
+ .bg(t.popover)
241
+ .when(first, (el) => el.border_t(0).rounded_t(CARD.innerRadius))
242
+ .when(last && !open, (el) => el.rounded_b(CARD.innerRadius))
243
+ .text_size(TEXT.label)
244
+ .on_click((_event, cx) => group.toggle(cx))
245
+ .child(div().font_medium().text_color(role(t, group.tone)).child(group.label))
246
+ .child(foldChevron(t, open))
247
+ .child(div().text_color(t.dim).child(String(group.count)))
248
+ .child(div().flex_1()),
249
+ )
250
+ .child(
251
+ v_flex()
252
+ .id(`${motionScope}-${group.id}-body`)
253
+ .overflow_hidden()
254
+ .h(open ? group.rows.length * group.rowHeight : 0)
255
+ .transition("height", FOLD_MOTION)
256
+ .children(
257
+ group.rows.map((row, index) =>
258
+ row.when(last && index === group.rows.length - 1, (el) =>
259
+ el.rounded_b(CARD.innerRadius),
260
+ ),
261
+ ),
262
+ ),
263
+ );
264
+ }
265
+
266
+ /**
267
+ * A progress bar filled by `done` over `total`, and the fraction; `empty` when there is
268
+ * nothing to count. Its width is fixed, so bars line up down a list.
269
+ * @param t The theme.
270
+ * @param progress The counts, the fill's theme role (default success), and the empty label.
271
+ * @returns The bar.
272
+ */
273
+ export function progressBar(
274
+ t: Theme,
275
+ progress: { done: number; total: number; tone?: string; empty?: string },
276
+ ): Element {
277
+ const { done, total } = progress;
278
+ return h_flex()
279
+ .flex_none()
280
+ .w(PROGRESS.width + PROGRESS.gap + PROGRESS.labelWidth)
281
+ .gap(PROGRESS.gap)
282
+ .items_center()
283
+ .justify_end()
284
+ .text_size(TEXT.label)
285
+ .text_color(t.dim)
286
+ .when(total === 0, (el) => el.child(progress.empty ?? "None"))
287
+ .when(total > 0, (el) =>
288
+ el
289
+ .child(
290
+ div()
291
+ .w(PROGRESS.width)
292
+ .h(PROGRESS.height)
293
+ .rounded(PROGRESS.radius)
294
+ .overflow_hidden()
295
+ .bg(t.border)
296
+ .child(
297
+ div()
298
+ .h_full()
299
+ .w(Math.round((PROGRESS.width * done) / total))
300
+ .bg(role(t, progress.tone ?? TONES.success)),
301
+ ),
302
+ )
303
+ .child(`${done}/${total}`),
304
+ );
305
+ }
@@ -0,0 +1,110 @@
1
+ // Small badges: a label chip on `raised`, and a count chip tinted in its own color.
2
+ import { div, svg, type Color, type Element } from "gpui-kit";
3
+ import { h_flex } from "gpui-base";
4
+ import { tint } from "../color";
5
+ import { CHIP } from "../tokens";
6
+ import type { Theme } from "./theme";
7
+
8
+ /**
9
+ * A row of chips that shrinks and clips rather than pushing its row wider.
10
+ * @param chips The chips.
11
+ * @returns The row.
12
+ */
13
+ export const chipRow = (chips: readonly Element[]): Element =>
14
+ h_flex()
15
+ .min_w_0()
16
+ .flex_shrink(1)
17
+ .gap(CHIP.rowGap)
18
+ .items_center()
19
+ .overflow_hidden()
20
+ .children([...chips]);
21
+
22
+ /**
23
+ * What a {@link labelChip} shows.
24
+ */
25
+ export type LabelChipOptions = {
26
+ id: string;
27
+ label: string;
28
+ /**
29
+ * The icon's `svg()` path.
30
+ */
31
+ icon: string;
32
+ /**
33
+ * The icon's color (data, such as a label's color), else `muted`.
34
+ */
35
+ color: string | undefined;
36
+ /**
37
+ * The tooltip and accessibility label; default the label.
38
+ */
39
+ caption?: string;
40
+ };
41
+
42
+ /**
43
+ * A label chip: an icon in the label's color and its truncating name on `raised`.
44
+ * @param t The theme.
45
+ * @param options What it shows.
46
+ * @returns The chip.
47
+ */
48
+ export function labelChip(t: Theme, options: LabelChipOptions): Element {
49
+ const caption = options.caption ?? options.label;
50
+ return h_flex()
51
+ .id(options.id)
52
+ .h(CHIP.height)
53
+ .max_w(CHIP.maxWidth)
54
+ .min_w_0()
55
+ .px(CHIP.paddingX)
56
+ .gap(CHIP.gap)
57
+ .rounded(CHIP.radius)
58
+ .bg(t.raised)
59
+ .text_size(CHIP.textSize)
60
+ .text_color(t.foreground)
61
+ .tooltip(caption)
62
+ .accessibility_label(caption)
63
+ .child(
64
+ svg(options.icon)
65
+ .size(CHIP.iconSize)
66
+ .flex_none()
67
+ .text_color((options.color as Color | undefined) ?? t.muted),
68
+ )
69
+ .child(div().min_w_0().truncate().child(options.label));
70
+ }
71
+
72
+ /**
73
+ * What a {@link countChip} shows.
74
+ */
75
+ export type CountChipOptions = {
76
+ id: string;
77
+ count: number;
78
+ /**
79
+ * The icon's `svg()` path.
80
+ */
81
+ icon: string;
82
+ /**
83
+ * The chip's color: the icon and count take it, the background a tint of it.
84
+ */
85
+ color: Color;
86
+ tooltip: string;
87
+ };
88
+
89
+ /**
90
+ * A count chip, like the Tasks panel's Blocked and Blocking badges: an icon and a number in one
91
+ * color over a tint of it.
92
+ * @param options What it shows.
93
+ * @returns The chip.
94
+ */
95
+ export const countChip = (options: CountChipOptions): Element =>
96
+ h_flex()
97
+ .id(options.id)
98
+ .flex_none()
99
+ .h(CHIP.height)
100
+ .px(CHIP.paddingX)
101
+ .rounded(CHIP.radius)
102
+ .gap(CHIP.gap)
103
+ .items_center()
104
+ // GPUI accepts #rrggbbaa: tint only the background, not the icon or count.
105
+ .bg(tint(options.color, CHIP.tintAlpha) as Color)
106
+ .text_size(CHIP.textSize)
107
+ .text_color(options.color)
108
+ .tooltip(options.tooltip)
109
+ .child(svg(options.icon).size(CHIP.iconSize).flex_none().text_color(options.color))
110
+ .child(String(options.count));
@@ -0,0 +1,83 @@
1
+ // The panel button: an icon and a label in Herdr's top-bar button style.
2
+ import { svg, type Context, type Element } from "gpui-kit";
3
+ import { h_flex } from "gpui-base";
4
+ import { BUTTON_STYLE, type ButtonStyle } from "../toolbar";
5
+ import { role, type Theme } from "./theme";
6
+
7
+ /**
8
+ * What a {@link button} shows and does.
9
+ */
10
+ export type ButtonOptions = {
11
+ /**
12
+ * The element id, from a domain id and namespaced by region.
13
+ */
14
+ id: string;
15
+ /**
16
+ * The label: shown when `labelled`, else the tooltip.
17
+ */
18
+ label: string;
19
+ /**
20
+ * The leading icon's `svg()` path.
21
+ */
22
+ icon?: string;
23
+ /**
24
+ * The press handler; without one the button is inert and dimmed.
25
+ */
26
+ onClick?: (cx: Context) => void;
27
+ /**
28
+ * Whether the label shows. Default true.
29
+ */
30
+ labelled?: boolean;
31
+ /**
32
+ * A tooltip other than the label.
33
+ */
34
+ tooltip?: string;
35
+ /**
36
+ * Draws the icon in the accent color: the button names a state that is on (Pinned).
37
+ */
38
+ active?: boolean;
39
+ /**
40
+ * Overrides the panel button style.
41
+ */
42
+ style?: ButtonStyle;
43
+ };
44
+
45
+ /**
46
+ * A panel button in the top bar's Files/Changes style. An icon-only button shows its label as its
47
+ * tooltip unless it's given another.
48
+ * @param t The theme.
49
+ * @param options What it shows and does.
50
+ * @returns The button.
51
+ */
52
+ export function button(t: Theme, options: ButtonOptions): Element {
53
+ const s = options.style ?? BUTTON_STYLE;
54
+ const labelled = options.labelled ?? true;
55
+ const tooltip = options.tooltip ?? (labelled ? undefined : options.label);
56
+ const { onClick, icon } = options;
57
+ return h_flex()
58
+ .id(options.id)
59
+ .h(s.height)
60
+ .px(s.paddingX)
61
+ .gap(s.gap)
62
+ .flex_none()
63
+ .items_center()
64
+ .rounded(s.radius)
65
+ .text_size(s.textSize)
66
+ .bg(role(t, s.background))
67
+ .text_color(onClick === undefined ? t.dim : role(t, s.text))
68
+ .when(onClick !== undefined, (el) =>
69
+ el
70
+ .cursor_pointer()
71
+ .hover((style) => style.bg(role(t, s.hover)))
72
+ .on_click((_event, cx) => onClick!(cx)),
73
+ )
74
+ .when(icon !== undefined, (el) =>
75
+ el.child(
76
+ svg(icon!)
77
+ .size(s.iconSize)
78
+ .when(options.active === true, (glyph) => glyph.text_color(t.accent)),
79
+ ),
80
+ )
81
+ .when(labelled, (el) => el.child(options.label))
82
+ .when(tooltip !== undefined, (el) => el.tooltip(tooltip!));
83
+ }