mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 05:01:03 +03:00
feat(tui): add dialog footer theme override and retire faint in new designs (#60003)
This commit is contained in:
committed by
GitHub
Unverified
parent
66f1fa816d
commit
726cf09639
@@ -1,5 +1,6 @@
|
||||
import type {
|
||||
BackgroundDefinition,
|
||||
DialogTokensDefinition,
|
||||
ModeDefinition,
|
||||
StatefulColorDefinition,
|
||||
TextDefinition,
|
||||
@@ -11,7 +12,14 @@ export function expandTheme<Definition extends ModeDefinition>(definition: Defin
|
||||
return {
|
||||
...definition,
|
||||
...expandTokens(definition),
|
||||
...(definition["@dialog"] ? { "@dialog": expandTokens(definition["@dialog"]) } : {}),
|
||||
...(definition["@dialog"] ? { "@dialog": expandDialog(definition["@dialog"]) } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
function expandDialog(definition: DialogTokensDefinition): DialogTokensDefinition {
|
||||
return {
|
||||
...expandTokens(definition),
|
||||
...(definition["@footer"] ? { "@footer": expandTokens(definition["@footer"]) } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ export {
|
||||
ThemeDefinition,
|
||||
ThemeDocument,
|
||||
type BackgroundDefinition,
|
||||
type DialogTokensDefinition,
|
||||
type DiffDefinition,
|
||||
type FormfieldColorDefinition,
|
||||
type HueDefinition,
|
||||
|
||||
@@ -76,11 +76,16 @@ function resolveExpandedTheme(definition: ThemeDefinition): ResolvedTheme {
|
||||
...resolveView(tokens, hue, categorical, hueSteps),
|
||||
surface: (name) => views[name],
|
||||
})
|
||||
views.dialog = definition["@dialog"] ? view(contextualize(base, definition["@dialog"])) : view(base)
|
||||
const dialog = definition["@dialog"]
|
||||
const dialogTokens = dialog ? contextualize(base, tokens(dialog)) : base
|
||||
views.dialog = view(dialogTokens)
|
||||
// The footer override layers on the dialog surface, so footers keep every dialog token they don't override.
|
||||
const footer = dialog?.["@footer"]
|
||||
views["dialog.footer"] = footer ? view(contextualize(dialogTokens, footer)) : views.dialog
|
||||
return view(base)
|
||||
}
|
||||
|
||||
function tokens(definition: ThemeDefinition): ThemeTokensDefinition {
|
||||
function tokens(definition: ThemeTokensDefinition): ThemeTokensDefinition {
|
||||
return {
|
||||
text: definition.text,
|
||||
background: definition.background,
|
||||
|
||||
@@ -11,7 +11,7 @@ export const ActionState = Schema.Literals(["disabled", "pressed", "focused", "s
|
||||
export type ActionState = Schema.Schema.Type<typeof ActionState>
|
||||
export type ActionStateKey = `$${ActionState}`
|
||||
|
||||
export const SurfaceName = Schema.Literal("dialog")
|
||||
export const SurfaceName = Schema.Literals(["dialog", "dialog.footer"])
|
||||
export type SurfaceName = Schema.Schema.Type<typeof SurfaceName>
|
||||
|
||||
export const FormfieldState = ActionState
|
||||
@@ -201,6 +201,12 @@ const ThemeTokensDefinition = Schema.Struct({
|
||||
})
|
||||
export type ThemeTokensDefinition = Schema.Schema.Type<typeof ThemeTokensDefinition>
|
||||
|
||||
const DialogTokensDefinition = Schema.Struct({
|
||||
...ThemeTokensDefinition.fields,
|
||||
"@footer": Schema.optional(ThemeTokensDefinition),
|
||||
})
|
||||
export type DialogTokensDefinition = Schema.Schema.Type<typeof DialogTokensDefinition>
|
||||
|
||||
const CompleteStatefulColorDefinition = Schema.Struct({
|
||||
base: ColorValue,
|
||||
$hovered: Schema.optional(ColorValue),
|
||||
@@ -264,7 +270,7 @@ const ThemeDefinitionFields = Schema.Struct({
|
||||
hue: HueDefinition,
|
||||
categorical: CategoricalDefinition,
|
||||
...CompleteThemeTokensDefinition.fields,
|
||||
"@dialog": Schema.optional(ThemeTokensDefinition),
|
||||
"@dialog": Schema.optional(DialogTokensDefinition),
|
||||
})
|
||||
export const ThemeDefinition = ThemeDefinitionFields
|
||||
export type ThemeDefinition = Schema.Schema.Type<typeof ThemeDefinition>
|
||||
@@ -272,7 +278,7 @@ export type ThemeDefinition = Schema.Schema.Type<typeof ThemeDefinition>
|
||||
export const BaseThemeDefinition = Schema.Struct({
|
||||
categorical: CategoricalDefinition,
|
||||
...CompleteThemeTokensDefinition.fields,
|
||||
"@dialog": Schema.optional(ThemeTokensDefinition),
|
||||
"@dialog": Schema.optional(DialogTokensDefinition),
|
||||
})
|
||||
export type BaseThemeDefinition = Schema.Schema.Type<typeof BaseThemeDefinition>
|
||||
|
||||
@@ -280,7 +286,7 @@ export const ModeDefinition = Schema.Struct({
|
||||
hue: HueDefinition,
|
||||
categorical: Schema.optional(CategoricalDefinition),
|
||||
...ThemeTokensDefinition.fields,
|
||||
"@dialog": Schema.optional(ThemeTokensDefinition),
|
||||
"@dialog": Schema.optional(DialogTokensDefinition),
|
||||
})
|
||||
export type ModeDefinition = Schema.Schema.Type<typeof ModeDefinition>
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ export function ModelDetail(props: {
|
||||
...(props.model.variants.length > 0 ? ["Reasoning"] : []),
|
||||
].filter(Boolean)
|
||||
const list = (items: string[]) => (
|
||||
<text fg={theme.text.faint} wrapMode="none" flexShrink={0}>
|
||||
<text fg={theme.text.muted} wrapMode="none" flexShrink={0}>
|
||||
<For each={items}>
|
||||
{(fact, index) => (
|
||||
<>
|
||||
@@ -85,7 +85,7 @@ export function ModelDetail(props: {
|
||||
fallback={
|
||||
<box flexDirection="row" justifyContent={props.price === false ? "flex-start" : "space-between"} gap={2}>
|
||||
<Show when={props.price !== false}>
|
||||
<text fg={theme.text.faint} wrapMode="none">
|
||||
<text fg={theme.text.muted} wrapMode="none">
|
||||
{price()}
|
||||
</text>
|
||||
</Show>
|
||||
|
||||
@@ -10,12 +10,11 @@
|
||||
],
|
||||
"text": {
|
||||
"base": "$hue.neutral.100",
|
||||
"muted": "$hue.neutral.200",
|
||||
"faint": "$hue.neutral.300",
|
||||
"muted": "$hue.neutral.300",
|
||||
"action": {
|
||||
"primary": {
|
||||
"base": "$text.base",
|
||||
"$disabled": "$text.faint",
|
||||
"$disabled": "$text.muted",
|
||||
"$focused": "$text.base",
|
||||
"$selected": "$hue.interactive.400"
|
||||
},
|
||||
@@ -26,7 +25,7 @@
|
||||
},
|
||||
"destructive": {
|
||||
"base": "$hue.neutral.900",
|
||||
"$disabled": "$text.faint"
|
||||
"$disabled": "$text.muted"
|
||||
}
|
||||
},
|
||||
"formfield": {
|
||||
@@ -34,7 +33,7 @@
|
||||
"$hovered": "$hue.interactive.400",
|
||||
"$focused": "$hue.interactive.400",
|
||||
"$pressed": "$hue.interactive.400",
|
||||
"$disabled": "$text.faint",
|
||||
"$disabled": "$text.muted",
|
||||
"$selected": "$hue.interactive.400"
|
||||
},
|
||||
"feedback": {
|
||||
@@ -159,6 +158,11 @@
|
||||
"$hovered": "$background.raised.max"
|
||||
}
|
||||
}
|
||||
},
|
||||
"@footer": {
|
||||
"text": {
|
||||
"muted": "$hue.neutral.200"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useTheme } from "../context/theme"
|
||||
import { DialogFooter, DialogHeader, DialogLayout, useDialog, type DialogSize } from "./dialog"
|
||||
import { Show, createEffect, createSignal, onMount, type JSX } from "solid-js"
|
||||
import { Spinner } from "../component/spinner"
|
||||
import { useConfig, useNewDesigns } from "../config"
|
||||
import { useConfig } from "../config"
|
||||
import { useRenderer } from "@opentui/solid"
|
||||
|
||||
export type DialogPromptAction = {
|
||||
@@ -19,7 +19,7 @@ export type DialogPromptAction = {
|
||||
export type DialogPromptProps = {
|
||||
title: string
|
||||
size?: DialogSize
|
||||
/** Faint line below the title, under the "new-designs" experiment. */
|
||||
/** Muted line below the title, under the "new-designs" experiment. */
|
||||
subtitle?: string
|
||||
description?: () => JSX.Element
|
||||
placeholder?: string
|
||||
@@ -36,7 +36,6 @@ export function DialogPrompt(props: DialogPromptProps) {
|
||||
const renderer = useRenderer()
|
||||
const theme = useTheme().surface("dialog")
|
||||
const config = useConfig().data
|
||||
const newDesigns = useNewDesigns()
|
||||
const [textareaTarget, setTextareaTarget] = createSignal<TextareaRenderable>()
|
||||
let textarea: TextareaRenderable
|
||||
|
||||
@@ -169,7 +168,7 @@ export function DialogPrompt(props: DialogPromptProps) {
|
||||
}}
|
||||
initialValue={props.value}
|
||||
placeholder={props.placeholder ?? "Enter text"}
|
||||
placeholderColor={newDesigns() ? theme.text.faint : theme.text.muted}
|
||||
placeholderColor={theme.text.muted}
|
||||
textColor={props.busy ? theme.text.formfield.disabled : theme.text.formfield.base}
|
||||
focusedTextColor={props.busy ? theme.text.formfield.disabled : theme.text.formfield.base}
|
||||
cursorColor={props.busy ? theme.background.formfield.disabled : theme.text.base}
|
||||
|
||||
@@ -26,7 +26,7 @@ import { moveSelection, reconcileSelection } from "./select-controller"
|
||||
export interface DialogSelectProps<T> {
|
||||
title: string
|
||||
titleView?: JSX.Element
|
||||
/** Faint line below the title, under the "new-designs" experiment. Not shown with `searchInTitle`. */
|
||||
/** Muted line below the title, under the "new-designs" experiment. Not shown with `searchInTitle`. */
|
||||
description?: string
|
||||
/** Blank rows above the footer under the "new-designs" experiment. Defaults to 1. */
|
||||
footerGap?: number
|
||||
@@ -677,7 +677,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
|
||||
}, 1)
|
||||
}}
|
||||
placeholder={(searchInTitle() ? props.titlePlaceholder : undefined) ?? props.placeholder ?? "Search"}
|
||||
placeholderColor={newDesigns() ? theme.text.faint : theme.text.muted}
|
||||
placeholderColor={theme.text.muted}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -829,7 +829,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
|
||||
</scrollbox>
|
||||
<Show when={ellipsis()}>
|
||||
<box paddingLeft={DIALOG_LIST_INSET} flexShrink={0}>
|
||||
<text fg={theme.text.faint}>…</text>
|
||||
<text fg={theme.text.muted}>…</text>
|
||||
</box>
|
||||
</Show>
|
||||
{/* Reserved whenever any option has a detail, so the dialog does not resize as the selection moves. */}
|
||||
@@ -839,7 +839,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
|
||||
when={detailView()}
|
||||
keyed
|
||||
fallback={
|
||||
<text fg={theme.text.muted} wrapMode="word">
|
||||
<text fg={theme.surface("dialog.footer").text.muted} wrapMode="word">
|
||||
{detailText() || " "}
|
||||
</text>
|
||||
}
|
||||
@@ -865,7 +865,7 @@ export function DialogSelectChoice(props: { value: string; active: boolean; open
|
||||
if (!props.active) return ` ${props.value} `
|
||||
return props.open ? ` ${props.value} ↵` : `‹ ${props.value} ›`
|
||||
}
|
||||
return <span style={{ fg: props.active ? theme.text.action.primary.focused : theme.text.faint }}>{text()}</span>
|
||||
return <span style={{ fg: props.active ? theme.text.action.primary.focused : theme.text.muted }}>{text()}</span>
|
||||
}
|
||||
|
||||
function DialogSelectCategory(props: { title: string; first: boolean }) {
|
||||
@@ -873,7 +873,7 @@ function DialogSelectCategory(props: { title: string; first: boolean }) {
|
||||
const newDesigns = useNewDesigns()
|
||||
return (
|
||||
<box paddingTop={props.first ? 0 : 1} paddingLeft={DIALOG_LIST_INSET - (newDesigns() ? 0 : 1)}>
|
||||
<text fg={newDesigns() ? theme.text.faint : theme.hue.accent[200]} attributes={TextAttributes.BOLD}>
|
||||
<text fg={newDesigns() ? theme.text.muted : theme.hue.accent[200]} attributes={TextAttributes.BOLD}>
|
||||
{props.title}
|
||||
</text>
|
||||
</box>
|
||||
@@ -906,7 +906,7 @@ function DialogSelectRow(props: {
|
||||
// Secondary text (description and footer).
|
||||
const secondary = () => {
|
||||
if (!newDesigns()) return props.active ? text() : theme.text.muted
|
||||
return props.active ? theme.text.action.secondary.focused : theme.text.faint
|
||||
return props.active ? theme.text.action.secondary.focused : theme.text.muted
|
||||
}
|
||||
|
||||
const row = () => (
|
||||
|
||||
@@ -96,7 +96,7 @@ export function DialogHeader(
|
||||
closeLabel?: string
|
||||
onClose?: () => void
|
||||
gap?: number
|
||||
/** Faint line below the title. Shown only under the "new-designs" experiment. */
|
||||
/** Muted line below the title. Shown only under the "new-designs" experiment. */
|
||||
description?: string
|
||||
}>,
|
||||
) {
|
||||
@@ -112,7 +112,7 @@ export function DialogHeader(
|
||||
)}
|
||||
{props.children}
|
||||
<text
|
||||
fg={newDesigns() ? theme.text.faint : theme.text.muted}
|
||||
fg={theme.text.muted}
|
||||
flexShrink={0}
|
||||
onMouseUp={() => (props.onClose ?? dialog.clear)()}
|
||||
>
|
||||
@@ -124,7 +124,7 @@ export function DialogHeader(
|
||||
<Show when={newDesigns() && props.description} fallback={row()}>
|
||||
<box>
|
||||
{row()}
|
||||
<text fg={theme.text.faint} wrapMode="word">
|
||||
<text fg={theme.text.muted} wrapMode="word">
|
||||
{props.description}
|
||||
</text>
|
||||
</box>
|
||||
@@ -297,7 +297,7 @@ function DialogFooterItem(props: { action: DialogFooterAction; variant: "primary
|
||||
onMouseOut={() => setHovered(false)}
|
||||
onMouseUp={trigger}
|
||||
>
|
||||
<text>{label(theme.text.faint)}</text>
|
||||
<text>{label(theme.text.muted)}</text>
|
||||
</box>
|
||||
</Show>
|
||||
)
|
||||
|
||||
@@ -337,6 +337,23 @@ test("surface overrides rewire references and reset action states from their bas
|
||||
expect(raised.text.action.primary.focused.toInts()).toEqual([85, 85, 85, 255])
|
||||
})
|
||||
|
||||
test("dialog footer overrides layer on the dialog surface", () => {
|
||||
const theme = resolveTheme(
|
||||
override(light, {
|
||||
"@dialog": {
|
||||
text: { base: "#333333" },
|
||||
"@footer": { text: { muted: "#666666" } },
|
||||
},
|
||||
}),
|
||||
)
|
||||
const footer = theme.surface("dialog.footer")
|
||||
expect(footer.text.muted.toInts()).toEqual([102, 102, 102, 255])
|
||||
expect(footer.text.base.toInts()).toEqual([51, 51, 51, 255])
|
||||
expect(theme.surface("dialog").text.muted.toInts()).not.toEqual([102, 102, 102, 255])
|
||||
const plain = resolveTheme(light)
|
||||
expect(plain.surface("dialog.footer")).toBe(plain.surface("dialog"))
|
||||
})
|
||||
|
||||
test("rejects missing and circular references", () => {
|
||||
expect(() => resolveTheme(override(light, { text: { base: "$missing" } }))).toThrow(
|
||||
'Theme reference "$missing" was not found',
|
||||
|
||||
Reference in New Issue
Block a user