Skip to content

Commit 2b23452

Browse files
committed
feat: add the global adjustments tab to the theme designer
1 parent 203f386 commit 2b23452

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { BackgroundImage } from "./BackgroundImage.tsx";
1515
import { ChartDesign } from "./ChartDesign.tsx";
1616
import { useCustomTheme } from "./context.ts";
1717
import * as styles from "./DesignPane.module.less";
18+
import { GlobalAdjustments } from "./GlobalAdjustments.tsx";
1819
import { InterfaceDesign } from "./InterfaceDesign.tsx";
1920
import { KeyboardDesign } from "./KeyboardDesign.tsx";
2021
import { LessonKeysDesign } from "./LessonKeysDesign.tsx";
@@ -113,6 +114,7 @@ export function DesignPane() {
113114
<ProfileDesign />
114115
<KeyboardDesign />
115116
<SyntaxDesign />
117+
<GlobalAdjustments />
116118
</div>
117119
<FieldList>
118120
<Field>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Field, FieldList, Icon, IconButton } from "@keybr/widget";
2+
import { mdiMinusCircleOutline, mdiPlusCircleOutline } from "@mdi/js";
3+
import { adjustColors } from "./adjust-colors.ts";
4+
import { useCustomTheme } from "./context.ts";
5+
import { Group } from "./Group.tsx";
6+
import { PreviewPane } from "./PreviewPane.tsx";
7+
import { WidgetsPreview } from "./WidgetsPreview.tsx";
8+
9+
export function GlobalAdjustments() {
10+
const { theme, setTheme } = useCustomTheme();
11+
return (
12+
<Group title="Global Adjustments">
13+
<FieldList>
14+
<Field.Filler />
15+
<Field>
16+
<IconButton
17+
icon={<Icon shape={mdiMinusCircleOutline} />}
18+
onClick={() => {
19+
setTheme(adjustColors(theme, "saturation", -0.05));
20+
}}
21+
/>
22+
</Field>
23+
<Field>Saturation</Field>
24+
<Field>
25+
<IconButton
26+
icon={<Icon shape={mdiPlusCircleOutline} />}
27+
onClick={() => {
28+
setTheme(adjustColors(theme, "saturation", +0.05));
29+
}}
30+
/>
31+
</Field>
32+
<Field.Filler />
33+
</FieldList>
34+
<FieldList>
35+
<Field.Filler />
36+
<Field>
37+
<IconButton
38+
icon={<Icon shape={mdiMinusCircleOutline} />}
39+
onClick={() => {
40+
setTheme(adjustColors(theme, "brightness", -0.05));
41+
}}
42+
/>
43+
</Field>
44+
<Field>Brightness</Field>
45+
<Field>
46+
<IconButton
47+
icon={<Icon shape={mdiPlusCircleOutline} />}
48+
onClick={() => {
49+
setTheme(adjustColors(theme, "brightness", +0.05));
50+
}}
51+
/>
52+
</Field>
53+
<Field.Filler />
54+
</FieldList>
55+
<PreviewPane>
56+
<WidgetsPreview />
57+
</PreviewPane>
58+
</Group>
59+
);
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Color } from "@keybr/color";
2+
import { type CustomTheme } from "@keybr/themes";
3+
4+
export function adjustColors(
5+
theme: CustomTheme,
6+
property: "saturation" | "brightness",
7+
delta: number,
8+
) {
9+
for (let [prop, value] of theme) {
10+
if (value instanceof Color) {
11+
switch (property) {
12+
case "saturation":
13+
value = value.saturate(delta);
14+
break;
15+
case "brightness":
16+
value = value.lighten(delta);
17+
break;
18+
}
19+
theme = theme.set(prop, value);
20+
}
21+
}
22+
return theme;
23+
}

0 commit comments

Comments
 (0)