Skip to content

Commit 11d0cf6

Browse files
committed
Set mini browser colors
1 parent f0bb3a7 commit 11d0cf6

File tree

4 files changed

+70
-7
lines changed

4 files changed

+70
-7
lines changed

packages/mini-browser/src/buttons.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,20 @@ function Refresh() {
4949
)
5050
}
5151

52-
function Open({ href }: { href: string }) {
52+
function Open({
53+
href,
54+
style,
55+
}: {
56+
href: string
57+
style?: React.CSSProperties
58+
}) {
5359
const c = useClasser("ch-browser")
5460
return (
5561
<a
5662
className={c("button", "open-button")}
5763
title="Open in new tab"
5864
href={href}
65+
style={style}
5966
target="_blank"
6067
rel="noopener noreferrer"
6168
>

packages/mini-browser/src/title-bar.tsx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import React from "react"
22
import { Back, Forward, Open } from "./buttons"
33
import { FrameButtons } from "@code-hike/mini-frame"
4-
import { EditorTheme } from "@code-hike/utils"
4+
import {
5+
EditorTheme,
6+
getColor,
7+
ColorName,
8+
} from "@code-hike/utils"
59

610
export { TitleBar }
711

@@ -14,14 +18,36 @@ function TitleBar({
1418
linkUrl: string
1519
theme: EditorTheme
1620
}) {
21+
const inputBorder = getColor(theme, ColorName.InputBorder)
1722
return (
1823
<>
1924
<FrameButtons />
2025
<Back />
2126
<Forward />
2227
{/* <Refresh /> */}
23-
<input value={url || ""} readOnly />
24-
<Open href={linkUrl} />
28+
<input
29+
value={url || ""}
30+
readOnly
31+
style={{
32+
background: getColor(
33+
theme,
34+
ColorName.InputBackground
35+
),
36+
color: getColor(theme, ColorName.InputForeground),
37+
border: inputBorder
38+
? `1px solid ${inputBorder}`
39+
: undefined,
40+
}}
41+
/>
42+
<Open
43+
href={linkUrl}
44+
style={{
45+
color: getColor(
46+
theme,
47+
ColorName.EditorForeground
48+
),
49+
}}
50+
/>
2551
</>
2652
)
2753
}

packages/playground/content/test.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# Hello
22

3-
<CH.Preview show="/" style={{ height: 200 }} />
3+
<CH.Preview
4+
show="/"
5+
style={{ height: 200 }}
6+
url="https://google.com"
7+
/>

packages/utils/src/theme.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ export enum ColorName {
3939
TabBorder,
4040
ActiveTabBottomBorder,
4141
LineNumberForeground,
42+
InputForeground,
43+
InputBackground,
44+
InputBorder,
4245
}
4346

4447
type Color = string | undefined
4548

4649
const contrastBorder = "#6FC3DF"
4750

4851
// defaults from: https://github.com/microsoft/vscode/blob/main/src/vs/workbench/common/theme.ts
49-
// and: https://github.com/microsoft/vscode/blob/main/src/vs/editor/common/view/editorColorRegistry.ts
52+
// and: https://github.com/microsoft/vscode/blob/main/src/vs/editor/common/core/editorColorRegistry.ts
53+
// and: https://github.com/microsoft/vscode/blob/main/src/vs/platform/theme/common/colorRegistry.ts
5054
// keys from : https://code.visualstudio.com/api/references/theme-color#editor-groups-tabs
5155
export function getColor(
5256
theme: EditorTheme,
@@ -161,7 +165,29 @@ export function getColor(
161165
hc: "#fffffe",
162166
})
163167
)
164-
168+
case ColorName.InputBackground:
169+
return (
170+
colors["input.background"] ||
171+
getDefault(theme, {
172+
dark: "#3C3C3C",
173+
light: "#fffffe",
174+
hc: "#000000",
175+
})
176+
)
177+
case ColorName.InputForeground:
178+
return (
179+
colors["input.foreground"] ||
180+
getColor(theme, ColorName.EditorForeground)
181+
)
182+
case ColorName.InputBorder:
183+
return (
184+
colors["input.border"] ||
185+
getDefault(theme, {
186+
dark: undefined,
187+
light: undefined,
188+
hc: contrastBorder,
189+
})
190+
)
165191
default:
166192
return "#f00"
167193
}

0 commit comments

Comments
 (0)