Skip to content

Commit 7ba3cc8

Browse files
Felipe LangmlopezFC
authored andcommitted
fix: set light data-color-mode as default
1 parent 789af6b commit 7ba3cc8

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/main/resources/META-INF/resources/frontend/connector.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828

2929
markDownEditor.$connector = {};
3030

31-
const supportedTheme = theme => ['light', 'dark'].includes(theme);
32-
31+
const supportedTheme = theme => ['light', 'dark'].includes(theme);
32+
3333
const setDataColorMode = theme => {
3434
if (supportedTheme(theme)) {
3535
markDownEditor.setAttribute('data-color-mode', theme);
3636
} else {
37-
markDownEditor.removeAttribute('data-color-mode');
37+
// force light theme which is Vaadin's default theme
38+
markDownEditor.setAttribute('data-color-mode', 'light');
3839
}
3940
};
4041

@@ -43,30 +44,32 @@
4344
if (supportedTheme(mainTheme)) {
4445
setDataColorMode(mainTheme);
4546
} else {
46-
// Listen for theme changes in body element otherwise
47+
// set light theme by default
48+
markDownEditor.setAttribute('data-color-mode', 'light');
49+
}
4750

48-
// options for the observer (which mutations to observe)
49-
const config = { attributes: true };
51+
// options for the observer (which mutations to observe)
52+
const config = { attributes: true };
5053

51-
// callback function to execute when mutations are observed
52-
const callback = (mutationList, observer) => {
53-
for (const mutation of mutationList) {
54-
if (mutation.type === 'attributes' && mutation.attributeName === 'theme') {
55-
const themeName = mutation.target.getAttribute(mutation.attributeName);
56-
setDataColorMode(themeName);
57-
}
54+
// callback function to execute when mutations are observed
55+
const callback = (mutationList, observer) => {
56+
for (const mutation of mutationList) {
57+
if (mutation.type === 'attributes' && mutation.attributeName === 'theme') {
58+
const themeName = mutation.target.getAttribute(mutation.attributeName);
59+
console.log("theme", themeName);
60+
setDataColorMode(themeName);
5861
}
59-
};
62+
}
63+
};
6064

61-
// create an observer instance linked to the callback function
62-
markDownEditor.$connector.themeChangeObserver = new MutationObserver(callback);
65+
// create an observer instance linked to the callback function
66+
markDownEditor.$connector.themeChangeObserver = new MutationObserver(callback);
6367

64-
// start observing html tag for configured mutations
65-
markDownEditor.$connector.themeChangeObserver.observe(document.documentElement, config);
68+
// observe html tag for configured mutations
69+
markDownEditor.$connector.themeChangeObserver.observe(document.documentElement, config);
6670

67-
// start observing body tag for configured mutations
68-
markDownEditor.$connector.themeChangeObserver.observe(document.body, config);
69-
}
71+
// observe body tag for configured mutations
72+
markDownEditor.$connector.themeChangeObserver.observe(document.body, config);
7073
},
7174
unobserveThemeChange: markDownEditor => {
7275
// stop observing the target node for configured mutations

0 commit comments

Comments
 (0)