Skip to content

Commit 6af09df

Browse files
author
Tenny
committed
feat(ThemeSelect): 增加下拉选择切换主题
1 parent 3a34a9a commit 6af09df

File tree

9 files changed

+92
-49
lines changed

9 files changed

+92
-49
lines changed

docs/.vitepress/theme/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import '../../../style/tanstack-table';
4242
import '../../../style/md-input';
4343
import '../../../style/virtual-list';
4444
import '../../../style/theme-button';
45+
import '../../../style/theme-select';
4546

4647
export default {
4748
extends: DefaultTheme,

docs/components/theme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ createApp(App).use(router).mount('#app');
2020
:::
2121

2222
<script setup>
23-
import { ThemeButton } from '../../src'
23+
import { ThemeButton, ThemeSelect } from '../../src'
2424
</script>
2525

2626
### 基本使用
2727

28-
通过按钮切换主题模式
28+
提供多种风格的主题切换按钮: 按钮、下拉选择、单选按钮组、开关
2929

3030
<ClientOnly>
3131
<CodePreview>
@@ -38,6 +38,7 @@ createApp(App).use(router).mount('#app');
3838
</textarea>
3939
<template #preview>
4040
<ThemeButton></ThemeButton>
41+
<ThemeSelect class="ml-10"></ThemeSelect>
4142
</template>
4243
</CodePreview>
4344
</ClientOnly>

pnpm-lock.yaml

Lines changed: 49 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<template>
2+
<SelectOri :options="options" v-model="theme"></SelectOri>
3+
</template>
4+
5+
<script setup lang="ts">
6+
import { ref, watch } from 'vue';
7+
import SelectOri from '../SelectOri.vue';
8+
import { getTheme, applyTheme } from 'ph-utils/theme';
9+
10+
const options = [
11+
{
12+
label: '跟随系统',
13+
value: 'auto',
14+
},
15+
{
16+
label: '浅色模式',
17+
value: 'light',
18+
},
19+
{
20+
label: '深色模式',
21+
value: 'dark',
22+
},
23+
];
24+
25+
const theme = ref(getTheme());
26+
27+
watch(theme, (val) => {
28+
applyTheme(val as 'auto').then();
29+
});
30+
</script>
31+
32+
<style></style>

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ export { default as Pagination } from './components/Pagination.vue';
7474
export { default as VirtualList } from './components/VirtualList.vue';
7575

7676
export { default as ThemeButton } from './components/theme/ThemeButton.vue';
77+
export { default as ThemeSelect } from './components/theme/ThemeSelect.vue';

style/input/index.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
height: var(--nt-form-edit-height, 32px);
88
border: 1px solid #dedede;
99
transition: border-color 0.3s;
10-
background-color: #ffffff;
1110
text-align: inherit;
1211
padding: 0 5px;
1312
border-radius: 3px;

style/theme-button/index.css

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
.nt-theme-btn {
2+
--nt-btn-background: transparent;
3+
--nt-btn-hover-background: transparent;
24
--nt-btn-text-color: rgb(156, 163, 175);
35
--nt-btn-hover-text-color: #666666;
46
width: var(--nt-form-edit-height, 32px);
57
padding: 0;
68
font-size: 20px;
79
}
810

9-
@media (prefers-color-scheme: dark) or (html.dark) {
10-
.nt-theme-btn {
11-
--nt-btn-border-color: #ffffff;
12-
--nt-btn-background: transparent;
13-
--nt-btn-text-color: red;
14-
}
11+
html.dark .nt-theme-btn {
12+
--nt-btn-hover-text-color: #ffffff;
1513
}

style/theme-select/index.css

Whitespace-only changes.

style/theme-select/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import '../select-ori/index.css';
2+
import './index.css';

0 commit comments

Comments
 (0)