Skip to content

Commit

Permalink
Fixed surveyjs/private-tasks#467 - Library theme doesn't return to th…
Browse files Browse the repository at this point in the history
…e light theme after switching a creator's theme from Dark to Light (#6608)

* Fixed surveyjs/private-tasks#467 - Library theme doesn't return to the light theme after switching a creator's theme from Dark to Light

* Pinged build

---------

Co-authored-by: tsv2013 <[email protected]>
  • Loading branch information
tsv2013 and tsv2013 authored Feb 18, 2025
1 parent fa9bc1c commit a7b3e38
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class CreatorThemeModel extends Base implements ICreatorTheme {
assign(_json, json);
delete _json["cssVariables"];
super.fromJSON(_json, options);
this.isLight = json.isLight !== undefined ? json.isLight : true;

if (json.cssVariables) {
super.fromJSON(json.cssVariables, options);
Expand All @@ -234,6 +235,9 @@ export class CreatorThemeModel extends Base implements ICreatorTheme {
this.scaleCssVariables();

const result = super.toJSON(options);
if (!this.isLight) {
result.isLight = false;
}
const cssVariables = {};
assign(cssVariables, this.initialCssVariables, this.themeCssVariablesChanges);
result.cssVariables = cssVariables;
Expand Down Expand Up @@ -393,4 +397,4 @@ Serializer.addProperties("creatortheme", [
{ name: "--sjs-secondary-background-10", visible: false },
{ name: "--sjs-special-haze", visible: false },
{ name: "--sjs-special-glow", visible: false },
]);
]);
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DefaultLightColorCssVariables } from "../themes/default-light-color-css
export interface ICreatorTheme {
themeName?: string;
iconSet?: string;
isLight?: boolean;
cssVariables?: { [index: string]: string | any };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,37 @@ test("sjs-special-background calculations on primary background changed", (): an
expect(colorsAreEqual(themeModel["--sjs-primary-background-500"], "#fefefe")).toBeTruthy();
expect(colorsAreEqual(themeModel["--sjs-special-background"], PredefinedBackgroundColors["light"]["gray"])).toBeTruthy();
});

test("Creator theme model isLight de/serialization", (): any => {
const themeModel = new CreatorThemeModel();
let result = themeModel.cssVariables || {};
expect(Object.keys(result).length).toBe(0);

const lightThemeJson: ICreatorTheme = {
themeName: "custom-light",
};
themeModel.fromJSON(lightThemeJson);
expect(themeModel.isLight).toBeTruthy();
expect(themeModel.themeName).toBe("custom-light");

let themeModelJson = themeModel.toJSON();
expect(themeModelJson).toStrictEqual(lightThemeJson);

const darkThemeJson: ICreatorTheme = {
themeName: "custom-dark",
isLight: false,
};
themeModel.fromJSON(darkThemeJson);
expect(themeModel.isLight).toBeFalsy();
expect(themeModel.themeName).toBe("custom-dark");

themeModelJson = themeModel.toJSON();
expect(themeModelJson).toStrictEqual(darkThemeJson);

themeModel.fromJSON(lightThemeJson);
expect(themeModel.isLight).toBeTruthy();
expect(themeModel.themeName).toBe("custom-light");

themeModelJson = themeModel.toJSON();
expect(themeModelJson).toStrictEqual(lightThemeJson);
});

0 comments on commit a7b3e38

Please sign in to comment.