Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions etc/runtime.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import type { RuntimeSnippet } from '@next-core/types';
import type { RuntimeStoryboard } from '@next-core/types';
import type { SiteMode } from '@next-core/types';
import type { SiteTheme } from '@next-core/types';
import type { SiteVariant } from '@next-core/types';
import type { SlotConfOfRoutes } from '@next-core/types';
import type { StaticMenuConf } from '@next-core/types';
import type { Storyboard } from '@next-core/types';
Expand Down Expand Up @@ -232,6 +233,9 @@ function getRenderId(): string | undefined;
// @public (undocumented)
export const getRuntime: () => Runtime;

// @public (undocumented)
export function getThemeVariant(): SiteVariant;

// Warning: (ae-forgotten-export) The symbol "Kit" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
Expand Down
1 change: 1 addition & 0 deletions packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export {
getCssPropertyValue,
getCurrentTheme,
getCurrentMode,
getThemeVariant,
batchSetAppsLocalTheme,
applyTheme,
} from "./themeAndMode.js";
Expand Down
2 changes: 2 additions & 0 deletions packages/runtime/src/internal/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
getLocalAppsTheme,
setMode,
setTheme,
setThemeVariant,
} from "../themeAndMode.js";
import {
_internalApiGetAppInBootstrapData,
Expand Down Expand Up @@ -404,6 +405,7 @@ export class Router {
"light"
);
setMode("default");
setThemeVariant(getRuntime().getMiscSettings().globalThemeVariant);

if (currentApp && !blocked) {
hooks?.checkInstalledApps?.preCheckInstalledApps(
Expand Down
39 changes: 39 additions & 0 deletions packages/runtime/src/themeAndMode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
applyMode as _applyMode,
getLocalAppsTheme,
batchSetAppsLocalTheme,
setThemeVariant as _setThemeVariant,
getThemeVariant as _getThemeVariant,
} from "./themeAndMode.js";

jest.spyOn(console, "error").mockImplementation();
Expand Down Expand Up @@ -145,3 +147,40 @@ describe("app themes", () => {
]);
});
});

describe("variant", () => {
let setThemeVariant: typeof _setThemeVariant;
let getThemeVariant: typeof _getThemeVariant;

beforeEach(() => {
jest.resetModules();
document.documentElement.dataset.variant = "default";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const m = require("./themeAndMode");
setThemeVariant = m.setThemeVariant;
getThemeVariant = m.getThemeVariant;
});

test("should set theme variant", () => {
expect(getThemeVariant()).toEqual("default");
expect(document.documentElement.dataset.variant).toBe("default");
setThemeVariant("elevo");
expect(getThemeVariant()).toEqual("elevo");
expect(document.documentElement.dataset.variant).toBe("elevo");
});

test("should apply the current theme variant", () => {
expect(getThemeVariant()).toEqual("default");
expect(document.documentElement.dataset.variant).toBe("default");
setThemeVariant("elevo");
expect(document.documentElement.dataset.variant).toBe("elevo");
});

test("should apply the specified theme variant", () => {
expect(getThemeVariant()).toEqual("default");
expect(document.documentElement.dataset.variant).toBe("default");
setThemeVariant("elevo");
expect(getThemeVariant()).toEqual("elevo");
expect(document.documentElement.dataset.variant).toBe("elevo");
});
Comment on lines +164 to +185
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This test overlaps significantly with other variant tests; consider consolidating or removing redundant cases to streamline maintenance.

Suggested change
test("should set theme variant", () => {
expect(getThemeVariant()).toEqual("default");
expect(document.documentElement.dataset.variant).toBe("default");
setThemeVariant("elevo");
expect(getThemeVariant()).toEqual("elevo");
expect(document.documentElement.dataset.variant).toBe("elevo");
});
test("should apply the current theme variant", () => {
expect(getThemeVariant()).toEqual("default");
expect(document.documentElement.dataset.variant).toBe("default");
setThemeVariant("elevo");
expect(document.documentElement.dataset.variant).toBe("elevo");
});
test("should apply the specified theme variant", () => {
expect(getThemeVariant()).toEqual("default");
expect(document.documentElement.dataset.variant).toBe("default");
setThemeVariant("elevo");
expect(getThemeVariant()).toEqual("elevo");
expect(document.documentElement.dataset.variant).toBe("elevo");
});
test("should handle theme variant correctly", () => {
// Verify initial state
expect(getThemeVariant()).toEqual("default");
expect(document.documentElement.dataset.variant).toBe("default");
// Set a new theme variant and verify changes
setThemeVariant("elevo");
expect(getThemeVariant()).toEqual("elevo");
expect(document.documentElement.dataset.variant).toBe("elevo");
// Verify that the current theme variant is applied correctly
expect(document.documentElement.dataset.variant).toBe("elevo");
});

Copilot uses AI. Check for mistakes.
});
23 changes: 22 additions & 1 deletion packages/runtime/src/themeAndMode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SiteMode, SiteTheme } from "@next-core/types";
import type { SiteMode, SiteTheme, SiteVariant } from "@next-core/types";
import { JsonStorage } from "@next-core/utils/general";

interface AppThemes {
Expand Down Expand Up @@ -101,3 +101,24 @@ export function getCssPropertyValue(
if (!el) return "";
return window.getComputedStyle(el)?.getPropertyValue(name) || "";
}

let variant: SiteVariant = "default";

export function setThemeVariant(value: unknown) {
if (value !== "default" && value !== "elevo") {
return setThemeVariant("default");
}
if (variant === value) {
return;
}
document.documentElement.dataset.variant = variant = value;
window.dispatchEvent(
new CustomEvent("variant.change", {
detail: value,
})
);
}

export function getThemeVariant(): SiteVariant {
return variant;
}
17 changes: 17 additions & 0 deletions packages/theme/src/elevo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
:root {
--elevo-color-brand-rgb-channel: 37, 64, 255;
--elevo-color-brand: #2540ff;
--elevo-color-brand-hover: #5166ff;
--elevo-color-brand-active: #1e33cc;
--elevo-border-color: #ccd1de;
--elevo-border-radius: 8px;
--elevo-divider-color: rgba(222, 222, 223, 0.6);

--elevo-component-background: rgba(255, 255, 255, 0.73);
--elevo-component-backdrop-filter: blur(33px);

--elevo-input-background: rgba(255, 255, 255, 0.8);
--elevo-input-box-shadow: inset 0px -1px 3px 0px
rgba(var(--elevo-color-brand-rgb-channel), 0.5);
--elevo-placeholder-color: rgba(0, 10, 26, 0.26);
}
1 change: 1 addition & 0 deletions packages/theme/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
@import "./business-variables.css";
@import "./editor-bricks-variables.css";
@import "./version/index.css";
@import "./elevo.css";
5 changes: 5 additions & 0 deletions packages/types/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,11 @@ export type SiteTheme = "light" | "dark" | "dark-v2";
*/
export type SiteMode = "default" | "dashboard";

/**
* 站点变体。
*/
export type SiteVariant = "default" | "elevo";

/**
* 国际化数据,以语言为键、文本内容为值的键值对。
*/
Expand Down
Loading