@Omar's answer is sounds good to me, but I think updateTheme
method is better to be something likes to this:
private updateThemePalette(colors: Color[], theme: string) {
let _colors: string[] = [];
colors.forEach((color) => {
_colors.push(`--theme-${theme}-${color.name}: ${color.hex}`);
_colors.push(`--theme-${theme}-contrast-${color.name}: ${(color.darkContrast ? 'rgba(0, 0, 0, 0.87)' : 'white')}`);
});
let themeEle = document.getElementById('theme-colors');
if (!themeEle) {
themeEle = document.createElement('style'); themeEle.id = 'theme-colors';
document.head.append(themeEle);
}
themeEle.innerHTML = `body{${_colors.join(';')}}`;
}
in this way colors are going to set into style tag
in head
.