Official
ui
The look of the app's components: buttons, list rows, cards, settings, callouts, and the blocks and tables of replies. Edit a component here and the whole app draws with it.
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/ui@0.1.0
Permissions in 0.1.0
Files
components/item.tsx7.3 KB
/** @jsxRuntime classic */
/** @jsx template */
// A row of a list: a leading mark (an icon, an SVG, a spinner while
// `busy`, or a `<slot name="leading">`), a label with an optional second
// line, trailing content (the children), a badge, and buttons that take
// the trailing content's place while the pointer is on the row
// (`actions`), on the same pitch as the icons they replace. The div props an instance is given (an `id`, `onClick`,
// drag and drop, `layoutMotion`) are the row's own.
import { FILL, TONES, prop, when, type Definition, template } from "../define.ts";
const MARK = {
display: "flex",
alignItems: "center",
justifyContent: "center",
position: "relative",
flexGrow: 0,
flexShrink: 0,
width: "density.rowLead",
height: "density.rowLead",
};
// The resting trailing content and the hover actions share one line, each
// a row of no height centred on it and ending at the row's end, so the
// actions sit where the resting icons were, on their pitch, and the label
// keeps the same width whether the pointer is on the row or not.
const LAYER = { display: "flex", flexDirection: "row", alignItems: "center", justifyContent: "flex-end", height: 0, flexShrink: 0 };
const sublabel = <text text={prop("sublabel")} fontSize="type.sublabelSize" lineHeight="type.sublabelLine" truncate color={prop("sublabelTone", { map: TONES, else: "mutedForeground" })} />;
export const item: Definition = {
props: {
label: "",
sublabel: null,
sublabelTone: null,
icon: null,
// SVG markup drawn instead of the named icon (an agent's mark).
iconSvg: null,
iconTone: null,
// A spinner instead of the icon.
busy: false,
// The icon shown while the pointer is on the mark, which is then a
// button of its own calling `onIconClick` (a chat's check-off circle).
hoverIcon: null,
onIconClick: null,
// A row that opens a page (a chat, Settings) takes the pointer cursor;
// every other row keeps the arrow.
opens: false,
selected: false,
// Raised while selected, as the sidebar's open chat is, and on the
// raised look's transparent edge otherwise, so selecting moves nothing.
lift: false,
// A struck-through label, for finished items.
strike: false,
// A group's title row: a larger, bolder label.
strong: false,
// A section title above a list's rows: small bold capitals in `tone`,
// its children (a count) at the end.
heading: false,
tone: null,
// The second line under the mark too, across the whole row.
stacked: false,
badge: null,
// `[{ icon, tooltip?, disabled?, onClick }]`.
actions: [],
},
template: (
<div display="flex" flexDirection="column" justifyContent="center" position="relative" group="item" flexShrink={0} borderRadius="sm" paddingX="density.rowPaddingX" paddingY="density.rowPaddingY" minHeight="density.rowMinHeight" $when={[
when("selected", { background: "accent" }),
when("lift", { elevation: "none" }),
when(["lift", "selected"], { elevation: "raised" }),
when(["!selected", "onClick"], { hover: { background: "hover" } }),
when("opens", { cursor: "pointer" }),
when("heading", { paddingY: 3, minHeight: 0 }),
when(["stacked", "sublabel", "label"], { gap: 2 }),
]}>
<div display="flex" flexDirection="row" alignItems="center" gap="density.rowLeadGap" minWidth={0}>
<div $if="slot.leading" {...MARK}><slot name="leading" /></div>
<div $if={["!slot.leading", "busy|icon|iconSvg"]} {...MARK} $when={[
when(["hoverIcon", "onIconClick"], {
group: "item-mark",
borderRadius: "full",
hover: { background: "hover" },
onClick: prop("onIconClick"),
stopPropagation: true,
}),
]}>
<div display="flex" groupHover={{ group: "item-mark", visibility: "hidden" }}>
<spinner $if="busy" />
<icon $if={["!busy", "icon|iconSvg"]} name={prop("icon", { else: "" })} svg={prop("iconSvg")} small tone={prop("iconTone", { else: "muted" })} $when={[when(["selected", "!iconTone"], { tone: "foreground" })]} />
</div>
<div $if={["hoverIcon", "onIconClick"]} position="absolute" top={0} right={0} bottom={0} left={0} display="flex" alignItems="center" justifyContent="center" visibility="hidden" groupHover={{ group: "item-mark", visibility: "visible" }}><icon name={prop("hoverIcon")} small tone="foreground" /></div>
</div>
<div $if={["label", "heading"]} {...FILL}>
<text text={prop("label")} textTransform="uppercase" fontSize="type.sublabelSize + 0.44" fontWeight={700} lineHeight="type.sublabelLine" color={prop("tone", { map: TONES, else: "mutedForeground" })} truncate />
</div>
<div $if={["label", "!heading"]} display="flex" flexDirection="column" {...FILL}>
<text text={prop("label")} fontSize="type.labelSize" fontWeight={500} lineHeight="type.labelLine" color="mutedForeground" truncate $when={[
when("strong|selected", { color: "foreground" }),
when("strong", { fontSize: "type.strongSize", fontWeight: 600, lineHeight: "type.strongSize + 4" }),
when("strike", { textDecoration: "lineThrough" }),
]} />
<div $if={["sublabel", "!stacked"]} marginTop={2}>{sublabel}</div>
</div>
<div $if={["children", "!actions"]} display="flex" flexDirection="row" alignItems="center" gap={6} $when={[
when("label", { flexGrow: 0, flexShrink: 0, height: "type.labelLine" }),
when(["label", "strong"], { height: "type.strongSize + 4" }),
when("!label", FILL),
]}><slot /></div>
<div $if={["label", "actions"]} display="flex" flexDirection="column" alignItems="flex-end" justifyContent="center" flexGrow={0} flexShrink={0} height="type.labelLine">
<div $if="children" {...LAYER} gap={6} groupHover={{ group: "item", visibility: "hidden" }}><slot /></div>
<div {...LAYER} marginRight={-3} visibility="hidden" groupHover={{ group: "item", visibility: "visible" }}>
<div $each="actions" role="button" id={prop("item.id")} label={prop("item.tooltip")} tooltip={prop("item.tooltip")} isDisabled={prop("item.disabled", { else: false })} stopPropagation={true} display="flex" alignItems="center" justifyContent="center" flexShrink={0} width={20} height={20} borderRadius="sm" color="foreground" onClick={prop("item.onClick")} $when={[
when("!item.disabled", { hover: { background: "hover" }, active: { background: "accent" } }),
when("item.disabled", { color: "mutedForeground/50" }),
]}><icon name={prop("item.icon")} small /></div>
</div>
</div>
<div $if="badge" flexGrow={0} flexShrink={0} fontSize="type.sublabelSize + 0.44" color="mutedForeground"><text text={prop("badge")} /></div>
</div>
<div $if={["stacked", "sublabel", "label"]} minWidth={0} $when={[when("slot.leading|busy|icon|iconSvg", { paddingLeft: "density.rowLead + density.rowLeadGap" })]}>{sublabel}</div>
</div>
),
};
No comments yet.