@tokamaq/ui 0.0.0-stage → 0.1.0-dev.1
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/README.md +23 -2
- package/lint/index.js +22 -0
- package/lint/oxlint.json +58 -0
- package/lint/plugin.js +411 -0
- package/package.json +82 -4
- package/src/avatar.tsx +34 -0
- package/src/button.tsx +109 -0
- package/src/chip.tsx +52 -0
- package/src/cn.ts +71 -0
- package/src/code-block.tsx +58 -0
- package/src/collapsible.tsx +76 -0
- package/src/command.tsx +101 -0
- package/src/dialog.tsx +93 -0
- package/src/file-name.tsx +41 -0
- package/src/fonts/Geist-Variable.woff2 +0 -0
- package/src/fonts/GeistMono-Variable.woff2 +0 -0
- package/src/fonts/OFL.txt +92 -0
- package/src/fonts.css +15 -0
- package/src/icon.tsx +30 -0
- package/src/icons.ts +23 -0
- package/src/index.ts +24 -0
- package/src/input.tsx +86 -0
- package/src/kbd.tsx +33 -0
- package/src/kit/command.tsx +45 -0
- package/src/kit/contrast.ts +31 -0
- package/src/kit/controls.tsx +233 -0
- package/src/kit/disclosure.tsx +39 -0
- package/src/kit/frame.tsx +34 -0
- package/src/kit/inputs.tsx +53 -0
- package/src/kit/kit.tsx +76 -0
- package/src/kit/overlays.tsx +79 -0
- package/src/kit/rows.tsx +160 -0
- package/src/kit/tokens.tsx +189 -0
- package/src/menu.tsx +99 -0
- package/src/resizable.tsx +40 -0
- package/src/row-list.tsx +65 -0
- package/src/row.tsx +147 -0
- package/src/scroll-area.tsx +64 -0
- package/src/select.tsx +67 -0
- package/src/status-icon.tsx +49 -0
- package/src/switch.tsx +73 -0
- package/src/tabs.tsx +44 -0
- package/src/textarea.tsx +30 -0
- package/src/theme.css +397 -0
- package/src/tooltip.tsx +40 -0
- package/tests/setup.ts +29 -0
package/src/menu.tsx
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<Menu.Root onAction={run}>
|
|
3
|
+
<Menu.Trigger variant="ghost" icon={icons.more} label="Thread actions" />
|
|
4
|
+
<Menu.Content>
|
|
5
|
+
<Menu.Item value="archive" shortcut="mod+e">Archive</Menu.Item>
|
|
6
|
+
<Menu.Separator />
|
|
7
|
+
<Menu.Item value="delete" destructive>Delete</Menu.Item>
|
|
8
|
+
</Menu.Content>
|
|
9
|
+
</Menu.Root>
|
|
10
|
+
|
|
11
|
+
A card with 4 padding and radius 12; items are 32 rows with radius 8. A list
|
|
12
|
+
taller than the room beside its trigger scrolls.
|
|
13
|
+
The trigger takes the Button look props.
|
|
14
|
+
*/
|
|
15
|
+
import * as Base from "@ui-sdk/solid/menu";
|
|
16
|
+
import { omit } from "solid-js";
|
|
17
|
+
import type { ComponentProps, JSX } from "@solidjs/web";
|
|
18
|
+
import { ButtonContent, buttonClass, lookKeys, type ButtonLook } from "./button.tsx";
|
|
19
|
+
import { cn } from "./cn.ts";
|
|
20
|
+
import { Icon } from "./icon.tsx";
|
|
21
|
+
import { icons } from "./icons.ts";
|
|
22
|
+
|
|
23
|
+
type Classed<T extends (props: any) => JSX.Element> = Omit<ComponentProps<T>, "class"> & { class?: string };
|
|
24
|
+
|
|
25
|
+
export const popupClass = [
|
|
26
|
+
"z-50 m-0 flex min-w-menu flex-col rounded-md border-0 surface-card p-1 inset-ring inset-ring-edge outline-none",
|
|
27
|
+
// The positioner sets --available-height: a long list (many models, say) scrolls inside the window.
|
|
28
|
+
"max-h-(--available-height) overflow-y-auto overscroll-contain",
|
|
29
|
+
"transition duration-150 data-starting-style:opacity-0 data-ending-style:opacity-0",
|
|
30
|
+
];
|
|
31
|
+
export const itemClass = [
|
|
32
|
+
"flex h-8 cursor-default items-center gap-2 rounded-sm px-2 text-row text-ink outline-none select-none",
|
|
33
|
+
"data-highlighted:bg-hover data-disabled:text-ink-3",
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
export const Root = Base.Menu;
|
|
37
|
+
|
|
38
|
+
export function Trigger(
|
|
39
|
+
props: Omit<ComponentProps<typeof Base.MenuTrigger>, "children" | "class"> & ButtonLook,
|
|
40
|
+
) {
|
|
41
|
+
const rest = omit(props, ...lookKeys);
|
|
42
|
+
return (
|
|
43
|
+
<Base.MenuTrigger {...rest} class={buttonClass(props)} aria-label={props.label}>
|
|
44
|
+
<ButtonContent {...props} />
|
|
45
|
+
</Base.MenuTrigger>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function Content(props: Classed<typeof Base.MenuContent>) {
|
|
50
|
+
return <Base.MenuContent {...omit(props, "class")} class={cn(popupClass, props.class)} />;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function Item(props: Classed<typeof Base.MenuItem>) {
|
|
54
|
+
return (
|
|
55
|
+
<Base.MenuItem
|
|
56
|
+
{...omit(props, "class")}
|
|
57
|
+
class={cn(
|
|
58
|
+
itemClass,
|
|
59
|
+
"data-destructive:text-removed *:data-[slot=menu-shortcut]:ms-auto *:data-[slot=menu-shortcut]:ps-4",
|
|
60
|
+
"*:data-[slot=menu-shortcut]:text-data *:data-[slot=menu-shortcut]:text-ink-3",
|
|
61
|
+
props.class,
|
|
62
|
+
)}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function Separator(props: Classed<typeof Base.MenuSeparator>) {
|
|
68
|
+
return (
|
|
69
|
+
<Base.MenuSeparator
|
|
70
|
+
{...omit(props, "class")}
|
|
71
|
+
class={cn("-mx-1 my-1 h-px border-0 bg-edge", props.class)}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function GroupLabel(props: Classed<typeof Base.MenuGroupLabel>) {
|
|
77
|
+
return (
|
|
78
|
+
<Base.MenuGroupLabel
|
|
79
|
+
{...omit(props, "class")}
|
|
80
|
+
class={cn("flex h-6 items-center px-2 text-label text-ink-3", props.class)}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const Group = Base.MenuGroup;
|
|
86
|
+
|
|
87
|
+
export const RadioGroup = Base.MenuRadioGroup;
|
|
88
|
+
|
|
89
|
+
/** A choice of one in its RadioGroup; the chosen item shows a check at the end. */
|
|
90
|
+
export function RadioItem(props: Classed<typeof Base.MenuRadioItem>) {
|
|
91
|
+
return (
|
|
92
|
+
<Base.MenuRadioItem {...omit(props, "class", "children")} class={cn(itemClass, props.class)}>
|
|
93
|
+
{props.children}
|
|
94
|
+
<Base.MenuItemIndicator class="ms-auto ps-4 text-ink-2">
|
|
95
|
+
<Icon path={icons.check} />
|
|
96
|
+
</Base.MenuItemIndicator>
|
|
97
|
+
</Base.MenuRadioItem>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<Resizable.Root autoSaveId="frame">
|
|
3
|
+
<Resizable.Panel id="stage" minSize="400px">…</Resizable.Panel>
|
|
4
|
+
<Resizable.Handle aria-label="Resize panel" />
|
|
5
|
+
<Resizable.Panel id="panel" defaultSize="600px" minSize="360px">…</Resizable.Panel>
|
|
6
|
+
</Resizable.Root>
|
|
7
|
+
|
|
8
|
+
Panels side by side with a draggable divider between them. The handle is
|
|
9
|
+
the 4 px gap between two surfaces, a quiet line on hover and while dragged;
|
|
10
|
+
its hit area is wider than it looks, and arrow keys move it when focused.
|
|
11
|
+
autoSaveId keeps the sizes in this device's storage.
|
|
12
|
+
*/
|
|
13
|
+
import * as Base from "@ui-sdk/solid/resizable";
|
|
14
|
+
import { omit } from "solid-js";
|
|
15
|
+
import type { ComponentProps, JSX } from "@solidjs/web";
|
|
16
|
+
import { cn } from "./cn.ts";
|
|
17
|
+
|
|
18
|
+
type Classed<T extends (props: any) => JSX.Element> = Omit<ComponentProps<T>, "class"> & { class?: string };
|
|
19
|
+
|
|
20
|
+
export function Root(props: Classed<typeof Base.Resizable>): JSX.Element {
|
|
21
|
+
return <Base.Resizable {...omit(props, "class")} class={cn("flex min-h-0 min-w-0", props.class)} />;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function Panel(props: Classed<typeof Base.ResizablePanel>): JSX.Element {
|
|
25
|
+
return <Base.ResizablePanel {...omit(props, "class")} class={cn("flex min-h-0 min-w-0", props.class)} />;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function Handle(props: Omit<Classed<typeof Base.ResizableHandle>, "children">): JSX.Element {
|
|
29
|
+
return (
|
|
30
|
+
<Base.ResizableHandle
|
|
31
|
+
{...omit(props, "class")}
|
|
32
|
+
class={cn(
|
|
33
|
+
"group/handle relative flex w-1 shrink-0 cursor-col-resize justify-center focus-ring",
|
|
34
|
+
props.class,
|
|
35
|
+
)}
|
|
36
|
+
>
|
|
37
|
+
<span class="my-2 w-px rounded-full transition duration-200 group-data-hovering/handle:bg-edge-strong group-data-dragging/handle:bg-edge-strong" />
|
|
38
|
+
</Base.ResizableHandle>
|
|
39
|
+
);
|
|
40
|
+
}
|
package/src/row-list.tsx
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<RowList.Root aria-label="Threads" value={current()} onValueChange={open}>
|
|
3
|
+
<RowList.Option value="a" kind="double" lead={…} detail="sonnet 4.5" sub={<Row kind="half">…</Row>}>
|
|
4
|
+
Add CSV export
|
|
5
|
+
</RowList.Option>
|
|
6
|
+
<RowList.Group>
|
|
7
|
+
<RowList.Option value="b" lead={…} trail="12m">Paginate customer list</RowList.Option>
|
|
8
|
+
</RowList.Group>
|
|
9
|
+
</RowList.Root>
|
|
10
|
+
|
|
11
|
+
Rows you pick from, on ui-sdk Listbox: one tab stop, arrows and typing
|
|
12
|
+
move, Enter or a click selects. Rows in a Group sit 4 apart; groups and
|
|
13
|
+
lone options 12 apart. Half rows go in `sub`: they open with their option.
|
|
14
|
+
*/
|
|
15
|
+
import { Listbox, ListboxGroup, ListboxItem } from "@ui-sdk/solid/listbox";
|
|
16
|
+
import { omit } from "solid-js";
|
|
17
|
+
import type { ComponentProps, JSX } from "@solidjs/web";
|
|
18
|
+
import { cn } from "./cn.ts";
|
|
19
|
+
import { RowBody, rowVariants, type RowParts } from "./row.tsx";
|
|
20
|
+
|
|
21
|
+
export function Root(props: ComponentProps<typeof Listbox>): JSX.Element {
|
|
22
|
+
const rest = omit(props, "class");
|
|
23
|
+
return (
|
|
24
|
+
<Listbox
|
|
25
|
+
{...rest}
|
|
26
|
+
data-slot="row-list"
|
|
27
|
+
class={cn("flex flex-col gap-3 outline-offset-2", props.class as string)}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function Group(props: ComponentProps<typeof ListboxGroup>): JSX.Element {
|
|
33
|
+
const rest = omit(props, "class");
|
|
34
|
+
return <ListboxGroup {...rest} class={cn("flex flex-col gap-1", props.class as string)} />;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type OptionProps = RowParts & { sub?: JSX.Element } & Omit<
|
|
38
|
+
ComponentProps<typeof ListboxItem>,
|
|
39
|
+
"children"
|
|
40
|
+
>;
|
|
41
|
+
|
|
42
|
+
export function Option(props: OptionProps): JSX.Element {
|
|
43
|
+
const rest = omit(props, "kind", "lead", "trail", "detail", "children", "sub", "class");
|
|
44
|
+
return (
|
|
45
|
+
<ListboxItem
|
|
46
|
+
{...rest}
|
|
47
|
+
class={cn("group/row flex cursor-pointer flex-col gap-1 rounded-sm focus-ring", props.class as string)}
|
|
48
|
+
>
|
|
49
|
+
<span
|
|
50
|
+
data-slot="row-box"
|
|
51
|
+
class={cn(
|
|
52
|
+
rowVariants({ kind: props.kind }).root(),
|
|
53
|
+
"group-hover/row:bg-hover group-data-disabled/row:cursor-default",
|
|
54
|
+
)}
|
|
55
|
+
>
|
|
56
|
+
<RowBody {...props} />
|
|
57
|
+
</span>
|
|
58
|
+
{props.sub && (
|
|
59
|
+
<span data-slot="row-sub" class="flex flex-col">
|
|
60
|
+
{props.sub}
|
|
61
|
+
</span>
|
|
62
|
+
)}
|
|
63
|
+
</ListboxItem>
|
|
64
|
+
);
|
|
65
|
+
}
|
package/src/row.tsx
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<Row lead={<StatusIcon status="done" />} trail="12m">Paginate customer list</Row>
|
|
3
|
+
<Row kind="double" selected lead={…} trail="0:12" detail="sonnet 4.5 · invoices-app">Add CSV export</Row>
|
|
4
|
+
<Row kind="half" lead={<Icon path={mark} size={12} />}>haiku 4.5 running tests</Row>
|
|
5
|
+
<Row as="button" onClick={createThread}>New thread</Row>
|
|
6
|
+
<Row render={(attrs) => <a href="/threads/1" {...attrs} />}>Weekly admin</Row>
|
|
7
|
+
|
|
8
|
+
Single rows follow the container's density-* (32 / 40 / 48); double is 48,
|
|
9
|
+
half is 24 and starts at the title edge of the row above. Lead 16, 8 from
|
|
10
|
+
the title; trail one quiet item; detail holds facts, never status words.
|
|
11
|
+
Selected: the surface's selected fill, ink, weight 500.
|
|
12
|
+
tab: inherits navigation chrome, with 12 px start padding and no end padding.
|
|
13
|
+
action/featured: ink labels with 8 px sides; featured uses the hover fill at rest.
|
|
14
|
+
card: an action on a card surface, with an 8 px trail gap and a hover transition.
|
|
15
|
+
*/
|
|
16
|
+
import { merge, omit } from "solid-js";
|
|
17
|
+
import type { JSX } from "@solidjs/web";
|
|
18
|
+
import { cn, tv } from "./cn.ts";
|
|
19
|
+
|
|
20
|
+
const actionSlots = { root: "px-2 text-ink", lead: "text-ink", trail: "text-label" };
|
|
21
|
+
|
|
22
|
+
export const rowVariants = tv({
|
|
23
|
+
slots: {
|
|
24
|
+
root: [
|
|
25
|
+
"group/row flex min-w-0 flex-col justify-center rounded-sm text-start text-row text-ink-2 no-underline",
|
|
26
|
+
"data-selected:bg-selected data-selected:text-ink",
|
|
27
|
+
"group-data-selected/row:bg-selected group-data-selected/row:text-ink group-data-disabled/row:text-ink-3",
|
|
28
|
+
],
|
|
29
|
+
line: "flex min-w-0 items-center gap-2",
|
|
30
|
+
lead: "flex w-4 shrink-0 justify-center text-ink-3 group-data-selected/row:text-ink",
|
|
31
|
+
title: "min-w-0 flex-1 truncate group-data-selected/row:font-medium",
|
|
32
|
+
trail: "flex shrink-0 items-center gap-1 text-data text-ink-3",
|
|
33
|
+
detail: "flex min-w-0 items-center gap-1 truncate text-label text-ink-3",
|
|
34
|
+
},
|
|
35
|
+
variants: {
|
|
36
|
+
kind: {
|
|
37
|
+
single: { root: "h-row" },
|
|
38
|
+
double: { root: "h-12" },
|
|
39
|
+
half: {
|
|
40
|
+
root: "h-6 text-label text-ink-3 group-data-selected/row:bg-transparent group-data-selected/row:text-ink-3",
|
|
41
|
+
line: "ps-6 gap-1",
|
|
42
|
+
lead: "w-3 group-data-selected/row:text-ink-3",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
lead: { true: { detail: "ps-6" } },
|
|
46
|
+
interactive: { true: { root: "cursor-pointer focus-ring" } },
|
|
47
|
+
variant: {
|
|
48
|
+
standard: { root: "px-row" },
|
|
49
|
+
tab: { root: "ps-3 text-inherit" },
|
|
50
|
+
action: actionSlots,
|
|
51
|
+
featured: { ...actionSlots, root: [actionSlots.root, "bg-hover"] },
|
|
52
|
+
card: { root: "px-row transition duration-200", lead: "text-ink", trail: "gap-2 text-label" },
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
compoundVariants: [
|
|
56
|
+
{ interactive: true, variant: ["standard", "action", "card"], class: { root: "hover:bg-hover" } },
|
|
57
|
+
{ interactive: true, variant: "featured", class: { root: "hover:bg-selected" } },
|
|
58
|
+
],
|
|
59
|
+
defaultVariants: { kind: "single", variant: "standard" },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export type RowKind = "single" | "double" | "half";
|
|
63
|
+
type RowVariant = "standard" | "tab" | "action" | "featured" | "card";
|
|
64
|
+
|
|
65
|
+
export type RowParts = {
|
|
66
|
+
kind?: RowKind;
|
|
67
|
+
variant?: RowVariant;
|
|
68
|
+
lead?: JSX.Element;
|
|
69
|
+
trail?: JSX.Element;
|
|
70
|
+
detail?: JSX.Element;
|
|
71
|
+
children: JSX.Element;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export function RowBody(props: RowParts): JSX.Element {
|
|
75
|
+
const slots = () => rowVariants({ kind: props.kind, variant: props.variant, lead: Boolean(props.lead) });
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
<span data-slot="row-line" class={slots().line()}>
|
|
79
|
+
{props.lead && (
|
|
80
|
+
<span data-slot="row-lead" class={slots().lead()}>
|
|
81
|
+
{props.lead}
|
|
82
|
+
</span>
|
|
83
|
+
)}
|
|
84
|
+
<span data-slot="row-title" class={slots().title()}>
|
|
85
|
+
{props.children}
|
|
86
|
+
</span>
|
|
87
|
+
{props.trail && (
|
|
88
|
+
<span data-slot="row-trail" class={slots().trail()}>
|
|
89
|
+
{props.trail}
|
|
90
|
+
</span>
|
|
91
|
+
)}
|
|
92
|
+
</span>
|
|
93
|
+
{props.kind === "double" && props.detail && (
|
|
94
|
+
<span data-slot="row-detail" class={slots().detail()}>
|
|
95
|
+
{props.detail}
|
|
96
|
+
</span>
|
|
97
|
+
)}
|
|
98
|
+
</>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type RowProps = RowParts &
|
|
103
|
+
Omit<JSX.HTMLAttributes<HTMLElement>, "children" | "class"> & {
|
|
104
|
+
class?: string;
|
|
105
|
+
selected?: boolean;
|
|
106
|
+
as?: "button";
|
|
107
|
+
render?: (attrs: Record<string, unknown>) => JSX.Element;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export function Row(props: RowProps): JSX.Element {
|
|
111
|
+
const rest = omit(
|
|
112
|
+
props,
|
|
113
|
+
"kind",
|
|
114
|
+
"variant",
|
|
115
|
+
"lead",
|
|
116
|
+
"trail",
|
|
117
|
+
"detail",
|
|
118
|
+
"children",
|
|
119
|
+
"selected",
|
|
120
|
+
"as",
|
|
121
|
+
"render",
|
|
122
|
+
"class",
|
|
123
|
+
);
|
|
124
|
+
const attrs = merge(rest, {
|
|
125
|
+
"data-slot": "row",
|
|
126
|
+
get "data-selected"() {
|
|
127
|
+
return props.selected ? "" : undefined;
|
|
128
|
+
},
|
|
129
|
+
get class() {
|
|
130
|
+
return cn(
|
|
131
|
+
rowVariants({
|
|
132
|
+
kind: props.kind,
|
|
133
|
+
variant: props.variant,
|
|
134
|
+
interactive: props.as === "button" || Boolean(props.render),
|
|
135
|
+
}).root(),
|
|
136
|
+
props.as === "button" && "w-full",
|
|
137
|
+
props.class,
|
|
138
|
+
);
|
|
139
|
+
},
|
|
140
|
+
get children() {
|
|
141
|
+
return <RowBody {...props} />;
|
|
142
|
+
},
|
|
143
|
+
}) as Record<string, unknown>;
|
|
144
|
+
if (props.render) return props.render(attrs);
|
|
145
|
+
if (props.as === "button") return <button type="button" {...attrs} />;
|
|
146
|
+
return <div {...attrs} />;
|
|
147
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<ScrollArea class="min-h-0 flex-1" label="Review">…</ScrollArea>
|
|
3
|
+
|
|
4
|
+
A panel's one scroll container: it scrolls up and down only, and draws the
|
|
5
|
+
quiet thumb of Paper "Scrollbars · options" (option B) over its edge: a 4 px
|
|
6
|
+
thumb in a 12 px lane, edge at rest, edge-strong while the pointer or focus is
|
|
7
|
+
inside (150 ms in, 300 ms out after 600 ms), ink-3 when the thumb itself is
|
|
8
|
+
hovered or dragged. Keep at least 12 px of padding on the end side so the lane
|
|
9
|
+
covers no content. The browser still scrolls, so the wheel, keys and find in
|
|
10
|
+
page work as usual. Give the root its size; content wraps, never scrolls sideways.
|
|
11
|
+
*/
|
|
12
|
+
import {
|
|
13
|
+
ScrollArea as Root,
|
|
14
|
+
ScrollAreaContent,
|
|
15
|
+
ScrollAreaScrollbar,
|
|
16
|
+
ScrollAreaThumb,
|
|
17
|
+
ScrollAreaViewport,
|
|
18
|
+
} from "@ui-sdk/solid/scroll-area";
|
|
19
|
+
import type { JSX } from "@solidjs/web";
|
|
20
|
+
import { cn } from "./cn.ts";
|
|
21
|
+
|
|
22
|
+
export type ScrollAreaProps = {
|
|
23
|
+
class?: string;
|
|
24
|
+
/** Names the scrolling region for screen readers; also makes it a landmark. */
|
|
25
|
+
label?: string;
|
|
26
|
+
/** The viewport, the element that scrolls. */
|
|
27
|
+
viewportRef?: (element: HTMLDivElement) => void;
|
|
28
|
+
contentRef?: (element: HTMLDivElement) => void;
|
|
29
|
+
children: JSX.Element;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function ScrollArea(props: ScrollAreaProps): JSX.Element {
|
|
33
|
+
return (
|
|
34
|
+
<Root
|
|
35
|
+
type="auto"
|
|
36
|
+
data-slot="scroll-area"
|
|
37
|
+
class={cn("group/scroll relative flex min-h-0 flex-col overflow-hidden", props.class)}
|
|
38
|
+
>
|
|
39
|
+
<ScrollAreaViewport
|
|
40
|
+
ref={props.viewportRef}
|
|
41
|
+
role={props.label ? "region" : undefined}
|
|
42
|
+
aria-label={props.label}
|
|
43
|
+
class="size-full min-h-0 flex-1 focus-ring"
|
|
44
|
+
>
|
|
45
|
+
<ScrollAreaContent ref={props.contentRef} class="flex min-h-full flex-col">
|
|
46
|
+
{props.children}
|
|
47
|
+
</ScrollAreaContent>
|
|
48
|
+
</ScrollAreaViewport>
|
|
49
|
+
<ScrollAreaScrollbar
|
|
50
|
+
orientation="vertical"
|
|
51
|
+
class="flex w-3 touch-none justify-center py-1 opacity-0 select-none data-visible:opacity-100"
|
|
52
|
+
>
|
|
53
|
+
<ScrollAreaThumb
|
|
54
|
+
class={cn(
|
|
55
|
+
"w-1 rounded-full bg-edge transition-colors delay-600 duration-300 ease-out",
|
|
56
|
+
"group-focus-within/scroll:bg-edge-strong group-focus-within/scroll:delay-0 group-focus-within/scroll:duration-150",
|
|
57
|
+
"group-data-hovering/scroll:bg-edge-strong group-data-hovering/scroll:delay-0 group-data-hovering/scroll:duration-150",
|
|
58
|
+
"hover:bg-ink-3 hover:delay-0 data-dragging:bg-ink-3 data-dragging:delay-0 motion-reduce:transition-none",
|
|
59
|
+
)}
|
|
60
|
+
/>
|
|
61
|
+
</ScrollAreaScrollbar>
|
|
62
|
+
</Root>
|
|
63
|
+
);
|
|
64
|
+
}
|
package/src/select.tsx
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<Select.Root defaultValue="normal" items={densities}>
|
|
3
|
+
<Select.Label>Density</Select.Label>
|
|
4
|
+
<Select.Trigger><Select.Value /></Select.Trigger>
|
|
5
|
+
<Select.Content>
|
|
6
|
+
<Select.Item value="normal">Normal</Select.Item>
|
|
7
|
+
</Select.Content>
|
|
8
|
+
</Select.Root>
|
|
9
|
+
|
|
10
|
+
The trigger is an outline key with a chevron; the list is the Menu card,
|
|
11
|
+
and the chosen item carries a check.
|
|
12
|
+
*/
|
|
13
|
+
import * as Base from "@ui-sdk/solid/select";
|
|
14
|
+
import { omit } from "solid-js";
|
|
15
|
+
import type { ComponentProps, JSX } from "@solidjs/web";
|
|
16
|
+
import { buttonVariants } from "./button.tsx";
|
|
17
|
+
import { cn } from "./cn.ts";
|
|
18
|
+
import { Icon } from "./icon.tsx";
|
|
19
|
+
import { icons } from "./icons.ts";
|
|
20
|
+
import { itemClass, popupClass } from "./menu.tsx";
|
|
21
|
+
|
|
22
|
+
type Classed<T extends (props: any) => JSX.Element> = Omit<ComponentProps<T>, "class"> & { class?: string };
|
|
23
|
+
|
|
24
|
+
export const Root = Base.Select;
|
|
25
|
+
|
|
26
|
+
export function Label(props: Classed<typeof Base.SelectLabel>) {
|
|
27
|
+
return (
|
|
28
|
+
<Base.SelectLabel {...omit(props, "class")} class={cn("mb-2 block text-label text-ink-2", props.class)} />
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function Trigger(props: Classed<typeof Base.SelectTrigger>) {
|
|
33
|
+
return (
|
|
34
|
+
<Base.SelectTrigger
|
|
35
|
+
{...omit(props, "class", "children")}
|
|
36
|
+
class={cn(
|
|
37
|
+
buttonVariants({ variant: "outline" }),
|
|
38
|
+
"min-w-menu justify-between pe-2 font-normal",
|
|
39
|
+
props.class,
|
|
40
|
+
)}
|
|
41
|
+
>
|
|
42
|
+
{props.children}
|
|
43
|
+
<Icon path={icons.chevronDown} class="text-ink-3" />
|
|
44
|
+
</Base.SelectTrigger>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function Value(props: Classed<typeof Base.SelectValue>) {
|
|
49
|
+
return (
|
|
50
|
+
<Base.SelectValue {...omit(props, "class")} class={cn("data-placeholder:text-ink-3", props.class)} />
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function Content(props: Classed<typeof Base.SelectContent>) {
|
|
55
|
+
return <Base.SelectContent {...omit(props, "class")} class={cn(popupClass, props.class)} />;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function Item(props: Classed<typeof Base.SelectItem>) {
|
|
59
|
+
return (
|
|
60
|
+
<Base.SelectItem {...omit(props, "class", "children")} class={cn(itemClass, "gap-4", props.class)}>
|
|
61
|
+
{props.children}
|
|
62
|
+
<Base.SelectItemIndicator class="ms-auto">
|
|
63
|
+
<Icon path={icons.check} />
|
|
64
|
+
</Base.SelectItemIndicator>
|
|
65
|
+
</Base.SelectItem>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<StatusIcon status="needs-you" label="Fix total rounding" /> → "Fix total rounding, needs you"
|
|
3
|
+
|
|
4
|
+
One shape per state. Only needs you (amber) and failed (red) are coloured;
|
|
5
|
+
running and done take the row's tone. The word is in the name, not on screen.
|
|
6
|
+
*/
|
|
7
|
+
import type { JSX } from "@solidjs/web";
|
|
8
|
+
import { cn, tv } from "./cn.ts";
|
|
9
|
+
import { Icon } from "./icon.tsx";
|
|
10
|
+
import { icons } from "./icons.ts";
|
|
11
|
+
|
|
12
|
+
export type Status = "running" | "needs-you" | "done" | "failed";
|
|
13
|
+
|
|
14
|
+
const shapes: Record<Status, { path: string; word: string }> = {
|
|
15
|
+
running: { path: icons.running, word: "running" },
|
|
16
|
+
"needs-you": { path: icons.needsYou, word: "needs you" },
|
|
17
|
+
done: { path: icons.done, word: "done" },
|
|
18
|
+
failed: { path: icons.failed, word: "failed" },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const statusVariants = tv({
|
|
22
|
+
base: "inline-flex shrink-0",
|
|
23
|
+
variants: {
|
|
24
|
+
status: {
|
|
25
|
+
running: "motion-safe:*:animate-spin",
|
|
26
|
+
"needs-you": "text-warn",
|
|
27
|
+
done: "",
|
|
28
|
+
failed: "text-removed",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export function StatusIcon(props: {
|
|
34
|
+
status: Status;
|
|
35
|
+
label?: string;
|
|
36
|
+
size?: 12 | 16;
|
|
37
|
+
class?: string;
|
|
38
|
+
}): JSX.Element {
|
|
39
|
+
const shape = () => shapes[props.status];
|
|
40
|
+
return (
|
|
41
|
+
<span data-slot="status-icon" class={cn(statusVariants({ status: props.status }), props.class)}>
|
|
42
|
+
<Icon
|
|
43
|
+
path={shape().path}
|
|
44
|
+
size={props.size}
|
|
45
|
+
label={props.label ? `${props.label}, ${shape().word}` : shape().word}
|
|
46
|
+
/>
|
|
47
|
+
</span>
|
|
48
|
+
);
|
|
49
|
+
}
|
package/src/switch.tsx
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<Switch aria-label="Enabled" checked={enabled()} onCheckedChange={setEnabled} />
|
|
3
|
+
<Switch aria-label="Enabled" defaultChecked />
|
|
4
|
+
|
|
5
|
+
A 28 × 16 pill with a 12 px thumb, 2 px in (Paper "Flow · Profiles", the
|
|
6
|
+
subscription card's "Enabled" toggle). On: an ink track with a stage thumb
|
|
7
|
+
at the end. Off: the translucent edge-strong track, thumb at the start.
|
|
8
|
+
It has no text of its own, so its type asks for a name: aria-label,
|
|
9
|
+
aria-labelledby, or an id that a <label for> points at.
|
|
10
|
+
solid-js also exports a Switch; a file that needs both renames one on import.
|
|
11
|
+
*/
|
|
12
|
+
import { Switch as Base, SwitchThumb } from "@ui-sdk/solid/switch";
|
|
13
|
+
import { omit } from "solid-js";
|
|
14
|
+
import type { ComponentProps, JSX } from "@solidjs/web";
|
|
15
|
+
import { cn } from "./cn.ts";
|
|
16
|
+
|
|
17
|
+
// A nameless switch reads as just "switch, on", so one of the three ways to name it is required,
|
|
18
|
+
// as an icon-only Button requires its label.
|
|
19
|
+
type SwitchName = { "aria-label": string } | { "aria-labelledby": string } | { id: string };
|
|
20
|
+
|
|
21
|
+
export type SwitchProps = Omit<ComponentProps<typeof Base>, "class" | "children"> & {
|
|
22
|
+
class?: string;
|
|
23
|
+
} & SwitchName;
|
|
24
|
+
|
|
25
|
+
type KeyHandler = JSX.EventHandlerUnion<HTMLButtonElement, KeyboardEvent>;
|
|
26
|
+
|
|
27
|
+
function callKeyHandler(handler: KeyHandler | undefined, event: KeyboardEvent) {
|
|
28
|
+
if (typeof handler === "function") (handler as (event: KeyboardEvent) => void)(event);
|
|
29
|
+
else if (Array.isArray(handler))
|
|
30
|
+
(handler[0] as (data: unknown, event: KeyboardEvent) => void)(handler[1], event);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function Switch(props: SwitchProps): JSX.Element {
|
|
34
|
+
const rest = omit(props, "class", "onKeyDown");
|
|
35
|
+
// ui-sdk follows the ARIA switch pattern, where Enter submits the form and only
|
|
36
|
+
// Space toggles. Tokamaq's switches also toggle on Enter, like its buttons. Our
|
|
37
|
+
// handler runs before ui-sdk's and preventDefault skips it, so Enter never also
|
|
38
|
+
// submits; the click goes through ui-sdk's press, which honours readOnly.
|
|
39
|
+
const keyDown = (event: KeyboardEvent & { currentTarget: HTMLButtonElement }) => {
|
|
40
|
+
callKeyHandler(props.onKeyDown as KeyHandler | undefined, event);
|
|
41
|
+
if (event.defaultPrevented || event.key !== "Enter" || event.isComposing) return;
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
if (!event.repeat) event.currentTarget.click();
|
|
44
|
+
};
|
|
45
|
+
return (
|
|
46
|
+
<Base
|
|
47
|
+
{...rest}
|
|
48
|
+
onKeyDown={keyDown}
|
|
49
|
+
class={cn(
|
|
50
|
+
// 28 × 16 with a 2 px inset is off the 4 px scale: a w-6 h-3 content box inside
|
|
51
|
+
// a 2 px transparent border gives it, and the fill shows through the border.
|
|
52
|
+
"relative box-content inline-flex h-3 w-6 shrink-0 cursor-pointer items-center",
|
|
53
|
+
"rounded-full border-2 border-transparent bg-edge-strong transition-colors duration-150 focus-ring",
|
|
54
|
+
"data-checked:bg-ink",
|
|
55
|
+
"data-disabled:cursor-default data-disabled:opacity-50",
|
|
56
|
+
// Rules 09: every click target is 32 × 32 or bigger. The area hangs off the 24 × 12
|
|
57
|
+
// padding box (the border is outside it), so it reaches 4 px out each side and 12 px
|
|
58
|
+
// above and below: 32 × 36, the nearest the spacing steps allow.
|
|
59
|
+
"after:absolute after:-inset-x-1 after:-inset-y-3",
|
|
60
|
+
"motion-reduce:transition-none",
|
|
61
|
+
props.class,
|
|
62
|
+
)}
|
|
63
|
+
>
|
|
64
|
+
<SwitchThumb
|
|
65
|
+
class={cn(
|
|
66
|
+
"block size-3 rounded-full bg-stage transition-transform duration-150",
|
|
67
|
+
// A transform does not follow the writing direction, so the slide is mirrored by hand.
|
|
68
|
+
"data-checked:translate-x-3 rtl:data-checked:-translate-x-3 motion-reduce:transition-none",
|
|
69
|
+
)}
|
|
70
|
+
/>
|
|
71
|
+
</Base>
|
|
72
|
+
);
|
|
73
|
+
}
|
package/src/tabs.tsx
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<Tabs.Root defaultValue="changes">
|
|
3
|
+
<Tabs.List aria-label="Review">
|
|
4
|
+
<Tabs.Tab value="files">Files</Tabs.Tab>
|
|
5
|
+
<Tabs.Tab value="changes">Changes <span class="text-data text-ink-3">4</span></Tabs.Tab>
|
|
6
|
+
</Tabs.List>
|
|
7
|
+
<Tabs.Panel value="files">…</Tabs.Panel>
|
|
8
|
+
</Tabs.Root>
|
|
9
|
+
|
|
10
|
+
Tabs are 32 tall, label weight, secondary at rest; the selected tab takes
|
|
11
|
+
the selected fill and ink. No underline, no colour.
|
|
12
|
+
*/
|
|
13
|
+
import * as Base from "@ui-sdk/solid/tabs";
|
|
14
|
+
import { omit } from "solid-js";
|
|
15
|
+
import type { ComponentProps, JSX } from "@solidjs/web";
|
|
16
|
+
import { cn } from "./cn.ts";
|
|
17
|
+
|
|
18
|
+
type Classed<T extends (props: any) => JSX.Element> = Omit<ComponentProps<T>, "class"> & { class?: string };
|
|
19
|
+
|
|
20
|
+
export function Root(props: Classed<typeof Base.Tabs>) {
|
|
21
|
+
return <Base.Tabs {...omit(props, "class")} class={cn("flex flex-col", props.class)} />;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function List(props: Classed<typeof Base.TabsList>) {
|
|
25
|
+
return <Base.TabsList {...omit(props, "class")} class={cn("flex items-center gap-1", props.class)} />;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function Tab(props: Classed<typeof Base.TabsTab>) {
|
|
29
|
+
return (
|
|
30
|
+
<Base.TabsTab
|
|
31
|
+
{...omit(props, "class")}
|
|
32
|
+
class={cn(
|
|
33
|
+
"inline-flex h-8 cursor-pointer items-center gap-2 rounded-sm px-3 text-label whitespace-nowrap text-ink-2",
|
|
34
|
+
"focus-ring hover:bg-hover data-selected:bg-selected data-selected:text-ink",
|
|
35
|
+
"data-disabled:cursor-default data-disabled:text-ink-3 data-disabled:hover:bg-transparent",
|
|
36
|
+
props.class,
|
|
37
|
+
)}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function Panel(props: Classed<typeof Base.TabsPanel>) {
|
|
43
|
+
return <Base.TabsPanel {...omit(props, "class")} class={cn("rounded-sm focus-ring", props.class)} />;
|
|
44
|
+
}
|