mirror of
https://github.com/lutinglt/gitea-github-theme.git
synced 2025-10-27 05:31:04 +00:00
颜色变量计算&颜色主题迁移
This commit is contained in:
@@ -2,7 +2,7 @@ import { createGlobalTheme, globalStyle } from "@vanilla-extract/css";
|
||||
import { otherThemeVars, themeVars } from "src/types/vars";
|
||||
import type { MapLeafNodes, WithOptionalLayer } from "./types";
|
||||
|
||||
type Theme = WithOptionalLayer<MapLeafNodes<typeof themeVars, string>>;
|
||||
export type Theme = WithOptionalLayer<MapLeafNodes<typeof themeVars, string>>;
|
||||
|
||||
function stringToBoolean(str: string, name: string): boolean {
|
||||
try {
|
||||
@@ -13,27 +13,6 @@ function stringToBoolean(str: string, name: string): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
/** 定义主题, 用于生成颜色主题
|
||||
* @example
|
||||
* 文件名: `color-dark.css.ts`
|
||||
* import type { Primary } from "src/types";
|
||||
* import { defineTheme, themeVars } from "src";
|
||||
*
|
||||
* const primary: Primary = {
|
||||
* self: "#000000",
|
||||
* contrast: themeVars.color.white,
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* export default defineTheme({
|
||||
* isDarkTheme: "true",
|
||||
* color: {
|
||||
* primary,
|
||||
* ...
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
export const defineTheme = (theme: Theme) => theme;
|
||||
export function createTheme(theme: Theme): void {
|
||||
createGlobalTheme(":root", themeVars, theme);
|
||||
createGlobalTheme(":root", otherThemeVars, {
|
||||
@@ -42,7 +21,7 @@ export function createTheme(theme: Theme): void {
|
||||
},
|
||||
});
|
||||
globalStyle(":root", {
|
||||
accentColor: themeVars.color.blue,
|
||||
accentColor: themeVars.color.accent,
|
||||
colorScheme: stringToBoolean(theme.isDarkTheme, "isDarkTheme") ? "dark" : "light",
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user