@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,313 @@
1
+ // The breadcrumb band and the page title row under it.
2
+ import { div, svg, type Context, type Element } from "gpui-kit";
3
+ import { h_flex, Popover, v_flex } from "gpui-base";
4
+ import { HERDR_ICONS } from "../icons";
5
+ import { CARD, CRUMB, PANEL, PICKER, TEXT, TITLE } from "../tokens";
6
+ import { BUTTON_STYLE } from "../toolbar";
7
+ import { letThrough, type Hold, type Theme } from "./theme";
8
+
9
+ /**
10
+ * The separator drawn between crumbs.
11
+ * @param t The theme.
12
+ * @returns The separator.
13
+ */
14
+ export const crumbSeparator = (t: Theme): Element =>
15
+ div().flex_none().text_color(t.dim).child(CRUMB.separator);
16
+
17
+ /**
18
+ * The band under the top bar, ruled off above and below, holding the crumbs with a separator
19
+ * between each.
20
+ * @param t The theme.
21
+ * @param crumbs The crumbs, root first.
22
+ * @param id The band's id; default `breadcrumb`.
23
+ * @returns The band.
24
+ */
25
+ export function crumbBand(t: Theme, crumbs: readonly Element[], id = "breadcrumb"): Element {
26
+ return h_flex()
27
+ .id(id)
28
+ .flex_none()
29
+ .h(CRUMB.height)
30
+ .px(PANEL.padding)
31
+ .gap(CRUMB.gap)
32
+ .items_center()
33
+ .border_t(1)
34
+ .border_b(1)
35
+ .border_color(t.border)
36
+ .text_size(TEXT.label)
37
+ .text_color(t.muted)
38
+ .children(
39
+ crumbs.flatMap((crumb, index) => (index === 0 ? [crumb] : [crumbSeparator(t), crumb])),
40
+ );
41
+ }
42
+
43
+ /**
44
+ * What a {@link crumb} shows and does.
45
+ */
46
+ export type CrumbOptions = {
47
+ id: string;
48
+ label: string;
49
+ /**
50
+ * A leading mark, such as a status icon.
51
+ */
52
+ icon?: Element;
53
+ /**
54
+ * The trail ends here: drawn in the foreground.
55
+ */
56
+ current?: boolean;
57
+ /**
58
+ * Opens what the crumb names; without one the crumb is inert.
59
+ */
60
+ onClick?: (cx: Context) => void;
61
+ tooltip?: string;
62
+ /**
63
+ * Whether the label shrinks and truncates (default) or keeps its width, as a key does.
64
+ */
65
+ truncate?: boolean;
66
+ hold?: Hold;
67
+ };
68
+
69
+ /**
70
+ * One step of the trail: muted, foreground on hover when it opens something, and foreground when
71
+ * it is where the trail ends.
72
+ * @param t The theme.
73
+ * @param options What it shows and does.
74
+ * @returns The crumb.
75
+ */
76
+ export function crumb(t: Theme, options: CrumbOptions): Element {
77
+ const { onClick } = options;
78
+ const hold = options.hold ?? letThrough;
79
+ const label = div().child(options.label);
80
+ const item = h_flex()
81
+ .id(options.id)
82
+ .min_w_0()
83
+ .gap(CRUMB.itemGap)
84
+ .items_center()
85
+ .when(options.current === true, (el) => el.text_color(t.foreground))
86
+ .when(options.tooltip !== undefined, (el) => el.tooltip(options.tooltip!))
87
+ .when(onClick !== undefined, (el) =>
88
+ el
89
+ .cursor_pointer()
90
+ .hover((s) => s.text_color(t.foreground))
91
+ .on_click((_event, cx) => onClick!(cx)),
92
+ )
93
+ .when(options.icon !== undefined, (el) => el.child(options.icon!))
94
+ .child(options.truncate === false ? label.flex_none() : label.min_w_0().truncate());
95
+ return onClick === undefined ? item : hold(item);
96
+ }
97
+
98
+ /**
99
+ * One choice of a {@link crumbPicker}: its name and an optional icon in its own color.
100
+ */
101
+ export type PickerOption = {
102
+ name: string;
103
+ /**
104
+ * The icon's `svg()` path.
105
+ */
106
+ icon: string | undefined;
107
+ /**
108
+ * The icon's color (data, such as a user-picked color), else `muted`.
109
+ */
110
+ color: string | undefined;
111
+ };
112
+
113
+ /**
114
+ * What a {@link crumbPicker} offers.
115
+ */
116
+ export type CrumbPickerOptions = {
117
+ /**
118
+ * The picker's id; its parts are `<id>-crumb`, `<id>-chevron`, `<id>-popover`,
119
+ * `<id>-list` and `<id>-<choice name>` (`<id>-all` for the "any" row).
120
+ */
121
+ id: string;
122
+ /**
123
+ * What choosing nothing is called, like "All projects".
124
+ */
125
+ any: string;
126
+ choices: readonly PickerOption[];
127
+ /**
128
+ * The chosen option's name, or undefined for "any".
129
+ */
130
+ chosen: string | undefined;
131
+ open: boolean;
132
+ /**
133
+ * It's the last crumb, where the trail ends.
134
+ */
135
+ current: boolean;
136
+ /**
137
+ * Opens what the crumb names.
138
+ */
139
+ browse: (cx: Context) => void;
140
+ /**
141
+ * Picks a choice by name, or undefined for "any".
142
+ */
143
+ pick: (name: string | undefined, cx: Context) => void;
144
+ /**
145
+ * The popover opened or closed.
146
+ */
147
+ setOpen: (open: boolean, cx: Context) => void;
148
+ /**
149
+ * The chevron's tooltip; default `Switch <id>`.
150
+ */
151
+ switchTooltip?: string;
152
+ hold?: Hold;
153
+ };
154
+
155
+ const optionIcon = (t: Theme, option: PickerOption): Element =>
156
+ svg(option.icon!)
157
+ .size(BUTTON_STYLE.iconSize)
158
+ .flex_none()
159
+ .text_color((option.color as Theme[string] | undefined) ?? t.muted);
160
+
161
+ /**
162
+ * A breadcrumb with a dropdown: the chosen option (or "any") with its icon, which browses it when
163
+ * pressed, and a chevron after it, which opens a list of the others to switch to.
164
+ * @param t The theme.
165
+ * @param options What it offers.
166
+ * @returns The picker.
167
+ */
168
+ export function crumbPicker(t: Theme, options: CrumbPickerOptions): Element {
169
+ const hold = options.hold ?? letThrough;
170
+ const chosen = options.choices.find((choice) => choice.name === options.chosen);
171
+ const option = (choice: PickerOption | undefined) =>
172
+ h_flex()
173
+ .id(`${options.id}-${choice?.name ?? "all"}`)
174
+ .h(BUTTON_STYLE.height)
175
+ .flex_none()
176
+ .px(PICKER.optionPaddingX)
177
+ .gap(PICKER.optionGap)
178
+ .items_center()
179
+ .text_size(TEXT.label)
180
+ .text_color(choice?.name === chosen?.name ? t.foreground : t.muted)
181
+ .hover((style) => style.bg(t.hover))
182
+ .on_click((_event, cx) => options.pick(choice?.name, cx))
183
+ .when(choice?.icon !== undefined, (el) => el.child(optionIcon(t, choice!)))
184
+ .child(
185
+ div()
186
+ .flex_1()
187
+ .min_w_0()
188
+ .truncate()
189
+ .child(choice?.name ?? options.any),
190
+ )
191
+ .when(choice?.name === chosen?.name, (el) =>
192
+ el.child(svg(HERDR_ICONS.check).size(BUTTON_STYLE.iconSize).flex_none()),
193
+ );
194
+ const label = hold(
195
+ h_flex()
196
+ .id(`${options.id}-crumb`)
197
+ .gap(CRUMB.itemGap)
198
+ .items_center()
199
+ .min_w_0()
200
+ .cursor_pointer()
201
+ .text_color(options.current ? t.foreground : t.muted)
202
+ .hover((style) => style.text_color(t.foreground))
203
+ .tooltip(`Browse ${chosen?.name ?? options.any}`)
204
+ .on_click((_event, cx) => options.browse(cx))
205
+ .when(chosen?.icon !== undefined, (el) => el.child(optionIcon(t, chosen!)))
206
+ .child(
207
+ div()
208
+ .min_w_0()
209
+ .truncate()
210
+ .child(chosen?.name ?? options.any),
211
+ ),
212
+ );
213
+ const chevron = h_flex()
214
+ .id(`${options.id}-chevron`)
215
+ .px(PICKER.chevronPaddingX)
216
+ .items_center()
217
+ .cursor_pointer()
218
+ .hover((style) => style.bg(t.hover))
219
+ .rounded(PICKER.chevronRadius)
220
+ .tooltip(options.switchTooltip ?? `Switch ${options.id}`)
221
+ .child(svg(HERDR_ICONS.chevronDown).size(CARD.chevronSize).flex_none().text_color(t.dim));
222
+ return h_flex()
223
+ .gap(2)
224
+ .items_center()
225
+ .min_w_0()
226
+ .child(label)
227
+ .child(
228
+ Popover.new(`${options.id}-popover`)
229
+ .open(options.open)
230
+ .anchor("top_left")
231
+ .on_open_change((open, cx) => options.setOpen(open, cx))
232
+ .trigger(chevron)
233
+ .content(
234
+ v_flex()
235
+ .id(`${options.id}-list`)
236
+ .w(PICKER.width)
237
+ .max_h(PICKER.rows * BUTTON_STYLE.height)
238
+ .overflow_y_scroll()
239
+ .rounded(PICKER.radius)
240
+ .border_1()
241
+ .border_color(t.input)
242
+ .bg(t.popover)
243
+ .child(option(undefined))
244
+ .children(options.choices.map(option)),
245
+ ),
246
+ );
247
+ }
248
+
249
+ /**
250
+ * What a {@link titleRow} shows.
251
+ */
252
+ export type TitleRowOptions = {
253
+ /**
254
+ * The row's id; default `page-title`. Its parts are `<id>-icon` and `<id>-trailing`.
255
+ */
256
+ id?: string;
257
+ title: string;
258
+ /**
259
+ * A record's key or number, drawn muted before the title.
260
+ */
261
+ identifier?: string;
262
+ /**
263
+ * A leading icon, centered on the title's first line.
264
+ */
265
+ icon?: Element;
266
+ /**
267
+ * A trailing control, centered on the title's first line (a Copy ID button).
268
+ */
269
+ trailing?: Element;
270
+ };
271
+
272
+ /**
273
+ * The page's title in a row of its own under the breadcrumb band, ruled off below.
274
+ * @param t The theme.
275
+ * @param options What it shows.
276
+ * @returns The row.
277
+ */
278
+ export function titleRow(t: Theme, options: TitleRowOptions): Element {
279
+ const id = options.id ?? "page-title";
280
+ const lineBox = (part: string, child: Element) =>
281
+ h_flex().id(`${id}-${part}`).flex_none().h(TITLE.lineHeight).items_center().child(child);
282
+ return h_flex()
283
+ .id(id)
284
+ .flex_none()
285
+ .min_w_0()
286
+ .px(PANEL.padding)
287
+ .py(TITLE.paddingY)
288
+ .gap(TITLE.gap)
289
+ .items_start()
290
+ .border_b(1)
291
+ .border_color(t.border)
292
+ .text_size(TITLE.textSize)
293
+ .font_semibold()
294
+ .when(options.icon !== undefined, (el) => el.child(lineBox("icon", options.icon!)))
295
+ .when(options.identifier !== undefined && options.identifier !== "", (el) =>
296
+ el.child(div().flex_none().text_color(t.muted).child(options.identifier!)),
297
+ )
298
+ .child(div().flex_1().min_w_0().text_color(t.foreground).child(options.title))
299
+ .when(options.trailing !== undefined, (el) => el.child(lineBox("trailing", options.trailing!)));
300
+ }
301
+
302
+ /**
303
+ * A title row's icon at the title's icon size.
304
+ * @param t The theme.
305
+ * @param icon The `svg()` path.
306
+ * @param color Its color (data), else `muted`.
307
+ * @returns The icon.
308
+ */
309
+ export const titleIcon = (t: Theme, icon: string, color: string | undefined = undefined): Element =>
310
+ svg(icon)
311
+ .size(TITLE.iconSize)
312
+ .flex_none()
313
+ .text_color((color as Theme[string] | undefined) ?? t.muted);
@@ -0,0 +1,120 @@
1
+ // A collapsible markdown document card: native Markdown, clipped to a preview with a fade, and a
2
+ // control below to reveal or re-collapse it.
3
+ import { div, type Color, type Context, type Element } from "gpui-kit";
4
+ import { h_flex, TextView, v_flex } from "gpui-base";
5
+ import { opaqueOver } from "../color";
6
+ import { HERDR_ICONS } from "../icons";
7
+ import { DOCUMENT, TEXT } from "../tokens";
8
+ import { card, cardBody, cardHeader, cardNote, cardSection } from "./cards";
9
+ import { button } from "./controls";
10
+ import type { Theme } from "./theme";
11
+
12
+ /**
13
+ * A fade over a clipped preview's bottom. A translucent card exposes the host surface, so the
14
+ * bands paint that visible color at full alpha and the ramp, not the card's alpha, sets the
15
+ * fade's strength.
16
+ * @param t The theme.
17
+ * @param id The fade's id.
18
+ * @param surface The paint behind the card.
19
+ * @returns The fade, absolute over its parent.
20
+ */
21
+ export function documentFade(t: Theme, id: string, surface: Color): Element {
22
+ const background = opaqueOver(t.canvas, surface) as Color;
23
+ const bandHeight = DOCUMENT.fadeHeight / DOCUMENT.fadeOpacities.length;
24
+ return v_flex()
25
+ .id(id)
26
+ .absolute()
27
+ .inset_0()
28
+ .justify_end()
29
+ .children(
30
+ DOCUMENT.fadeOpacities.map((opacity) =>
31
+ div().h(bandHeight).flex_none().bg(background).opacity(opacity),
32
+ ),
33
+ );
34
+ }
35
+
36
+ /**
37
+ * What a {@link documentCard} shows.
38
+ */
39
+ export type DocumentCardOptions = {
40
+ /**
41
+ * Qualifies every part's id (`document-card-<id>`, `document-<id>`…), isolating its UI state.
42
+ */
43
+ id: string;
44
+ /**
45
+ * The section's header; default `Document`.
46
+ */
47
+ title?: string;
48
+ /**
49
+ * The markdown.
50
+ */
51
+ text: string;
52
+ /**
53
+ * What an empty document says; default `No document`.
54
+ */
55
+ empty?: string;
56
+ open: boolean;
57
+ /**
58
+ * A collapsed preview's height cap in px; {@link DOCUMENT.previewViewportRatio} times the
59
+ * window's height gives the Tasks panel's.
60
+ */
61
+ previewHeight: number;
62
+ /**
63
+ * The paint behind the card (`surface` in a pane, `popover` in an overlay).
64
+ */
65
+ surface: Color;
66
+ toggle: (cx: Context) => void;
67
+ };
68
+
69
+ /**
70
+ * A document card: its header, then the markdown, collapsed to a faded preview until revealed.
71
+ * @param t The theme.
72
+ * @param options What it shows.
73
+ * @returns The section.
74
+ */
75
+ export function documentCard(t: Theme, options: DocumentCardOptions): Element {
76
+ const { id, open } = options;
77
+ const header = cardHeader(t, `document-header-${id}`, options.title ?? "Document");
78
+ if (options.text.trim() === "")
79
+ return cardSection(
80
+ header,
81
+ card(t, `document-card-${id}`).child(cardNote(t, options.empty ?? "No document")),
82
+ );
83
+ const markdown = TextView.markdown(`document-${id}`, options.text)
84
+ .selectable()
85
+ .text_size(TEXT.body)
86
+ .text_color(t.foreground);
87
+ const content = open
88
+ ? markdown
89
+ : v_flex()
90
+ .id(`document-preview-${id}`)
91
+ .w_full()
92
+ .relative()
93
+ .max_h(options.previewHeight)
94
+ .overflow_hidden()
95
+ .child(markdown)
96
+ .child(documentFade(t, `document-fade-${id}`, options.surface));
97
+ return cardSection(
98
+ header,
99
+ card(t, `document-card-${id}`).child(
100
+ cardBody().child(
101
+ v_flex()
102
+ .gap(DOCUMENT.gap)
103
+ .child(content)
104
+ .child(
105
+ h_flex()
106
+ .w_full()
107
+ .justify_center()
108
+ .child(
109
+ button(t, {
110
+ id: `document-toggle-${id}`,
111
+ icon: open ? HERDR_ICONS.chevronDown : HERDR_ICONS.chevronRight,
112
+ label: open ? "Show less" : "Reveal more",
113
+ onClick: options.toggle,
114
+ }),
115
+ ),
116
+ ),
117
+ ),
118
+ ),
119
+ );
120
+ }
@@ -0,0 +1,177 @@
1
+ // The panel's frame: the root, the chrome top bar with its brand and tool row, the padded body,
2
+ // and the footer strip. A pane fills its space on the theme's surface; a floating overlay draws
3
+ // inside Herdr's frame at a fixed width.
4
+ import { div, svg, type Element } from "gpui-kit";
5
+ import { h_flex, v_flex } from "gpui-base";
6
+ import { BRAND, PANEL } from "../tokens";
7
+ import { BUTTON_STYLE, TOOL_GAP } from "../toolbar";
8
+ import type { Theme } from "./theme";
9
+
10
+ /**
11
+ * How a column takes height. In a pane (`scrollCap` undefined) it fills the space left. A
12
+ * floating overlay sizes to its content, where a 0 flex basis would collapse it, so there it
13
+ * keeps its content's height.
14
+ * @param el The column.
15
+ * @param scrollCap The overlay's body height cap, or undefined in a pane.
16
+ * @returns The column.
17
+ */
18
+ export const fill = (el: Element, scrollCap: number | undefined): Element =>
19
+ scrollCap === undefined ? el.flex_1().min_h_0() : el.flex_none();
20
+
21
+ /**
22
+ * The panel's root column.
23
+ * @param t The theme.
24
+ * @param id The root's id.
25
+ * @param floatWidth The overlay's width, or undefined in a pane, where the root fills its block
26
+ * on `surface` with rounded top corners.
27
+ * @returns The root; add the top bar, bands and body as children.
28
+ */
29
+ export const panelFrame = (t: Theme, id: string, floatWidth: number | undefined): Element =>
30
+ v_flex()
31
+ .id(id)
32
+ .when(floatWidth === undefined, (el) =>
33
+ el.size_full().bg(t.surface).rounded_t(PANEL.frameRadius),
34
+ )
35
+ .when(floatWidth !== undefined, (el) => el.w(floatWidth!));
36
+
37
+ /**
38
+ * The top bar: a `chrome` band holding the tool row. Floating, its backdrop reaches up over the
39
+ * strip Herdr's frame leaves above the content and rounds to match; it's absolute, so the
40
+ * frame's size, which Herdr measures from the layout, ignores it.
41
+ * @param t The theme.
42
+ * @param options `floating` in an overlay; `content` is the tool row; `id` defaults to
43
+ * `tool-bar`.
44
+ * @returns The bar.
45
+ */
46
+ export function topBar(
47
+ t: Theme,
48
+ options: { floating: boolean; content: Element; id?: string },
49
+ ): Element {
50
+ const { floating } = options;
51
+ return v_flex()
52
+ .id(options.id ?? "tool-bar")
53
+ .flex_none()
54
+ .px(PANEL.padding)
55
+ .py(PANEL.barPaddingY)
56
+ .when(floating, (el) => el.pt(PANEL.barPaddingY - PANEL.frameTopInset - 1))
57
+ .relative()
58
+ .when(!floating, (el) => el.bg(t.chrome).rounded_t(PANEL.frameRadius))
59
+ .when(floating, (el) =>
60
+ el.child(
61
+ div()
62
+ .absolute()
63
+ .top(-PANEL.frameTopInset)
64
+ .left(0)
65
+ .right(0)
66
+ .bottom(0)
67
+ .bg(t.chrome)
68
+ .rounded_t(PANEL.frameRadius),
69
+ ),
70
+ )
71
+ .child(options.content);
72
+ }
73
+
74
+ /**
75
+ * A panel's mark and name, as tall as the buttons: the mark in the accent color and the name in
76
+ * the foreground.
77
+ * @param t The theme.
78
+ * @param options The mark's `svg()` path, the name, and the id (default `brand`).
79
+ * @returns The brand.
80
+ */
81
+ export const brand = (t: Theme, options: { icon: string; name: string; id?: string }): Element =>
82
+ h_flex()
83
+ .id(options.id ?? "brand")
84
+ .h(BUTTON_STYLE.height)
85
+ .flex_none()
86
+ .gap(BRAND.gap)
87
+ .items_center()
88
+ .child(svg(options.icon).size(BRAND.iconSize).flex_none().text_color(t.accent))
89
+ .child(
90
+ div().text_size(BRAND.textSize).font_semibold().text_color(t.foreground).child(options.name),
91
+ );
92
+
93
+ /**
94
+ * The tool row inside the top bar.
95
+ * @param options `fixed` keeps one line (the overlay: fit labels first with `fitLabels`), with
96
+ * the brand and `leading` tools at the start and `trailing` ones at the end, the free space
97
+ * between them dragging the overlay. Otherwise (a pane) the row wraps and every tool sits at
98
+ * the end. `id` defaults to `bar`.
99
+ * @returns The row.
100
+ */
101
+ export function toolRow(options: {
102
+ fixed: boolean;
103
+ brand?: Element;
104
+ leading: readonly Element[];
105
+ trailing: readonly Element[];
106
+ id?: string;
107
+ }): Element {
108
+ const id = options.id ?? "bar";
109
+ const spacer = () => div().flex_1().min_w_0().h(BUTTON_STYLE.height);
110
+ if (options.fixed)
111
+ return h_flex()
112
+ .id(id)
113
+ .gap(TOOL_GAP)
114
+ .items_center()
115
+ .when(options.brand !== undefined, (el) => el.child(options.brand!))
116
+ .children([...options.leading])
117
+ .child(spacer())
118
+ .children([...options.trailing]);
119
+ return h_flex()
120
+ .id(id)
121
+ .flex_wrap()
122
+ .justify_between()
123
+ .gap(TOOL_GAP)
124
+ .items_center()
125
+ .when(options.brand !== undefined, (el) => el.child(options.brand!))
126
+ .child(spacer())
127
+ .child(
128
+ h_flex()
129
+ .flex_wrap()
130
+ .gap(TOOL_GAP)
131
+ .children([...options.leading, ...options.trailing]),
132
+ );
133
+ }
134
+
135
+ /**
136
+ * The padded body under the bands, holding the screen's content column.
137
+ * @param options The body's id (default `panel-body`), the overlay's height cap (undefined in a
138
+ * pane), `hold` for the content column, and the content.
139
+ * @returns The body.
140
+ */
141
+ export function panelBody(options: {
142
+ scrollCap: number | undefined;
143
+ hold: <E extends Element>(el: E) => E;
144
+ content: Element;
145
+ id?: string;
146
+ }): Element {
147
+ const id = options.id ?? "panel-body";
148
+ return fill(v_flex().id(id), options.scrollCap)
149
+ .min_w_0()
150
+ .p(PANEL.padding)
151
+ .child(
152
+ fill(options.hold(v_flex().id(`${id}-content`)), options.scrollCap)
153
+ .min_w_0()
154
+ .gap(PANEL.contentGap)
155
+ .child(options.content),
156
+ );
157
+ }
158
+
159
+ /**
160
+ * A footer strip ruled off above, like the diagnostics footer.
161
+ * @param t The theme.
162
+ * @param id The strip's id.
163
+ * @param children Its contents, start to end; put `div().flex_1()` between groups.
164
+ * @returns The strip.
165
+ */
166
+ export const panelFooter = (t: Theme, id: string, children: readonly Element[]): Element =>
167
+ h_flex()
168
+ .id(id)
169
+ .flex_none()
170
+ .flex_wrap()
171
+ .px(PANEL.padding)
172
+ .py(PANEL.barPaddingY)
173
+ .gap(PANEL.contentGap)
174
+ .items_center()
175
+ .border_t(1)
176
+ .border_color(t.border)
177
+ .children([...children]);
package/src/ui/menu.ts ADDED
@@ -0,0 +1,55 @@
1
+ // The compact property menu's surface and search input.
2
+ import { div, type Element } from "gpui-kit";
3
+ import { Input, type InputState, v_flex } from "gpui-base";
4
+ import { MENU } from "../menu-metrics";
5
+ import { MENU_SURFACE } from "../tokens";
6
+ import type { Theme } from "./theme";
7
+
8
+ /**
9
+ * A compact menu panel on `popover`. It consumes presses so an outside-dismiss surface beneath
10
+ * doesn't close it.
11
+ * @param t The theme.
12
+ * @param width The panel's width.
13
+ * @param padding Its padding; default the Task menu's.
14
+ * @returns The panel; add rows as children.
15
+ */
16
+ export const menuPanel = (t: Theme, width: number, padding: number = MENU.padding): Element =>
17
+ v_flex()
18
+ .w(width)
19
+ .flex_none()
20
+ .p(padding)
21
+ .rounded(MENU_SURFACE.radius)
22
+ .bg(t.popover)
23
+ .border_1()
24
+ .border_color(t.border)
25
+ .text_color(t.foreground)
26
+ .on_mouse_down("left", (_event, cx) => cx.stop_propagation())
27
+ .on_mouse_down("right", (_event, cx) => cx.stop_propagation());
28
+
29
+ /**
30
+ * A menu's native search input, keeping the caller's keyboard context.
31
+ * @param t The theme.
32
+ * @param input The input's state, created outside render.
33
+ * @param context The key context its bindings use.
34
+ * @param height Its height; default the Task menu's.
35
+ * @returns The input.
36
+ */
37
+ export const menuInput = (
38
+ t: Theme,
39
+ input: InputState,
40
+ context: string,
41
+ height: number = MENU.inputHeight,
42
+ ): Element =>
43
+ div()
44
+ .h(height)
45
+ .flex_none()
46
+ .key_context(context)
47
+ .child(
48
+ Input.new(input)
49
+ .h(height)
50
+ .px(MENU_SURFACE.inputPaddingX)
51
+ .rounded(MENU_SURFACE.inputRadius)
52
+ .border_1()
53
+ .border_color(t.input)
54
+ .text_size(MENU_SURFACE.inputTextSize),
55
+ );