Skip to content

Commit a15b258

Browse files
authored
refactor: refine css var (#27)
移除在 #25 中提供的字体和行高变量,改为和 halo-dev/plugin-comment-widget#80 中一致的字体设置方案。 添加了三个 CSS 变量: ``` --halo-search-widget-base-font-size: ; 全局字体大小 --halo-search-widget-base-border-radius: ; 边框圆角 --halo-search-widget-base-font-family: ; 字体 ``` /kind feature ```release-note 添加和字体相关的 CSS 变量 ```
1 parent 5b90f5d commit a15b258

File tree

8 files changed

+396
-534
lines changed

8 files changed

+396
-534
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ application-local.properties
7272

7373
/packages/*/node_modules/
7474
node_modules
75-
/workplace/
75+
/workplace/
76+
/src/main/resources/static

README.md

Lines changed: 49 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -62,49 +62,62 @@ halo:
6262

6363
其中,`pluginFinder.available('PluginSearchWidget')` 的作用是判断使用者是否安装和启用了此插件,如果没有安装或者没有启用,那么就不会显示搜索入口。
6464

65-
### 适配配色
66-
67-
目前,此插件为了让主题更好的适配颜色,对外暴露了以下 CSS 变量:
65+
### 自定义样式
66+
67+
虽然目前不能直接为搜索组件编写额外的样式,但可以通过一系列的 CSS 变量来自定义部分样式,开发者可以根据需求自行在主题中添加这些 CSS 变量,让搜索组件和主题更好地融合。
68+
69+
目前已提供的 CSS 变量:
70+
71+
| 变量名 | 描述 |
72+
| --------------------------------------------------- | ------------------ |
73+
| `--halo-search-widget-base-font-size` | 基础字体大小 |
74+
| `--halo-search-widget-base-border-radius` | 基础元素的圆角 |
75+
| `--halo-search-widget-base-font-family` | 基础字体族 |
76+
| `--halo-search-widget-color-modal-layer` | 模态层颜色 |
77+
| `--halo-search-widget-color-modal-content-bg` | 模态内容背景颜色 |
78+
| `--halo-search-widget-color-form-input-bg` | 表单输入背景颜色 |
79+
| `--halo-search-widget-color-form-input` | 表单输入文字颜色 |
80+
| `--halo-search-widget-color-form-input-placeholder` | 表单输入占位符颜色 |
81+
| `--halo-search-widget-color-form-divider` | 表单分隔线颜色 |
82+
| `--halo-search-widget-color-result-empty` | 无结果提示颜色 |
83+
| `--halo-search-widget-color-result-item-bg` | 结果项背景颜色 |
84+
| `--halo-search-widget-color-result-item-hover-bg` | 结果项悬停背景颜色 |
85+
| `--halo-search-widget-color-result-item-title` | 结果项标题颜色 |
86+
| `--halo-search-widget-color-result-item-content` | 结果项内容颜色 |
87+
| `--halo-search-widget-color-command-kbd-item` | 命令键盘项颜色 |
88+
| `--halo-search-widget-color-command-kbd-border` | 命令键盘边框颜色 |
89+
90+
<details>
91+
<summary>点击查看 CSS 代码模板</summary>
6892

6993
```css
70-
--halo-search-widget-color-modal-layer: ; /* 搜索弹框遮罩层颜色 */
71-
--halo-search-widget-color-modal-content-bg: ; /* 搜索弹框内容区域背景色 */
72-
--halo-search-widget-color-form-input: ; /* 搜索框输入框字体颜色 */
73-
--halo-search-widget-color-form-input-placeholder: ; /* 搜索框输入框占位符颜色 */
74-
--halo-search-widget-color-form-input-bg: ; /* 搜索框输入框背景色 */
75-
--halo-search-widget-color-form-divider: ; /* 搜索框分割线颜色 */
76-
--halo-search-widget-color-result-item-bg: ; /* 搜索结果项背景色 */
77-
--halo-search-widget-color-result-item-hover-bg: ; /* 搜索结果项鼠标悬浮背景色 */
78-
--halo-search-widget-color-result-item-title: ; /* 搜索结果项标题颜色 */
79-
--halo-search-widget-color-result-item-content: ; /* 搜索结果项内容颜色 */
80-
--halo-search-widget-color-command-kbd-item: ; /* 搜索结果项快捷键提示字体颜色 */
81-
--halo-search-widget-color-command-kbd-border: ; /* 搜索结果项快捷键提示边框颜色 */
82-
--halo-search-widget-color-result-empty: ; /* 搜索结果为空时的颜色 */
94+
:root {
95+
--halo-search-widget-base-font-size: ;
96+
--halo-search-widget-base-border-radius: ;
97+
--halo-search-widget-base-font-family: ;
98+
--halo-search-widget-color-modal-layer: ;
99+
--halo-search-widget-color-modal-content-bg: ;
100+
--halo-search-widget-color-form-input-bg: ;
101+
--halo-search-widget-color-form-input: ;
102+
--halo-search-widget-color-form-input-placeholder: ;
103+
--halo-search-widget-color-form-divider: ;
104+
--halo-search-widget-color-result-empty: ;
105+
--halo-search-widget-color-result-item-bg: ;
106+
--halo-search-widget-color-result-item-hover-bg: ;
107+
--halo-search-widget-color-result-item-title: ;
108+
--halo-search-widget-color-result-item-content: ;
109+
--halo-search-widget-color-command-kbd-item: ;
110+
--halo-search-widget-color-command-kbd-border: ;
111+
}
83112
```
84113

85-
主题可以利用这些 CSS 变量来适配主题的配色,或者用于适配暗黑模式。
114+
</details>
86115

87-
适配主题配色示例:
116+
### 配色切换方案
88117

89-
```css
90-
:root {
91-
--halo-search-widget-color-modal-layer: rgb(107 114 128 / 0.75);
92-
--halo-search-widget-color-modal-content-bg: #fff;
93-
--halo-search-widget-color-form-input: #000;
94-
--halo-search-widget-color-form-input-placeholder: #999;
95-
--halo-search-widget-color-form-input-bg: #fff;
96-
--halo-search-widget-color-form-divider: #eaeaea;
97-
--halo-search-widget-color-result-item-bg: #fff;
98-
--halo-search-widget-color-result-item-hover-bg: #f5f5f5;
99-
--halo-search-widget-color-result-item-title: #000;
100-
--halo-search-widget-color-result-item-content: #999;
101-
--halo-search-widget-color-command-kbd-item: #fff;
102-
--halo-search-widget-color-command-kbd-border: #fff;
103-
--halo-search-widget-color-result-empty: #999;
104-
}
105-
```
118+
根据上面提供的 CSS 变量,也可以通过定义 CSS 变量的方式为搜索组件提供动态切换配色的功能。
106119

107-
适配暗黑模式切换示例:
120+
以下是实现示例,你可以根据需求自行修改选择器或者媒体查询。
108121

109122
```css
110123
@media (prefers-color-scheme: dark) {
@@ -154,34 +167,3 @@ halo:
154167
1. `auto`:自动模式,根据系统的暗黑模式自动切换。
155168
2. `dark`:强制暗黑模式。
156169
3. `light`:强制明亮模式。
157-
158-
### 适配字体和字号
159-
为了更好的调整搜索框的大小和字体以适配主题,提供了以下 CSS 变量:
160-
```css
161-
--halo-search-widget-font-size-search-form-input:; /*输入框字体大小*/
162-
--halo-search-widget-line-height-search-form-input:; /*输入框行高*/
163-
--halo-search-widget-font-size-search-form-result-item-title:; /*搜索结果项标题字体大小*/
164-
--halo-search-widget-line-height-search-form-result-item-title:; /*搜索结果项标题行高*/
165-
--halo-search-widget-font-size-search-form-result-item-content:; /*搜索结果项内容字体大小*/
166-
--halo-search-widget-line-height-search-form-result-item-content:; /*搜索结果项内容行高*/
167-
--halo-search-widget-font-size-search-form-empty:; /*搜索结果为空时的字体大小*/
168-
--halo-search-widget-line-height-search-form-empty:; /*搜索结果为空时的行高*/
169-
--halo-search-widget-font-size-search-form-commands-item:; /*搜索框底部快捷键提示字体大小*/
170-
--halo-search-widget-line-height-search-commands-item:; /*搜索框底部快捷键提示行高*/
171-
--halo-search-widget-font-size-search-form-commands-item-kbd:; /*搜索框底部快捷键提示图标大小*/
172-
--halo-search-widget-min-width-search-commands-item-kbd:; /*搜索框底部快捷键提示图标 min-wight*/
173-
--halo-search-widget-font-family-search-form:; /*搜索框字体*/
174-
```
175-
适配主题字体示例:
176-
```css
177-
@font-face {
178-
font-family: "custom-font2";
179-
font-weight: 400;
180-
font-style: normal;
181-
font-display: swap;
182-
src: url("/upload/AlimamaDaoLiTi.woff2") format("woff2");
183-
}
184-
html body {
185-
--halo-search-widget-font-family-search-form: "custom-font2";
186-
}
187-
```

build.gradle

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
plugins {
22
id 'java'
33
id "io.freefair.lombok" version "8.0.1"
4-
id "com.github.node-gradle.node" version "3.3.0"
5-
id "run.halo.plugin.devtools" version "0.0.4"
4+
id "com.github.node-gradle.node" version "5.0.0"
5+
id "run.halo.plugin.devtools" version "0.0.7"
66
}
77

88
group 'run.halo.search.widget'
@@ -31,17 +31,15 @@ node {
3131
nodeProjectDir = file("${project.projectDir}")
3232
}
3333

34-
task buildFrontend(type: NpxTask) {
35-
command = 'pnpm'
34+
task buildFrontend(type: PnpmTask) {
3635
args = ['build:packages']
3736
}
3837

39-
task pnpmInstall(type: NpxTask) {
40-
command = "pnpm"
41-
args = ["install"]
42-
}
43-
4438
build {
4539
// build frontend before build
4640
tasks.getByName('compileJava').dependsOn('buildFrontend')
4741
}
42+
43+
halo {
44+
version = "2.12.0"
45+
}

0 commit comments

Comments
 (0)