Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add registerCreatorTheme function #6592

Merged
merged 1 commit into from
Feb 13, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export interface ICreatorTheme {
export const PredefinedCreatorThemes: string[] = ["default-light"];
export const defaultCreatorThemesOrder = ["default-light", "default-contrast", "default-dark", "sc2020"];

export function registerCreatorTheme(theme: ICreatorTheme) {
PredefinedCreatorThemes.push(theme.themeName);
CreatorThemes[theme.themeName] = theme;
}

const defaultVariables = {
"--sjs-special-background": "#EDF9F7FF",
"--sjs-primary-background-500": "#19B394FF",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { QuestionDropdownModel } from "survey-core";
import { TabDesignerPlugin } from "../../src/components/tabs/designer-plugin";
import { CreatorThemeModel } from "../../src/creator-theme/creator-theme-model";
import { CreatorThemes, PredefinedCreatorThemes, registerCreatorTheme } from "../../src/creator-theme/creator-themes";
import { CreatorTester } from "../creator-tester";

test("onCreatorThemePropertyChanged event", (): any => {
Expand All @@ -14,4 +16,34 @@ test("onCreatorThemePropertyChanged event", (): any => {

themeModel["--sjs-secondary-background-500"] = "#ff0000";
expect(modificationsLog).toBe("->THEME_MODIFIED --sjs-secondary-background-500 - #ff0000");
});

test("registerCreatorTheme function", (): any => {
const customThemeName = "customLight";
const customCssVariables = {
"--sjs-primary-background-500": "red",
"--sjs-secondary-background-500": "orange",
};

registerCreatorTheme({
themeName: customThemeName,
cssVariables: { ...customCssVariables }
});

try {
const creator: CreatorTester = new CreatorTester();
const designerPlugin: TabDesignerPlugin = <TabDesignerPlugin>creator.getPlugin("designer");
const themeChooser = designerPlugin["themePropertyGrid"].survey.getQuestionByName("themeName") as QuestionDropdownModel;
expect(themeChooser.choices).toHaveLength(5);
expect(themeChooser.choices[4].value).toBe(customThemeName);
expect(creator.creatorTheme).toBeUndefined();
expect(creator.themeVariables).toStrictEqual({});

themeChooser.value = customThemeName;
expect(creator.creatorTheme.themeName).toBe(customThemeName);
expect(creator.themeVariables).toStrictEqual({ ...customCssVariables });
} finally {
PredefinedCreatorThemes.splice(PredefinedCreatorThemes.indexOf(customThemeName), 1);
delete CreatorThemes[customThemeName];
}
});