@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.
- package/LICENSE +21 -0
- package/NOTICE.md +15 -0
- package/README.md +94 -2
- package/assets/icons/anchor-off.svg +4 -0
- package/assets/icons/anchor.svg +4 -0
- package/assets/icons/copy.svg +16 -0
- package/assets/icons/external-link.svg +5 -0
- package/assets/icons/globe.svg +1 -0
- package/assets/icons/log-in.svg +5 -0
- package/assets/icons/pin-filled.svg +1 -0
- package/assets/icons/return.svg +3 -0
- package/licenses/lucide.txt +43 -0
- package/package.json +54 -4
- package/src/assets.ts +33 -0
- package/src/color.ts +58 -0
- package/src/icons.ts +121 -0
- package/src/index.ts +15 -0
- package/src/menu-metrics.ts +117 -0
- package/src/pure.ts +8 -0
- package/src/record-scrolls.ts +50 -0
- package/src/tokens.ts +278 -0
- package/src/toolbar.ts +115 -0
- package/src/ui/cards.ts +305 -0
- package/src/ui/chips.ts +110 -0
- package/src/ui/controls.ts +83 -0
- package/src/ui/crumbs.ts +313 -0
- package/src/ui/document.ts +120 -0
- package/src/ui/frame.ts +177 -0
- package/src/ui/menu.ts +55 -0
- package/src/ui/scroll.ts +64 -0
- package/src/ui/states.ts +61 -0
- package/src/ui/tabs.ts +63 -0
- package/src/ui/theme.ts +37 -0
package/src/ui/scroll.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Scroll regions: a pane's bounded viewport with its scrollbar in the gutter, and an overlay's
|
|
2
|
+
// height-capped one.
|
|
3
|
+
import type { Element } from "gpui-kit";
|
|
4
|
+
import { Scrollbar, v_flex, type ScrollHandle } from "gpui-base";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A bounded pane viewport with an explicit scrollbar in the existing right gutter.
|
|
8
|
+
* @param id The viewport's id, which also pairs its scrollbar.
|
|
9
|
+
* @param content The scrolling content.
|
|
10
|
+
* @param rightGutter The gutter the scrollbar extends into (the panel's padding).
|
|
11
|
+
* @param handle An existing scroll handle, created outside render; its lifetime is the caller's.
|
|
12
|
+
* @returns The frame holding the viewport and its scrollbar.
|
|
13
|
+
*/
|
|
14
|
+
export function paneScrollRegion(
|
|
15
|
+
id: string,
|
|
16
|
+
content: Element,
|
|
17
|
+
rightGutter: number,
|
|
18
|
+
handle: ScrollHandle | undefined = undefined,
|
|
19
|
+
): Element {
|
|
20
|
+
const viewport = v_flex()
|
|
21
|
+
.id(id)
|
|
22
|
+
.flex_1()
|
|
23
|
+
.min_h_0()
|
|
24
|
+
.min_w_0()
|
|
25
|
+
.overflow_y_scroll()
|
|
26
|
+
.when(handle !== undefined, (el) => el.track_scroll(handle!));
|
|
27
|
+
|
|
28
|
+
return v_flex()
|
|
29
|
+
.id(`${id}-frame`)
|
|
30
|
+
.relative()
|
|
31
|
+
.flex_1()
|
|
32
|
+
.min_h_0()
|
|
33
|
+
.min_w_0()
|
|
34
|
+
.child(viewport.child(content))
|
|
35
|
+
.child(Scrollbar.vertical(id).viewport_from_layout().absolute().inset_0().right(-rightGutter));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A floating overlay's viewport: it takes its content's height up to a cap, then scrolls.
|
|
40
|
+
* @param id The viewport's id, which also pairs its scrollbar.
|
|
41
|
+
* @param maxHeight The cap.
|
|
42
|
+
* @param content The scrolling content.
|
|
43
|
+
* @param handle An existing scroll handle, created outside render.
|
|
44
|
+
* @returns The viewport with its scrollbar.
|
|
45
|
+
*/
|
|
46
|
+
export const floatScrollRegion = (
|
|
47
|
+
id: string,
|
|
48
|
+
maxHeight: number,
|
|
49
|
+
content: Element,
|
|
50
|
+
handle: ScrollHandle | undefined = undefined,
|
|
51
|
+
): Element =>
|
|
52
|
+
v_flex()
|
|
53
|
+
.relative()
|
|
54
|
+
.flex_none()
|
|
55
|
+
.min_w_0()
|
|
56
|
+
.child(
|
|
57
|
+
v_flex()
|
|
58
|
+
.id(id)
|
|
59
|
+
.max_h(maxHeight)
|
|
60
|
+
.overflow_y_scroll()
|
|
61
|
+
.when(handle !== undefined, (el) => el.track_scroll(handle!))
|
|
62
|
+
.child(content),
|
|
63
|
+
)
|
|
64
|
+
.child(Scrollbar.vertical(id).absolute().inset_0());
|
package/src/ui/states.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Empty, error and loading blocks: a title, an optional detail and an optional action.
|
|
2
|
+
import { div, type Element } from "gpui-kit";
|
|
3
|
+
import { h_flex, v_flex } from "gpui-base";
|
|
4
|
+
import { STATE, TEXT } from "../tokens";
|
|
5
|
+
import type { Theme } from "./theme";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* What a state block says.
|
|
9
|
+
*/
|
|
10
|
+
export type StateOptions = {
|
|
11
|
+
title: string;
|
|
12
|
+
detail?: string;
|
|
13
|
+
/**
|
|
14
|
+
* A control below, like a Sign in or Retry button.
|
|
15
|
+
*/
|
|
16
|
+
action?: Element;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A message block: the title in the foreground, its detail muted, then an optional action.
|
|
21
|
+
* @param t The theme.
|
|
22
|
+
* @param options What it says.
|
|
23
|
+
* @returns The block.
|
|
24
|
+
*/
|
|
25
|
+
export const stateBlock = (t: Theme, options: StateOptions): Element =>
|
|
26
|
+
v_flex()
|
|
27
|
+
.gap(STATE.gap)
|
|
28
|
+
.child(div().text_size(TEXT.body).font_medium().text_color(t.foreground).child(options.title))
|
|
29
|
+
.when(options.detail !== undefined, (el) =>
|
|
30
|
+
el.child(div().text_size(TEXT.label).text_color(t.muted).child(options.detail!)),
|
|
31
|
+
)
|
|
32
|
+
.when(options.action !== undefined, (el) => el.child(h_flex().child(options.action!)));
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Nothing to show yet, and how to get something.
|
|
36
|
+
* @param t The theme.
|
|
37
|
+
* @param options What it says.
|
|
38
|
+
* @returns The block.
|
|
39
|
+
*/
|
|
40
|
+
export const emptyState = (t: Theme, options: StateOptions): Element => stateBlock(t, options);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Something failed: what, why, and maybe a retry.
|
|
44
|
+
* @param t The theme.
|
|
45
|
+
* @param options What it says.
|
|
46
|
+
* @returns The block.
|
|
47
|
+
*/
|
|
48
|
+
export const errorState = (t: Theme, options: StateOptions): Element => stateBlock(t, options);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Work in progress.
|
|
52
|
+
* @param t The theme.
|
|
53
|
+
* @param title What is loading; default `Loading…`.
|
|
54
|
+
* @param detail What the person can do meanwhile.
|
|
55
|
+
* @returns The block.
|
|
56
|
+
*/
|
|
57
|
+
export const loadingState = (
|
|
58
|
+
t: Theme,
|
|
59
|
+
title = "Loading…",
|
|
60
|
+
detail: string | undefined = undefined,
|
|
61
|
+
): Element => stateBlock(t, detail === undefined ? { title } : { title, detail });
|
package/src/ui/tabs.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// A tab bar sized like the panel's buttons.
|
|
2
|
+
import { div, type Context, type Element } from "gpui-kit";
|
|
3
|
+
import { h_flex } from "gpui-base";
|
|
4
|
+
import { TAB } from "../tokens";
|
|
5
|
+
import type { Theme } from "./theme";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* One tab.
|
|
9
|
+
*/
|
|
10
|
+
export type TabItem<Id extends string = string> = {
|
|
11
|
+
id: Id;
|
|
12
|
+
label: string;
|
|
13
|
+
selected: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The tab bar. The selected tab takes the theme's `selected` fill and the foreground; the others
|
|
18
|
+
* are muted with a hover fill, or dimmed and inert while `locked`.
|
|
19
|
+
* @param t The theme.
|
|
20
|
+
* @param options The bar's id (each tab is `<id>-<tab id>`), its tabs, whether switching is
|
|
21
|
+
* refused, and the handler.
|
|
22
|
+
* @returns The tab bar.
|
|
23
|
+
*/
|
|
24
|
+
export function tabBar<Id extends string>(
|
|
25
|
+
t: Theme,
|
|
26
|
+
options: {
|
|
27
|
+
id: string;
|
|
28
|
+
tabs: readonly TabItem<Id>[];
|
|
29
|
+
locked?: boolean;
|
|
30
|
+
onTab: (tab: Id, cx: Context) => void;
|
|
31
|
+
},
|
|
32
|
+
): Element {
|
|
33
|
+
const locked = options.locked ?? false;
|
|
34
|
+
return h_flex()
|
|
35
|
+
.id(options.id)
|
|
36
|
+
.flex_shrink_0()
|
|
37
|
+
.min_w(0)
|
|
38
|
+
.gap(TAB.gap)
|
|
39
|
+
.items_center()
|
|
40
|
+
.children(
|
|
41
|
+
options.tabs.map((tab) =>
|
|
42
|
+
div()
|
|
43
|
+
.id(`${options.id}-${tab.id}`)
|
|
44
|
+
.flex_shrink_0()
|
|
45
|
+
.h(TAB.height)
|
|
46
|
+
.px(TAB.paddingX)
|
|
47
|
+
.flex()
|
|
48
|
+
.items_center()
|
|
49
|
+
.rounded(TAB.radius)
|
|
50
|
+
.text_size(TAB.textSize)
|
|
51
|
+
.when(tab.selected, (item) => item.bg(t.selected).text_color(t.foreground))
|
|
52
|
+
.when(!tab.selected, (item) =>
|
|
53
|
+
item.text_color(locked ? t.dim : t.muted).when(!locked, (item) =>
|
|
54
|
+
item
|
|
55
|
+
.cursor_pointer()
|
|
56
|
+
.hover((style) => style.bg(t.hover))
|
|
57
|
+
.on_click((_event, cx) => options.onTab(tab.id, cx)),
|
|
58
|
+
),
|
|
59
|
+
)
|
|
60
|
+
.child(tab.label),
|
|
61
|
+
),
|
|
62
|
+
);
|
|
63
|
+
}
|
package/src/ui/theme.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Color, Element } from "gpui-kit";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The host theme's colors by role, read once per render with `theme()` and passed to every
|
|
5
|
+
* element function.
|
|
6
|
+
*/
|
|
7
|
+
export type Theme = Record<string, Color>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Keeps a press on an element from reaching what holds it. A floating overlay stops presses on
|
|
11
|
+
* its controls, since Herdr drags a floating block by any press the mod doesn't stop; a pane lets
|
|
12
|
+
* them through, so a click still focuses the pane.
|
|
13
|
+
*/
|
|
14
|
+
export type Hold = <E extends Element>(el: E) => E;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The pane's {@link Hold}: presses pass through.
|
|
18
|
+
* @param el The element.
|
|
19
|
+
* @returns It unchanged.
|
|
20
|
+
*/
|
|
21
|
+
export const letThrough: Hold = (el) => el;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The floating overlay's {@link Hold}: a left press stops at the element.
|
|
25
|
+
* @param el The element.
|
|
26
|
+
* @returns It, stopping left presses.
|
|
27
|
+
*/
|
|
28
|
+
export const stopPress: Hold = (el) =>
|
|
29
|
+
el.on_mouse_down("left", (_event, cx) => cx.stop_propagation());
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A theme role's color, for a role name held as data (a tone).
|
|
33
|
+
* @param t The theme.
|
|
34
|
+
* @param role The role name.
|
|
35
|
+
* @returns Its color.
|
|
36
|
+
*/
|
|
37
|
+
export const role = (t: Theme, role: string): Color => t[role] as Color;
|