Skip to content

Commit 3079589

Browse files
committed
Remove resolveColor logic from remaining components
- Remove resolveFg/resolveThemeColor from SuggestionMenu, MultilineInput, RaisedPill - Components use theme properties directly (e.g., fg={theme.inputFg}) - All color resolution happens during theme building, not in components - Cleaner, more maintainable component code
1 parent ae76878 commit 3079589

File tree

3 files changed

+19
-58
lines changed

3 files changed

+19
-58
lines changed

cli/src/components/multiline-input.tsx

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -574,34 +574,24 @@ export const MultilineInput = forwardRef<
574574
maxHeight,
575575
])
576576

577-
const resolveFg = (
578-
color?: string | null,
579-
fallback?: string | null,
580-
): string | undefined => {
581-
if (color && color !== 'default') return color
582-
if (fallback && fallback !== 'default') return fallback
583-
return undefined
577+
const inputColor = isPlaceholder
578+
? theme.inputPlaceholder
579+
: focused
580+
? theme.inputFocusedFg
581+
: theme.inputFg
582+
583+
const textStyle: Record<string, unknown> = {
584+
bg: 'transparent',
585+
fg: inputColor,
584586
}
585587

586-
const resolvedInputColor = resolveFg(
587-
isPlaceholder
588-
? theme.inputPlaceholder
589-
: focused
590-
? theme.inputFocusedFg ?? theme.inputFg
591-
: theme.inputFg,
592-
)
593-
594-
const textStyle: Record<string, unknown> = { bg: 'transparent' }
595-
if (resolvedInputColor) {
596-
textStyle.fg = resolvedInputColor
597-
}
598588
if (isPlaceholder) {
599589
textStyle.attributes = TextAttributes.DIM
600590
} else if (textAttributes !== undefined && textAttributes !== 0) {
601591
textStyle.attributes = textAttributes
602592
}
603593

604-
const cursorFg = resolveFg(theme.cursor, theme.statusAccent)
594+
const cursorFg = theme.cursor
605595

606596
return (
607597
<scrollbox

cli/src/components/raised-pill.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,9 @@ export const RaisedPill = ({
3131
onPress,
3232
style,
3333
}: RaisedPillProps): React.ReactNode => {
34-
const resolveFg = (color?: string): string | undefined =>
35-
color && color !== 'default' ? color : undefined
36-
37-
const resolvedFrameColor = resolveFg(frameColor)
38-
const resolvedTextColor = resolveFg(textColor)
39-
4034
const leftRightPadding =
4135
padding > 0
42-
? [{ text: ' '.repeat(padding), fg: resolvedTextColor }]
36+
? [{ text: ' '.repeat(padding), fg: textColor }]
4337
: []
4438

4539
const normalizedSegments: Array<{
@@ -50,7 +44,7 @@ export const RaisedPill = ({
5044
...leftRightPadding,
5145
...segments.map((segment) => ({
5246
text: segment.text,
53-
fg: resolveFg(segment.fg ?? textColor),
47+
fg: segment.fg ?? textColor,
5448
attr: segment.attr,
5549
})),
5650
...leftRightPadding,
@@ -71,32 +65,28 @@ export const RaisedPill = ({
7165
onMouseDown={onPress}
7266
>
7367
<text>
74-
<span
75-
{...(resolvedFrameColor ? { fg: resolvedFrameColor } : undefined)}
76-
>{`╭${horizontal}╮`}</span>
68+
<span fg={frameColor}>{`╭${horizontal}╮`}</span>
7769
</text>
7870
<text>
79-
<span {...(resolvedFrameColor ? { fg: resolvedFrameColor } : undefined)}>
71+
<span fg={frameColor}>
8072
8173
</span>
8274
{normalizedSegments.map((segment, idx) => (
8375
<span
8476
key={idx}
85-
{...(segment.fg ? { fg: segment.fg } : undefined)}
77+
fg={segment.fg}
8678
bg={fillColor ?? 'transparent'}
8779
attributes={segment.attr}
8880
>
8981
{segment.text}
9082
</span>
9183
))}
92-
<span {...(resolvedFrameColor ? { fg: resolvedFrameColor } : undefined)}>
84+
<span fg={frameColor}>
9385
9486
</span>
9587
</text>
9688
<text>
97-
<span
98-
{...(resolvedFrameColor ? { fg: resolvedFrameColor } : undefined)}
99-
>{`╰${horizontal}╯`}</span>
89+
<span fg={frameColor}>{`╰${horizontal}╯`}</span>
10090
</text>
10191
</box>
10292
)

cli/src/components/suggestion-menu.tsx

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ export const SuggestionMenu = ({
2222
prefix = '/',
2323
}: SuggestionMenuProps) => {
2424
const theme = useTheme()
25-
const resolveFg = (
26-
color?: string | null,
27-
fallback?: string | null,
28-
): string | undefined => {
29-
if (color && color !== 'default') return color
30-
if (fallback && fallback !== 'default') return fallback
31-
return undefined
32-
}
33-
const fallbackTextColor =
34-
resolveFg(theme.agentContentText) ?? resolveFg(theme.chromeText) ?? '#d1d5e5'
35-
const fallbackDescriptionColor =
36-
resolveFg(theme.timestampUser) ?? fallbackTextColor
3725

3826
if (items.length === 0) {
3927
return null
@@ -88,11 +76,6 @@ export const SuggestionMenu = ({
8876
const descriptionColor = isSelected
8977
? theme.statusAccent
9078
: theme.timestampUser
91-
const textFg = resolveFg(textColor, fallbackTextColor)
92-
const descriptionFg = resolveFg(
93-
descriptionColor,
94-
fallbackDescriptionColor,
95-
)
9679
return (
9780
<box
9881
key={item.id}
@@ -109,17 +92,15 @@ export const SuggestionMenu = ({
10992
>
11093
<text
11194
style={{
112-
...(textFg ? { fg: textFg } : undefined),
95+
fg: textColor,
11396
marginBottom: 0,
11497
wrapMode: 'none',
11598
}}
11699
>
117100
<span fg={theme.agentPrefix}>{effectivePrefix}</span>
118101
<span>{item.label}</span>
119102
<span>{padding}</span>
120-
<span
121-
{...(descriptionFg ? { fg: descriptionFg } : undefined)}
122-
>
103+
<span fg={descriptionColor}>
123104
{item.description}
124105
</span>
125106
</text>

0 commit comments

Comments
 (0)