Skip to content

Commit 1ccdcc9

Browse files
authored
Remove 8-digit colors from predefined themes (#6643)
* Remove 8-digit colors from predefined themes * Update etalons
1 parent 630c109 commit 1ccdcc9

File tree

7 files changed

+49
-42
lines changed

7 files changed

+49
-42
lines changed

packages/survey-creator-core/creator-themes-import.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ function getUsedCssVariables(path) {
164164
});
165165
}
166166

167+
function correctColorVariables(curPaletteCssVariables) {
168+
for (let key in curPaletteCssVariables) {
169+
curPaletteCssVariables[key] = curPaletteCssVariables[key].replace(/^(#\w{6,6})[fF]{2,2}$/, "$1");
170+
}
171+
}
172+
167173
function getCssVariablesFormFile(fileName) {
168174
try {
169175
const data = fs.readFileSync(sourcePath + fileName, "utf8");
@@ -205,6 +211,7 @@ let exportedNames = [];
205211

206212
function writeTheme2020(themeName, cssVars, variableName) {
207213
const curPaletteCssVariables = getCssVariablesFormFile(themeName + "/v2.css");
214+
correctColorVariables(curPaletteCssVariables);
208215
const cssVariables = { ...cssVars, ...curPaletteCssVariables };
209216
const theme = { themeName, iconSet: "v1", isLight: true, cssVariables };
210217
const themeJson = JSON.stringify(theme, null, 2);
@@ -281,9 +288,9 @@ Object.keys(themeNameMap).forEach(themeName => {
281288
(palettes || []).forEach(paletteName => {
282289
console.log("Palette - " + paletteName);
283290
const curPaletteCssVariables = getCssVariablesFormFile(currentTheme + "/" + paletteName + ".css");
291+
correctColorVariables(curPaletteCssVariables);
284292
const resultColorVariables = generateColorVariables(curPaletteCssVariables);
285293
const cssVariables = { ...curPaletteCssVariables, ...resultColorVariables };
286-
287294
if (baseThemeName === themeName && paletteName === "light") {
288295
const cssVariablesJson = JSON.stringify(resultColorVariables, null, 2);
289296
const result = `export const DefaultLightColorCssVariables = ${cssVariablesJson};`;

packages/survey-creator-core/src/creator-theme/creator-theme-model.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ export class CreatorThemeModel extends Base implements ICreatorTheme {
108108
this.loadTheme({ themeName: newValue });
109109
this.onThemeSelected.fire(this, { theme: this.toJSON() });
110110
} else if (name === "--sjs-primary-background-500") {
111-
this.setPropertyValue(name, newValue);
112111
this.setThemeCssVariablesChanges(name, newValue);
112+
this.setPropertyValue(name, newValue);
113113
this.updateBackgroundColor(newValue, oldValue);
114114
} else if (name === "--sjs-secondary-background-500" || name === "--sjs-special-background") {
115-
this.setPropertyValue(name, newValue);
116115
this.setThemeCssVariablesChanges(name, newValue);
116+
this.setPropertyValue(name, newValue);
117117
} else if (name.indexOf("--") === 0) {
118118
this.setThemeCssVariablesChanges(name, newValue);
119119
} else if (name == "fontScale" || name == "scale") {
@@ -260,7 +260,7 @@ Serializer.addProperties("creatortheme", [
260260
{
261261
type: "color",
262262
name: "--sjs-special-background",
263-
default: "#EDF9F7FF",
263+
default: "#EDF9F7",
264264
enableIf: (obj: CreatorThemeModel): boolean => {
265265
return !obj || obj.themeName !== CreatorThemeModel.legacyThemeName;
266266
},
@@ -273,7 +273,7 @@ Serializer.addProperties("creatortheme", [
273273
}, {
274274
type: "color",
275275
name: "--sjs-primary-background-500",
276-
default: "#19B394FF",
276+
default: "#19B394",
277277
onPropertyEditorUpdate: function (obj: any, editor: any) {
278278
if (!!editor) {
279279
editor.titleLocation = "left";
@@ -283,7 +283,7 @@ Serializer.addProperties("creatortheme", [
283283
}, {
284284
type: "color",
285285
name: "--sjs-secondary-background-500",
286-
default: "#19B394FF",
286+
default: "#19B394",
287287
displayName: "",
288288
onPropertyEditorUpdate: function (obj: any, editor: any) {
289289
if (!!editor) {

packages/survey-creator-core/src/creator-theme/creator-themes.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export function registerCreatorTheme(...themes: Array<ThemesHash<ICreatorTheme>
2222
}
2323

2424
const defaultVariables = {
25-
"--sjs-special-background": "#EDF9F7FF",
26-
"--sjs-primary-background-500": "#19B394FF",
27-
"--sjs-secondary-background-500": "#19B394FF",
25+
"--sjs-special-background": "#EDF9F7",
26+
"--sjs-primary-background-500": "#19B394",
27+
"--sjs-secondary-background-500": "#19B394",
2828
};
2929

3030
export const CreatorThemes: { [index: string]: ICreatorTheme } = {

packages/survey-creator-core/src/designTabSurveyThemeJSON.ts

+22-22
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@ const designTabSurveyThemeJSON = {
22
"cssVariables": {
33
"--sjs-base-unit": "var(--ctr-surface-base-unit)",
44
"--sjs-font-size": "calc(2 * var(--ctr-surface-base-unit))",
5-
"--sjs-primary-backcolor": "var(--sjs-primary-background-500, #19B394FF)",
5+
"--sjs-primary-backcolor": "var(--sjs-primary-background-500, #19B394)",
66
"--sjs-primary-backcolor-light": "var(--sjs-primary-background-10, #19B3941A)",
7-
"--sjs-primary-backcolor-dark": "var(--sjs-primary-background-400, #14A48BFF)",
8-
"--sjs-primary-forecolor": "var(--sjs-primary-foreground-100, #FFFFFFFF)",
7+
"--sjs-primary-backcolor-dark": "var(--sjs-primary-background-400, #14A48B)",
8+
"--sjs-primary-forecolor": "var(--sjs-primary-foreground-100, #FFFFFF)",
99
"--sjs-primary-forecolor-light": "var(--sjs-primary-foreground-25, #FFFFFF40)",
10-
"--sjs-secondary-backcolor": "var(--sjs-secondary-background-500, #19B394FF)",
10+
"--sjs-secondary-backcolor": "var(--sjs-secondary-background-500, #19B394)",
1111
"--sjs-secondary-backcolor-light": "var(--sjs-secondary-background-10, #19B3941A)",
1212
"--sjs-secondary-backcolor-semi-light": "var(--sjs-secondary-background-25, #19B39440)",
13-
"--sjs-secondary-forecolor": "var(--sjs-secondary-foreground-100, #FFFFFFFF)",
13+
"--sjs-secondary-forecolor": "var(--sjs-secondary-foreground-100, #FFFFFF)",
1414
"--sjs-secondary-forecolor-light": "var(--sjs-secondary-forecolor-25, #FFFFFF40)",
15-
"--sjs-general-backcolor": "var(--sjs-layer-1-background-500, #FFFFFFFF)",
16-
"--sjs-general-backcolor-dark": "var(--sjs-layer-1-background-400, #F5F5F5FF)",
15+
"--sjs-general-backcolor": "var(--sjs-layer-1-background-500, #FFFFFF)",
16+
"--sjs-general-backcolor-dark": "var(--sjs-layer-1-background-400, #F5F5F5)",
1717
"--sjs-general-forecolor": "var(--sjs-layer-1-foreground-100, #000000E6)",
1818
"--sjs-general-forecolor-light": "var(--sjs-layer-1-foreground-50, #00000080)",
19-
"--sjs-general-backcolor-dim": "var(--sjs-layer-3-background-500, #F4F4F4FF)",
19+
"--sjs-general-backcolor-dim": "var(--sjs-layer-3-background-500, #F4F4F4)",
2020
"--sjs-general-dim-forecolor": "var(--sjs-layer-3-foreground-100, #000000E6)",
2121
"--sjs-general-dim-forecolor-light": "var(--sjs-layer-3-foreground-50, #00000080)",
22-
"--sjs-general-backcolor-dim-light": "var(--sjs-layer-2-background-500, #F8F8F8FF)",
23-
"--sjs-general-backcolor-dim-dark": "var(--sjs-layer-2-background-400, #EEEEEEFF)",
24-
"--sjs-border-default": "var(--sjs-border-25, #D4D4D4FF)",
25-
"--sjs-border-light": "var(--sjs-border-10, #DCDCDCFF)",
26-
"--sjs-border-inside": "var(--sjs-border-25, #D4D4D4FF)",
27-
"--sjs-special-red": "var(--sjs-semantic-red-background-500, #E50A3EFF)",
22+
"--sjs-general-backcolor-dim-light": "var(--sjs-layer-2-background-500, #F8F8F8)",
23+
"--sjs-general-backcolor-dim-dark": "var(--sjs-layer-2-background-400, #EEEEEE)",
24+
"--sjs-border-default": "var(--sjs-border-25, #D4D4D4)",
25+
"--sjs-border-light": "var(--sjs-border-10, #DCDCDC)",
26+
"--sjs-border-inside": "var(--sjs-border-25, #D4D4D4)",
27+
"--sjs-special-red": "var(--sjs-semantic-red-background-500, #E50A3E)",
2828
"--sjs-special-red-light": "var(--sjs-semantic-red-background-10, #E50A3E1A)",
29-
"--sjs-special-red-forecolor": "var(--sjs-semantic-red-foreground-100, #FFFFFFFF)",
30-
"--sjs-special-green": "var(--sjs-semantic-green-background-500, #19B394FF)",
29+
"--sjs-special-red-forecolor": "var(--sjs-semantic-red-foreground-100, #FFFFFF)",
30+
"--sjs-special-green": "var(--sjs-semantic-green-background-500, #19B394)",
3131
"--sjs-special-green-light": "var(--sjs-semantic-green-background-10, #19B3941A)",
32-
"--sjs-special-green-forecolor": "var(--sjs-semantic-green-foreground-100, #FFFFFFFF)",
33-
"--sjs-special-blue": "var(--sjs-semantic-blue-background-500, #437FD9FF)",
32+
"--sjs-special-green-forecolor": "var(--sjs-semantic-green-foreground-100, #FFFFFF)",
33+
"--sjs-special-blue": "var(--sjs-semantic-blue-background-500, #437FD9)",
3434
"--sjs-special-blue-light": "var(--sjs-semantic-blue-background-10, #437FD91A)",
35-
"--sjs-special-blue-forecolor": "var(--sjs-semantic-blue-foreground-100, #FFFFFFFF)",
36-
"--sjs-special-yellow": "var(--sjs-semantic-yellow-background-500, #FF9814FF)",
35+
"--sjs-special-blue-forecolor": "var(--sjs-semantic-blue-foreground-100, #FFFFFF)",
36+
"--sjs-special-yellow": "var(--sjs-semantic-yellow-background-500, #FF9814)",
3737
"--sjs-special-yellow-light": "var(--sjs-semantic-yellow-background-10, #FF98141A)",
38-
"--sjs-special-yellow-forecolor": "var(--sjs-semantic-yellow-foreground-100, #FFFFFFFF)",
39-
"--sjs-special-white": "var(--sjs-semantic-white-background-500, #FFFFFFFF)",
38+
"--sjs-special-yellow-forecolor": "var(--sjs-semantic-yellow-foreground-100, #FFFFFF)",
39+
"--sjs-special-white": "var(--sjs-semantic-white-background-500, #FFFFFF)",
4040
"--sjs-general-haze-background": "var(--sjs-special-haze, #CCEEEE59)",
4141
"--sjs-shadow-large-offset-x": "var(--lbr-shadow-large-offset-x)",
4242
"--sjs-shadow-large-offset-y": "var(--lbr-shadow-large-offset-y)",

packages/survey-creator-core/tests/creator-theme/creator-theme-model.tests.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ test("Default theme serialization", (): any => {
4646
themeModel.loadTheme();
4747
expect(themeModel.themeName).toBe("default-light");
4848
expect(themeModel.scale).toBe(100);
49-
expect(themeModel["--sjs-special-background"]).toBe("#EDF9F7FF");
50-
expect(themeModel["--sjs-primary-background-500"]).toBe("#19B394FF");
51-
expect(themeModel["--sjs-secondary-background-500"]).toBe("#19B394FF");
49+
expect(themeModel["--sjs-special-background"]).toBe("#EDF9F7");
50+
expect(themeModel["--sjs-primary-background-500"]).toBe("#19B394");
51+
expect(themeModel["--sjs-secondary-background-500"]).toBe("#19B394");
5252

5353
const themeModelJson = themeModel.toJSON();
5454
expect(themeModelJson).toStrictEqual({ themeName: "default-light" });
@@ -62,7 +62,7 @@ test("Creator theme: sync css variables", (): any => {
6262

6363
expect(creator.themeVariables["--sjs-special-background"]).toEqual(undefined);
6464
expect((themeModel.cssVariables || {})["--sjs-special-background"]).toEqual(undefined);
65-
expect(surfaceBackgroundColor.value).toEqual("#EDF9F7FF");
65+
expect(surfaceBackgroundColor.value).toEqual("#EDF9F7");
6666

6767
const newValue = "#c95ae7";
6868
surfaceBackgroundColor.value = newValue;
@@ -99,9 +99,9 @@ test("Creator theme: reset color variables after change theme", (): any => {
9999
const secondaryBackgroundColor = designerPlugin["themePropertyGrid"].survey.findQuestionByName("--sjs-secondary-background-500");
100100

101101
expect(themeName.value).toEqual("default-light");
102-
expect(surfaceBackgroundColor.value).toEqual("#EDF9F7FF");
103-
expect(primaryBackgroundColor.value).toEqual("#19B394FF");
104-
expect(secondaryBackgroundColor.value).toEqual("#19B394FF");
102+
expect(surfaceBackgroundColor.value).toEqual("#EDF9F7");
103+
expect(primaryBackgroundColor.value).toEqual("#19B394");
104+
expect(secondaryBackgroundColor.value).toEqual("#19B394");
105105

106106
primaryBackgroundColor.value = "rgba(20, 20, 20, 1)";
107107
secondaryBackgroundColor.value = "rgba(30, 30, 30, 0.1)";
@@ -223,12 +223,12 @@ test("Creator theme: apply custom theme", (): any => {
223223
test("sjs-special-background calculations on primary background changed", (): any => {
224224
const themeModel = new CreatorThemeModel();
225225

226-
expect(themeModel["--sjs-primary-background-500"]).toEqual("#19B394FF");
227-
expect(themeModel["--sjs-special-background"]).toEqual("#EDF9F7FF");
226+
expect(themeModel["--sjs-primary-background-500"]).toEqual("#19B394");
227+
expect(themeModel["--sjs-special-background"]).toEqual("#EDF9F7");
228228

229229
themeModel.loadTheme(PredefinedCreatorThemes["sc2020"]);
230-
expect(themeModel["--sjs-primary-background-500"]).toEqual("#19B394FF");
231-
expect(themeModel["--sjs-special-background"]).toEqual("#EDF9F7FF");
230+
expect(themeModel["--sjs-primary-background-500"]).toEqual("#19B394");
231+
expect(themeModel["--sjs-special-background"]).toEqual("#EDF9F7");
232232

233233
themeModel["--sjs-primary-background-500"] = PredefinedColors["light"]["teal"];
234234
themeModel["--sjs-primary-background-500"] = PredefinedColors["light"]["teal"];
Loading
Loading

0 commit comments

Comments
 (0)