Skip to content

Commit 003153f

Browse files
committed
feat(theme): allow auto generating theme color
1 parent f86da75 commit 003153f

File tree

32 files changed

+258
-193
lines changed

32 files changed

+258
-193
lines changed

demo/components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@vuepress/bundler-vite": "2.0.0-rc.15",
1818
"@vuepress/bundler-webpack": "2.0.0-rc.15",
1919
"@vuepress/helper": "2.0.0-rc.47",
20-
"@vuepress/theme-default": "2.0.0-rc.47",
20+
"@vuepress/theme-default": "2.0.0-rc.49",
2121
"artplayer": "5.1.7",
2222
"artplayer-plugin-danmuku": "5.1.4",
2323
"dashjs": "4.7.4",

demo/lightgallery/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"devDependencies": {
1717
"@vuepress/bundler-vite": "2.0.0-rc.15",
1818
"@vuepress/bundler-webpack": "2.0.0-rc.15",
19-
"@vuepress/theme-default": "2.0.0-rc.47",
19+
"@vuepress/theme-default": "2.0.0-rc.49",
2020
"sass-embedded": "1.79.3",
2121
"sass-loader": "16.0.2",
2222
"vue": "3.5.8",

demo/md-enhance/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@vue/repl": "4.4.2",
1919
"@vuepress/bundler-vite": "2.0.0-rc.15",
2020
"@vuepress/bundler-webpack": "2.0.0-rc.15",
21-
"@vuepress/theme-default": "2.0.0-rc.47",
21+
"@vuepress/theme-default": "2.0.0-rc.49",
2222
"chart.js": "4.4.4",
2323
"echarts": "5.5.1",
2424
"echarts-wordcloud": "2.1.0",

demo/md-enhance/src/.vuepress/styles/index.scss

Lines changed: 0 additions & 5 deletions
This file was deleted.

demo/search-pro/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"devDependencies": {
1717
"@vuepress/bundler-vite": "2.0.0-rc.15",
1818
"@vuepress/bundler-webpack": "2.0.0-rc.15",
19-
"@vuepress/theme-default": "2.0.0-rc.47",
19+
"@vuepress/theme-default": "2.0.0-rc.49",
2020
"nodejs-jieba": "0.1.2",
2121
"sass-embedded": "1.79.3",
2222
"sass-loader": "16.0.2",

docs/theme/src/config/style.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ Responsive breakpoints:
2929

3030
Theme Colors:
3131

32+
- `$theme-color`: primary theme color
3233
- `$theme-colors`: theme colors you want to use besides primary theme color
3334

3435
Code block (Only available with shiki):
3536

3637
- `$code-bg-color`: background color for code blocks
3738
- `$code-color`: font color for code blocks
3839

39-
Color list: `$colors`
40+
Color list:
41+
42+
- `$colors`: Used to generate color list.
4043

4144
::: details Demo
4245

@@ -61,7 +64,7 @@ $pc: 1920px;
6164

6265
All variables here (including your newly added variables) will be converted to kebab-case format and injected as CSS variables.
6366

64-
For example `$theme-color` will be injected as `--theme-color`, and `$backgroundColor` will be injected as `--background-color`.
67+
For example `$vp-c-text` will be injected as `--vp-c-text`, and `$vp-c-bg` will be injected as `--vp-c-bg`.
6568

6669
:::
6770

@@ -74,6 +77,9 @@ Available color variables:
7477
#### Text
7578

7679
- `$vp-c-text`: Default text color.
80+
81+
By default, the theme automatically generates the following colors based on the `$vp-c-text`, but you can still customize them:
82+
7783
- `$vp-c-text-mute`: Colors for muted texts, such as "inactive menu" or "info texts".
7884
- `$vp-c-text-subtle`: Color for subtle text, such as as "placeholders" or "caret icon".
7985

@@ -91,6 +97,8 @@ Available color variables:
9197

9298
Accent color and brand colors which used for interactive components.
9399

100+
By default, the theme automatically generates the following accent colors based on the `$theme-color` in config file, but you can still customize them:
101+
94102
- `$vp-c-accent`: The most solid color used mainly for colored text. It must satisfy the contrast ratio against when used on top of `$vp-c-accent-soft`.
95103
- `$vp-c-accent-hover`: Color used for hover state.
96104
- `$vp-c-accent-bg`: Color used for solid background. It must satisfy the contrast ratio with `$vp-c-accent-text` on top of it.
@@ -102,9 +110,12 @@ Accent color and brand colors which used for interactive components.
102110
#### Borders
103111

104112
- `$vp-c-border`: Border color for interactive components. For example this should be used for a button outline.
105-
- `$vp-c-border-hard`: Darker border colors, which is used for "hard" borders closed to text, such as table and kbd.
106113
- `$vp-c-divider`: Color for separators, used to divide sections within the same components, such as having separator on "h2" heading.
107114

115+
By default, the theme automatically generates the following colors based on the `$vp-c-border`, but you can still customize them:
116+
117+
- `$vp-c-border-hard`: Darker border colors, which is used for "hard" borders closed to text, such as table and kbd.
118+
108119
#### Controls
109120

110121
- `$vp-c-control`: Background color for interactive controls, such as buttons or checkboxes.

docs/theme/src/guide/customize/color.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Customize color
2+
title: Customize colors
33
icon: palette
44
order: 1
55
category:
@@ -9,29 +9,29 @@ tag:
99
- Customize
1010
---
1111

12-
This page guides you how to customize theme colors.
12+
This page guides you how to customize colors in theme.
1313

1414
<!-- more -->
1515

1616
## Modify the built-in color
1717

18-
The theme controls the color through the palette, you may need to set your color in two situations:
18+
The theme controls the color through config file and palette file. These files are `.vuepress/styles/{config|palette}.scss` files under the VuePress project folder.
1919

20-
1. This color remains the same in day mode and night mode, like theme color.
21-
2. This color is different in day mode, night mode, such as background color, font, border color, etc.
20+
You may need to set colors under two situations:
2221

23-
The palette file is the `.vuepress/styles/palette.scss` file under the VuePress project folder.
22+
1. This color remains the same in day mode and night mode, e.g.: theme color.
23+
1. This color is different in lightmode and darkmode, such as background color, font color, border color, etc.
2424

25-
For the former, you need to write variable values in `palette.scss`, e.g.:
25+
For the former, you need to write variable values directly, e.g.:
2626

27-
```scss title=".vuepress/styles/palette.scss"
27+
```scss title=".vuepress/styles/config.scss"
2828
$theme-color: #3eaf7c;
2929
```
3030

31-
For the latter, you need to set up a Map with key names `light` and `dark`, and values as color values, e.g.:
31+
For the latter, you need to set a color map with `light` and `dark` keys and color values, e.g.:
3232

3333
```scss title=".vuepress/styles/palette.scss"
34-
$bg-color: (
34+
$vp-c-bg: (
3535
light: #fff,
3636
dark: #000,
3737
);
@@ -41,27 +41,29 @@ See [Theme Configuration → Color Settings](../../config/style.md#color-config)
4141

4242
## Modify other colors
4343

44-
Sometimes, you may want to modify some colors that are not in `palette.scss`, such as the background color of the code block. At this time, you can check whether the corresponding color attribute value is a CSS variable through the devTools. If so, you can go to `index.scss` to manually override this variable value:
44+
Sometimes, you may want to modify some colors that are not in `palette.scss`, such as the background color of the code block. At this time, you can check whether the corresponding color attribute value is a CSS variable through the devTools.
45+
46+
If so, you can go to `index.scss` to manually override this variable value:
4547

4648
```scss title=".vuepress/styles/index.scss"
47-
// override code demo header color
49+
// override code block background color
4850
#app {
49-
--code-demo-c-bg-header: #fff;
51+
--code-c-bg: #fff;
5052

51-
html[data-theme="dark"] & {
52-
--code-demo-c-bg-header: #000;
53+
[data-theme="dark"] & {
54+
--code-c-bg: #000;
5355
}
5456
}
5557
```
5658

5759
If not, write your own selectors to override them:
5860

5961
```scss title=".vuepress/styles/index.scss"
60-
// override code block language font color
61-
pre[class*="language-"]::before {
62+
// override code block background color
63+
pre[class*="language-"] {
6264
color: #fff !important;
6365

64-
html[data-theme="dark"] & {
66+
[data-theme="dark"] & {
6567
background-color: #222 !important;
6668
}
6769
}

docs/theme/src/guide/interface/theme-color.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The theme allows you to customize theme color and even provide a picker.
1515

1616
## Setting Default Theme Color
1717

18-
You should set the default theme color of your site in `.vuepress/styles/palette.scss` through `$theme-color`:
18+
You should set the default theme color of your site in `.vuepress/styles/config.scss` through `$theme-color`:
1919

2020
```scss
2121
$theme-color: #f00;

docs/theme/src/zh/config/style.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ tag:
2929

3030
主题色:
3131

32+
- `$theme-color`: 主要主题色
3233
- `$theme-colors`: 除了主要主题色之外,你想使用的其他主题颜色
3334

34-
代码块 (仅限 shiki):
35+
代码块 (仅限 shiki 高亮器):
3536

3637
- `$code-bg-color`: 代码块的背景颜色
3738
- `$code-color`: 代码块的字体颜色
3839

39-
颜色列表: `$colors`
40+
颜色列表:
41+
42+
- `$colors`: 用于生成颜色列表。
4043

4144
::: details 例子
4245

@@ -61,7 +64,7 @@ $pc: 1920px;
6164

6265
此处的所有变量 (包括你新添加的变量) 都会被转换为 kebab-case 的格式注入为 CSS 变量。
6366

64-
`$theme-color` 会被注入为 `--theme-color``$backgroundColor` 会被注入为 `--background-color`
67+
`$vp-c-text` 会被注入为 `--vp-c-text``$vp-c-bg` 会被注入为 `--vp-c-bg`
6568

6669
:::
6770

@@ -74,6 +77,9 @@ $pc: 1920px;
7477
#### 文字
7578

7679
- `$vp-c-text`:默认文本颜色。
80+
81+
默认情况下,主题会根据 `$vp-c-text` 自动生成以下颜色,但你仍然可以自定义它们:
82+
7783
- `$vp-c-text-mute`:用于静音文本的颜色,例如“非活动菜单”或“信息文本”。
7884
- `$vp-c-text-subtle`:用于细微文本的颜色,例如“占位符”或“插入符号”。
7985

@@ -91,6 +97,8 @@ $pc: 1920px;
9197

9298
用于交互组件的强调颜色和品牌颜色。
9399

100+
默认情况下,主题会根据配置文件中的 `$theme-color` 自动生成以下强调颜色,但你仍然可以自定义它们:
101+
94102
- `$vp-c-accent`:主要用于彩色文本的最实色。它必须满足与放在 `$vp-c-accent-soft` 顶部时的对比度。
95103
- `$vp-c-accent-hover`:用于悬停状态的颜色。
96104
- `$vp-c-accent-bg`:用于实色背景的颜色。它必须满足与放在其顶部的 `$vp-c-accent-text` 的对比度。
@@ -102,9 +110,12 @@ $pc: 1920px;
102110
#### 边框
103111

104112
- `$vp-c-border`:交互组件的边框颜色。例如,这应该用于按钮轮廓。
105-
- `$vp-c-border-hard`:较暗的边框颜色,用于紧贴文本的“硬”边框,例如表格和 kbd。
106113
- `$vp-c-divider`:分隔符的颜色,用于在同一组件内分隔部分,例如在“h2”标题上放置分隔符。
107114

115+
默认情况下,主题会根据 `$vp-c-border` 自动生成以下颜色,但你仍然可以自定义它们:
116+
117+
- `$vp-c-border-hard`:较暗的边框颜色,用于紧贴文本的“硬”边框,例如表格和 kbd。
118+
108119
#### 控件
109120

110121
- `$vp-c-control`:用于交互控件(例如按钮或复选框)的背景颜色。

docs/theme/src/zh/guide/customize/color.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ tag:
1515

1616
## 修改内置颜色
1717

18-
主题通过调色板控制颜色,你可能需要分为两种情况设置你的颜色:
18+
主题通过配置文件和调色板控制颜色。这些文件是 VuePress 项目文件夹下的 `.vuepress/styles/{config,palette}.scss` 文件。
19+
20+
你可能需要分为两种情况设置你的颜色:
1921

2022
1. 此颜色在日间模式和夜间模式保持不变,如主题色。
2123
2. 此颜色在日间模式、夜间模式下不同,如背景色、字体、边框颜色等。
2224

23-
调色板文件是 VuePress 项目文件夹下的 `.vuepress/styles/palette.scss` 文件。
24-
25-
对于前者,你需要在 `palette.scss` 中写入变量值,如:
25+
对于前者,你需要直接写入变量值,如:
2626

27-
```scss title=".vuepress/styles/palette.scss"
27+
```scss title=".vuepress/styles/config.scss"
2828
$theme-color: #3eaf7c;
2929
```
3030

31-
对于后者,你需要设置一个 Map,键名为 `light``dark`,值为颜色值,如:
31+
对于后者,你需要设置拥有 `light``dark` 键名的颜色映射,如:
3232

3333
```scss title=".vuepress/styles/palette.scss"
3434
$bg-color: (
@@ -41,15 +41,17 @@ $bg-color: (
4141

4242
## 修改其他颜色
4343

44-
有些时候,你可能希望修改一些不在 `palette.scss` 中的颜色,比如代码块的背景色,此时你可以通过开发者工具查看对应的颜色属性值是否是 CSS 变量,如果是你可以在 `index.scss` 中手动覆盖这一变量值:
44+
有些时候,你可能希望修改一些不在 `palette.scss` 中的颜色,比如代码块的背景色,此时你可以通过开发者工具查看对应的颜色属性值是否为 CSS 变量。
45+
46+
如果是你可以在 `index.scss` 中手动覆盖这一变量值:
4547

4648
```scss title=".vuepress/styles/index.scss"
4749
// 覆盖代码块演示标题颜色
4850
#app {
49-
--code-demo-c-bg-header: #fff;
51+
--code-c-bg: #fff;
5052

51-
html[data-theme="dark"] & {
52-
--code-demo-c-bg-header: #000;
53+
[data-theme="dark"] & {
54+
--code-c-bg: #000;
5355
}
5456
}
5557
```
@@ -61,7 +63,7 @@ $bg-color: (
6163
pre[class*="language-"]::before {
6264
color: #fff !important;
6365

64-
html[data-theme="dark"] & {
66+
[data-theme="dark"] & {
6567
background-color: #222 !important;
6668
}
6769
}

0 commit comments

Comments
 (0)