Skip to content

Commit f5789f6

Browse files
committed
feat: add the ability to use the bundled images in custom themes
1 parent 63ba69b commit f5789f6

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

packages/keybr-theme-designer/lib/design/BackgroundImage.tsx

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Box } from "@keybr/widget";
1+
import { images } from "@keybr/themes";
2+
import { Box, Button, Para } from "@keybr/widget";
23
import { useCustomTheme } from "./context.ts";
34
import { Group } from "./Group.tsx";
45
import { ImageInput } from "./input/ImageInput.tsx";
@@ -15,6 +16,33 @@ export function BackgroundImage() {
1516
}}
1617
/>
1718
</Box>
19+
<Para align="center">
20+
<Button
21+
label="Clear"
22+
onClick={() => {
23+
setTheme(theme.delete("--background-image"));
24+
}}
25+
/>
26+
{" or "}
27+
<Button
28+
label="Chocolate"
29+
onClick={() => {
30+
setTheme(theme.set("--background-image", images.chocolate));
31+
}}
32+
/>
33+
<Button
34+
label="Coffee"
35+
onClick={() => {
36+
setTheme(theme.set("--background-image", images.coffee));
37+
}}
38+
/>
39+
<Button
40+
label="Garden"
41+
onClick={() => {
42+
setTheme(theme.set("--background-image", images.garden));
43+
}}
44+
/>
45+
</Para>
1846
</Group>
1947
);
2048
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import chocolateSvg from "../../assets/bg-chocolate.svg";
2+
import coffeeSvg from "../../assets/bg-coffee.svg";
3+
import gardenSvg from "../../assets/bg-garden.svg";
4+
import { UrlAsset } from "./asset.ts";
5+
6+
export const images = {
7+
chocolate: new UrlAsset(chocolateSvg),
8+
coffee: new UrlAsset(coffeeSvg),
9+
garden: new UrlAsset(gardenSvg),
10+
} as const;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { UrlAsset } from "./asset.ts";
2+
3+
export const images = {
4+
chocolate: new UrlAsset(""),
5+
coffee: new UrlAsset(""),
6+
garden: new UrlAsset(""),
7+
} as const;

packages/keybr-themes/lib/themes/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * from "./asset.ts";
22
export * from "./context.ts";
33
export * from "./custom-theme.ts";
44
export * from "./dynamic-styles-context.tsx";
5+
export * from "./images.ts";
56
export * from "./prefs.ts";
67
export * from "./theme-io.ts";
78
export * from "./theme-props.ts";

packages/keybr-themes/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"main": "lib/index.ts",
77
"types": ".types/index.d.ts",
88
"sideEffects": false,
9+
"browser": {
10+
"./lib/themes/images.ts": "./lib/themes/images-browser.ts"
11+
},
912
"dependencies": {
1013
"@keybr/color": "*",
1114
"@keybr/rand": "*",

0 commit comments

Comments
 (0)