Skip to content

Commit af6ec83

Browse files
authored
refactor(tui): add shared DialogHeader (anomalyco#55501)
1 parent 4f31eb9 commit af6ec83

21 files changed

Lines changed: 131 additions & 229 deletions

‎packages/tui/src/component/dialog-debug.tsx‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { TextAttributes } from "@opentui/core"
21
import { createMemo, createSignal, For } from "solid-js"
32
import { Keymap } from "../context/keymap"
43
import { useTheme } from "../context/theme"
5-
import { useDialog } from "../ui/dialog"
4+
import { DialogHeader, useDialog } from "../ui/dialog"
65
import { useRoute } from "../context/route"
76
import { useLocal } from "../context/local"
87
import { useClipboard } from "../context/clipboard"
@@ -54,14 +53,7 @@ export function DialogDebug() {
5453

5554
return (
5655
<box paddingLeft={2} paddingRight={2} gap={1} paddingBottom={1}>
57-
<box flexDirection="row" justifyContent="space-between">
58-
<text fg={theme.text.base} attributes={TextAttributes.BOLD}>
59-
Debug
60-
</text>
61-
<text fg={theme.text.muted} onMouseUp={() => dialog.clear()}>
62-
esc
63-
</text>
64-
</box>
56+
<DialogHeader title="Debug" />
6557
{/* No click-to-copy here: releasing a mouse selection must trigger the
6658
global copy-on-select so users can copy a single value, e.g. the session id. */}
6759
<box>

‎packages/tui/src/component/dialog-error-details.tsx‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useRoute } from "../context/route"
99
import { getScrollAcceleration } from "../util/scroll"
1010
import { useTheme } from "../context/theme"
1111
import { emptyPrompt } from "../prompt/history"
12-
import { dialogWidth, useDialog } from "../ui/dialog"
12+
import { DialogHeader, dialogWidth, useDialog } from "../ui/dialog"
1313
import { FilePath } from "../ui/file-path"
1414
import { useToast } from "../ui/toast"
1515
import { errorDetails } from "../util/error-details"
@@ -73,21 +73,22 @@ export function DialogErrorDetails(props: {
7373
return (
7474
<box paddingLeft={2} paddingRight={2} paddingBottom={1} gap={1}>
7575
<box>
76-
<box flexDirection="row" gap={2}>
77-
<text
78-
attributes={TextAttributes.BOLD}
79-
fg={theme.text.base}
80-
flexGrow={1}
81-
minWidth={0}
82-
wrapMode="none"
83-
truncate
84-
>
85-
{props.title}
86-
</text>
87-
<text fg={theme.text.muted} flexShrink={0} onMouseUp={props.onBack}>
88-
esc
89-
</text>
90-
</box>
76+
<DialogHeader
77+
gap={2}
78+
onClose={props.onBack}
79+
titleView={
80+
<text
81+
attributes={TextAttributes.BOLD}
82+
fg={theme.text.base}
83+
flexGrow={1}
84+
minWidth={0}
85+
wrapMode="none"
86+
truncate
87+
>
88+
{props.title}
89+
</text>
90+
}
91+
/>
9192
<Show when={props.source}>
9293
{(source) => (
9394
<FilePath

‎packages/tui/src/component/dialog-highlights.tsx‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useConfig } from "../config"
55
import { Keymap } from "../context/keymap"
66
import type { TuiHighlight } from "../context/runtime"
77
import { useTheme } from "../context/theme"
8-
import { useDialog } from "../ui/dialog"
8+
import { DialogHeader, useDialog } from "../ui/dialog"
99
import { getScrollAcceleration } from "../util/scroll"
1010

1111
export function DialogHighlights(props: { version: string; items: ReadonlyArray<TuiHighlight> }) {
@@ -34,14 +34,7 @@ export function DialogHighlights(props: { version: string; items: ReadonlyArray<
3434

3535
return (
3636
<box gap={1} paddingBottom={1}>
37-
<box flexDirection="row" justifyContent="space-between" paddingLeft={2} paddingRight={2}>
38-
<text attributes={TextAttributes.BOLD} fg={theme.text.base}>
39-
What's new in {props.version}
40-
</text>
41-
<text fg={theme.text.muted} onMouseUp={() => dialog.clear()}>
42-
esc
43-
</text>
44-
</box>
37+
<DialogHeader paddingX={2} title={`What's new in ${props.version}`} />
4538
{/* The band owns the vertical padding so it stays visible while the highlights scroll. */}
4639
<box backgroundColor={overlay.background.raised.high} paddingTop={1} paddingBottom={1}>
4740
<scrollbox

‎packages/tui/src/component/dialog-image-preview.tsx‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { TextAttributes } from "@opentui/core"
21
import { useTerminalDimensions } from "@opentui/solid"
32
import { createMemo, createSignal } from "solid-js"
43
import { Keymap } from "../context/keymap"
54
import { useTheme } from "../context/theme"
6-
import { useDialog } from "../ui/dialog"
5+
import { DialogHeader, useDialog } from "../ui/dialog"
76

87
type ImagePreviewItem = Readonly<{
98
uri: string
@@ -38,14 +37,7 @@ export function DialogImagePreview(props: { images: readonly ImagePreviewItem[];
3837

3938
return (
4039
<box id="prompt-image-viewer" paddingLeft={2} paddingRight={2} paddingBottom={1} gap={1}>
41-
<box flexDirection="row" justifyContent="space-between">
42-
<text attributes={TextAttributes.BOLD} fg={theme.text.base}>
43-
Image {index() + 1} of {props.images.length}
44-
</text>
45-
<text fg={theme.text.muted} onMouseUp={() => dialog.clear()}>
46-
esc
47-
</text>
48-
</box>
40+
<DialogHeader title={`Image ${index() + 1} of ${props.images.length}`} />
4941
<image
5042
id="prompt-image-viewer-image"
5143
source={current().uri}

‎packages/tui/src/component/dialog-integration.tsx‎

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ScrollBoxRenderable, TextareaRenderable, TextAttributes } from "@opentui/core"
1+
import { ScrollBoxRenderable, TextareaRenderable } from "@opentui/core"
22
import { useTerminalDimensions } from "@opentui/solid"
33
import type {
44
ConnectionInfo,
@@ -21,7 +21,7 @@ import { useClient } from "../context/client"
2121
import { Keymap } from "../context/keymap"
2222
import { useLocation } from "../context/location"
2323
import { useTheme } from "../context/theme"
24-
import { useDialog } from "../ui/dialog"
24+
import { DialogHeader, useDialog } from "../ui/dialog"
2525
import { DialogPrompt } from "../ui/dialog-prompt"
2626
import { DialogSelect } from "../ui/dialog-select"
2727
import { Link } from "../ui/link"
@@ -510,14 +510,7 @@ function CommandView(props: { title: string; output: string; message: string })
510510
onMount(() => dialog.setSize("large"))
511511
return (
512512
<box gap={1} paddingBottom={1}>
513-
<box flexDirection="row" justifyContent="space-between" paddingLeft={2} paddingRight={2}>
514-
<text attributes={TextAttributes.BOLD} fg={theme.text.base}>
515-
{props.title}
516-
</text>
517-
<text fg={theme.text.muted} onMouseUp={() => dialog.clear()}>
518-
esc close
519-
</text>
520-
</box>
513+
<DialogHeader paddingX={2} title={props.title} closeLabel="esc close" />
521514
<box
522515
backgroundColor={overlayTheme.background.raised.high}
523516
paddingLeft={2}
@@ -801,18 +794,10 @@ function OAuthView(props: {
801794
copy?: boolean
802795
open?: boolean
803796
}) {
804-
const dialog = useDialog()
805797
const theme = useTheme().surface("dialog")
806798
return (
807799
<box paddingLeft={2} paddingRight={2} gap={1} paddingBottom={1}>
808-
<box flexDirection="row" justifyContent="space-between">
809-
<text attributes={TextAttributes.BOLD} fg={theme.text.base}>
810-
{props.title}
811-
</text>
812-
<text fg={theme.text.muted} onMouseUp={() => dialog.clear()}>
813-
esc
814-
</text>
815-
</box>
800+
<DialogHeader title={props.title} />
816801
<Show when={props.url}>
817802
{(url) => (
818803
<box gap={1}>
@@ -986,14 +971,7 @@ function StringChoiceField(props: {
986971
}))
987972
return (
988973
<box paddingLeft={4} paddingRight={4} paddingBottom={1} gap={1}>
989-
<box flexDirection="row" justifyContent="space-between">
990-
<text fg={theme.text.base} attributes={TextAttributes.BOLD}>
991-
{formLabel(props.field)}
992-
</text>
993-
<text fg={theme.text.muted} onMouseUp={() => (store.editing ? back() : dialog.clear())}>
994-
esc
995-
</text>
996-
</box>
974+
<DialogHeader title={formLabel(props.field)} onClose={() => (store.editing ? back() : dialog.clear())} />
997975
<Show when={props.field.description}>{(description) => <text fg={theme.text.muted}>{description()}</text>}</Show>
998976
<scrollbox
999977
gap={1}

‎packages/tui/src/component/dialog-pair.tsx‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createMemo, createResource, createSignal, For, Show } from "solid-js"
44
import { renderUnicodeCompact } from "uqr"
55
import { useClient } from "../context/client"
66
import { useTheme } from "../context/theme"
7-
import { useDialog } from "../ui/dialog"
7+
import { DialogHeader, useDialog } from "../ui/dialog"
88
import { Link } from "../ui/link"
99
import { errorMessage } from "../util/error"
1010

@@ -88,14 +88,7 @@ export function DialogPair() {
8888

8989
return (
9090
<box paddingLeft={2} paddingRight={2} paddingBottom={1} gap={1}>
91-
<box flexDirection="row" justifyContent="space-between">
92-
<text fg={theme.text.base} attributes={TextAttributes.BOLD}>
93-
Pair
94-
</text>
95-
<text fg={theme.text.muted} onMouseUp={() => dialog.clear()}>
96-
esc
97-
</text>
98-
</box>
91+
<DialogHeader title="Pair" />
9992
<Show
10093
when={loadError()}
10194
fallback={

‎packages/tui/src/component/dialog-shell-output.tsx‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import stripAnsi from "strip-ansi"
66
import { useClient } from "../context/client"
77
import { Keymap } from "../context/keymap"
88
import { useTheme } from "../context/theme"
9-
import { useDialog } from "../ui/dialog"
9+
import { DialogHeader, useDialog } from "../ui/dialog"
1010

1111
const PAGE_BYTES = 64 * 1024
1212

@@ -101,15 +101,16 @@ export function DialogShellOutput(props: { shell: ShellInfo; location: LocationR
101101

102102
return (
103103
<box paddingLeft={2} paddingRight={2} paddingBottom={1} gap={1}>
104-
<box flexDirection="row" gap={2}>
105-
<text fg={theme.text.base} attributes={TextAttributes.BOLD} flexGrow={1}>
106-
Shell output
107-
</text>
104+
<DialogHeader
105+
gap={2}
106+
titleView={
107+
<text fg={theme.text.base} attributes={TextAttributes.BOLD} flexGrow={1}>
108+
Shell output
109+
</text>
110+
}
111+
>
108112
<text fg={theme.text.muted}>{status()}</text>
109-
<text fg={theme.text.muted} onMouseUp={() => dialog.clear()}>
110-
esc
111-
</text>
112-
</box>
113+
</DialogHeader>
113114
<text fg={theme.text.muted} maxHeight={3} wrapMode="word">
114115
{props.shell.command}
115116
</text>

‎packages/tui/src/component/dialog-status.tsx‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { TextAttributes } from "@opentui/core"
21
import { useTheme } from "../context/theme"
3-
import { useDialog } from "../ui/dialog"
2+
import { DialogHeader } from "../ui/dialog"
43
import { useData } from "../context/data"
54
import { For, Match, Switch, Show, createMemo } from "solid-js"
65

76
export function DialogStatus() {
87
const data = useData()
98
const theme = useTheme().surface("dialog")
10-
const dialog = useDialog()
119

1210
const mcp = createMemo(() => data.location.mcp.server.list() ?? [])
1311
const color = (status: string) => {
@@ -18,14 +16,7 @@ export function DialogStatus() {
1816
}
1917
return (
2018
<box paddingLeft={2} paddingRight={2} gap={1} paddingBottom={1}>
21-
<box flexDirection="row" justifyContent="space-between">
22-
<text fg={theme.text.base} attributes={TextAttributes.BOLD}>
23-
Status
24-
</text>
25-
<text fg={theme.text.muted} onMouseUp={() => dialog.clear()}>
26-
esc
27-
</text>
28-
</box>
19+
<DialogHeader title="Status" />
2920
<Show when={mcp().length > 0} fallback={<text fg={theme.text.base}>No MCP servers</text>}>
3021
<box>
3122
<text fg={theme.text.base}>

‎packages/tui/src/component/dialog-update.tsx‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { TextAttributes } from "@opentui/core"
21
import { createEffect, createMemo, createResource, createSignal, For, Match, onCleanup, Show, Switch } from "solid-js"
32
import { Keymap } from "../context/keymap"
43
import { useTheme } from "../context/theme"
54
import type { UpdateState } from "../context/update-notification"
6-
import { useDialog } from "../ui/dialog"
5+
import { DialogHeader, useDialog } from "../ui/dialog"
76
import { errorMessage } from "../util/error"
87
import { Spinner } from "./spinner"
98

@@ -87,18 +86,15 @@ export function DialogUpdate(props: {
8786

8887
return (
8988
<box paddingLeft={2} paddingRight={2} gap={1}>
90-
<box flexDirection="row" justifyContent="space-between">
91-
<text attributes={TextAttributes.BOLD} fg={theme.text.base}>
92-
{state().type === "installing"
89+
<DialogHeader
90+
title={
91+
state().type === "installing"
9392
? "Updating OpenCode"
9493
: state().type === "available" || state().type === "failed"
9594
? "Update available"
96-
: "Update"}
97-
</text>
98-
<text fg={theme.text.muted} onMouseUp={() => dialog.clear()}>
99-
esc
100-
</text>
101-
</box>
95+
: "Update"
96+
}
97+
/>
10298
<box paddingBottom={1}>
10399
<Show when={state()} keyed>
104100
{(current) => (

‎packages/tui/src/component/dialog-workspace-file-changes.tsx‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { TextAttributes } from "@opentui/core"
21
import { useKeyboard, useTerminalDimensions } from "@opentui/solid"
32
import type { VcsFileStatus } from "@opencode/client"
43
import { createMemo, For } from "solid-js"
54
import { createStore } from "solid-js/store"
65
import { FilePath } from "../ui/file-path"
76
import { useTheme } from "../context/theme"
87
import { useConfig } from "../config"
9-
import { useDialog, type DialogContext } from "../ui/dialog"
8+
import { DialogHeader, useDialog, type DialogContext } from "../ui/dialog"
109
import { getScrollAcceleration } from "../util/scroll"
1110

1211
const options = ["no", "yes"] as const
@@ -71,14 +70,7 @@ export function DialogWorkspaceFileChanges(props: {
7170

7271
return (
7372
<box gap={1}>
74-
<box flexDirection="row" justifyContent="space-between" paddingLeft={2} paddingRight={2}>
75-
<text attributes={TextAttributes.BOLD} fg={theme.text.base}>
76-
{props.title ?? "File Changes Found"}
77-
</text>
78-
<text fg={theme.text.muted} onMouseUp={() => dialog.clear()}>
79-
esc
80-
</text>
81-
</box>
73+
<DialogHeader paddingX={2} title={props.title ?? "File Changes Found"} />
8274
<box paddingLeft={2} paddingRight={2}>
8375
<text fg={theme.text.muted} wrapMode="word">
8476
{props.message ?? "Do you want to move these changes with the session?"}

0 commit comments

Comments
 (0)