Skip to content

Commit 251b043

Browse files
committed
feat(theme): add custom color support with ColorPicker
1 parent feb9592 commit 251b043

File tree

12 files changed

+102
-47
lines changed

12 files changed

+102
-47
lines changed

frontend/src/assets/styles/theme.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
--input-color: ~'var(--input-color-@{theme})';
7676
--input-bg: ~'var(--input-bg-@{theme})';
7777

78+
// ColorPicker
79+
--color-picker-bg: ~'var(--color-picker-bg-@{theme})';
80+
7881
// Divider
7982
--divider-color: ~'var(--divider-color-@{theme})';
8083

frontend/src/assets/styles/utilities/size.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@size-values: 0, 8, 10, 12, 16, 18, 24, 30, 32, 42, 64, 128, 256;
1+
@size-values: 0, 8, 10, 12, 16, 18, 24, 26, 30, 32, 42, 64, 128, 256;
22
@percent-values: 25, 36, 50, 60, 75, 90, 100;
33

44
.generate-size(@i: 1) when (@i <= length(@size-values)) {

frontend/src/assets/styles/variables.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@
126126
--input-color-dark: #fff;
127127
--input-bg-dark: rgba(255, 255, 255, 0.06);
128128

129+
// ColorPicker
130+
--color-picker-bg-light: #fff;
131+
--color-picker-bg-dark: rgba(255, 255, 255, 0.06);
132+
129133
// Divider
130134
--divider-color-light: #c6c6c6;
131135
--divider-color-dark: #4d4d4d;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<script lang="ts" setup>
2+
import { useTemplateRef } from 'vue'
3+
4+
const model = defineModel<string>({ default: '#000' })
5+
6+
const emit = defineEmits(['change'])
7+
8+
const inputRef = useTemplateRef('inputRef')
9+
10+
const onChange = (v: Event) => {
11+
const val = (v.target as HTMLInputElement).value
12+
emit('change', val)
13+
}
14+
15+
const pick = () => {
16+
inputRef.value?.click()
17+
}
18+
</script>
19+
20+
<template>
21+
<div
22+
:class="{ 'pr-8': $slots.suffix }"
23+
class="gui-color-picker rounded-full inline-flex items-center overflow-hidden"
24+
>
25+
<div v-if="$slots.prefix" class="flex items-center line-clamp-1 break-all">
26+
<slot name="prefix" v-bind="{ pick }"></slot>
27+
</div>
28+
<input
29+
ref="inputRef"
30+
v-model="model"
31+
@change="(e) => onChange(e)"
32+
type="color"
33+
class="w-26 border-0 bg-transparent cursor-pointer"
34+
/>
35+
<div v-if="$slots.suffix" class="flex items-center line-clamp-1 break-all">
36+
<slot name="suffix" v-bind="{ pick }"></slot>
37+
</div>
38+
</div>
39+
</template>
40+
41+
<style lang="less" scoped>
42+
.gui-color-picker {
43+
color: var(--color);
44+
border: 1px solid var(--primary-color);
45+
background: var(--color-picker-bg);
46+
}
47+
48+
input::-webkit-color-swatch {
49+
border-radius: 6px;
50+
border: none;
51+
}
52+
</style>

frontend/src/components/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ declare module 'vue' {
66
Card: (typeof import('./Card/index.vue'))['default']
77
CheckBox: (typeof import('./CheckBox/index.vue'))['default']
88
CodeViewer: (typeof import('./CodeViewer/index.vue'))['default']
9+
ColorPicker: (typeof import('./ColorPicker/index.vue'))['default']
910
Confirm: (typeof import('./Confirm/index.vue'))['default']
1011
CustomAction: (typeof import('./CustomAction/index.vue'))['default']
1112
Divider: (typeof import('./Divider/index.vue'))['default']

frontend/src/constant/app.ts

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,6 @@ export const Colors = {
3636
primary: 'rgb(0, 89, 214)',
3737
secondary: 'rgb(5, 62, 142)',
3838
},
39-
[Color.Orange]: {
40-
primary: 'orange',
41-
secondary: '#ab7207',
42-
},
43-
[Color.Pink]: {
44-
primary: 'pink',
45-
secondary: '#f1768b',
46-
},
47-
[Color.Red]: {
48-
primary: 'red',
49-
secondary: '#9e0404',
50-
},
51-
[Color.Skyblue]: {
52-
primary: 'skyblue',
53-
secondary: '#0ca4e2',
54-
},
5539
[Color.Green]: {
5640
primary: 'green',
5741
secondary: '#025f02',
@@ -60,6 +44,10 @@ export const Colors = {
6044
primary: 'purple',
6145
secondary: '#6a0f9c',
6246
},
47+
[Color.Custom]: {
48+
primary: '#000',
49+
secondary: '#000',
50+
},
6351
}
6452

6553
export const ViewOptions = [
@@ -101,22 +89,6 @@ export const ColorOptions = [
10189
label: 'settings.color.default',
10290
value: Color.Default,
10391
},
104-
{
105-
label: 'settings.color.orange',
106-
value: Color.Orange,
107-
},
108-
{
109-
label: 'settings.color.pink',
110-
value: Color.Pink,
111-
},
112-
{
113-
label: 'settings.color.red',
114-
value: Color.Red,
115-
},
116-
{
117-
label: 'settings.color.skyblue',
118-
value: Color.Skyblue,
119-
},
12092
{
12193
label: 'settings.color.green',
12294
value: Color.Green,
@@ -125,6 +97,10 @@ export const ColorOptions = [
12597
label: 'settings.color.purple',
12698
value: Color.Purple,
12799
},
100+
{
101+
label: 'settings.color.custom',
102+
value: Color.Custom,
103+
},
128104
]
129105

130106
export const WindowStateOptions = [

frontend/src/enums/app.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ export enum ControllerCloseMode {
3232

3333
export enum Color {
3434
Default = 'default',
35-
Orange = 'orange',
36-
Pink = 'pink',
37-
Red = 'red',
38-
Skyblue = 'skyblue',
3935
Green = 'green',
4036
Purple = 'purple',
37+
Custom = 'custom',
4138
}
4239

4340
export enum Branch {

frontend/src/lang/locale/en.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,11 @@ export default {
570570
color: {
571571
name: 'Color',
572572
default: 'Default',
573-
orange: 'Orange',
574-
pink: 'Pink',
575-
red: 'Red',
576-
skyblue: 'Skyblue',
577573
green: 'Green',
578574
purple: 'Purple',
575+
custom: 'Custom',
576+
primary: 'Primary',
577+
secondary: 'Secondary',
579578
},
580579
fontFamily: 'Font-Family',
581580
resetFont: 'Reset Font-Family',

frontend/src/lang/locale/zh.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,11 @@ export default {
569569
color: {
570570
name: '颜色',
571571
default: '默认',
572-
orange: '橘色',
573-
pink: '粉色',
574-
red: '红色',
575-
skyblue: '天蓝色',
576572
green: '绿色',
577573
purple: '紫色',
574+
custom: '自定义',
575+
primary: '主颜色',
576+
secondary: '次颜色',
578577
},
579578
fontFamily: '字体',
580579
resetFont: '重置字体',

frontend/src/stores/appSettings.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export const useAppSettingsStore = defineStore('app-settings', () => {
4747
lang: Lang.EN,
4848
theme: Theme.Auto,
4949
color: Color.Default,
50+
primaryColor: '#000',
51+
secondaryColor: '#545454',
5052
fontFamily: DefaultFontFamily,
5153
profilesView: View.Grid,
5254
subscribesView: View.Grid,
@@ -176,7 +178,12 @@ export const useAppSettingsStore = defineStore('app-settings', () => {
176178
? Theme.Dark
177179
: Theme.Light
178180
: settings.theme
179-
const { primary, secondary } = Colors[settings.color]
181+
let primary, secondary
182+
if (settings.color === Color.Custom) {
183+
;({ primaryColor: primary, secondaryColor: secondary } = settings)
184+
} else {
185+
;({ primary, secondary } = Colors[settings.color] ?? { primary: '', secondary: '' })
186+
}
180187
document.documentElement.style.setProperty('--primary-color', primary)
181188
document.documentElement.style.setProperty('--secondary-color', secondary)
182189
document.body.style.fontFamily = settings.fontFamily

0 commit comments

Comments
 (0)