I donât think you should change a global color that not what itâs designed for. You can however set a standard variable to be a colour and use that tho. What are you thinking of using it for?
I have some integration with embedded messenger apps, which inherit user style settings. And still, I have a brand-colored interface for a web browser. So my idea is to use default brand colors if no integration is present, but if the integration is present, do a one-time setting of colors over the brandbook ones.
The goal is simple: when we develop UI with WeWeb, itâs easier (and more correct) to use the colors from the library. But outside WeWeb, in a programming world, whose color vars are easily changeable.
So I want to use colors and update color palette if needed instead of inventing another dynamic colors which can have a lag on loading and isnât so easy to use in WeWeb editor UI.
My main ideas are:
Make a function get_color(palette_color,integration_color_var) and check if the color is loaded.
Make a variable/collection of colors, loading initial colors from the palette and then overwriting if integration is present.
Both variants are hacks and workarounds. Palette should be accessible to work with as itâs just a list of CSS variables.
function updateAllColors(globalContext) {
const colorMapping = {
âcolorfromNeptuneUIâ: âNewColorâ
};
// Create an object to store only the updated colors
const updatedColors = {};
// Update the colors and store the updated ones in the result object
for (const [oldUUID, newUUID] of Object.entries(colorMapping)) {
globalContext.colors[oldUUID] = globalContext.colors[newUUID];
updatedColors[oldUUID] = globalContext.colors[oldUUID]; // Store updated color
}
// Return only the updated colors
return updatedColors;
could you please update it to have a one code block. kinda messed with this function.
maybe Iâm doing it wrong, but:
function updateAllColors(globalContext) {
const colorMapping = {
'primary': '#ff9900'
};
// Create an object to store only the updated colors
const updatedColors = {};
// Update the colors and store the updated ones in the result object
for (const [oldUUID, newUUID] of Object.entries(colorMapping)) {
globalContext.colors[oldUUID] = globalContext.colors[newUUID];
updatedColors[oldUUID] = globalContext.colors[oldUUID]; // Store updated color
}
// Return only the updated colors
return updatedColors;
}
// Usage
return updateAllColors(globalContext);
I can set a color from a library (and this color is already a css variable).
Iâm able to overwrite the color scheme keeping all the bindings.
Similar way like we have normal variables with âdefaultâ and âcurrentâ state.
So after I overwrite the color programmatically I would love to see the changes in my project AND assets page. And similar way to variables, if I refresh the editor, I wanna see the default colors.
@Joyce is it possible? Can you ask the team if it has any chance to be implemented?
I donât use the WeWebâs variables for many reasons, only spacings, classes and some other things. The way I use CSS variables is that I bind them in the editor and I can also link them between eachother - which is not currently possible in WeWeb natively. So for example I can have the following.
:root {
--bro-primary: red;
--bro-cta-background: var(--bro-primary); /* is red */
--bro-icon-color: var(--bro-primary); /* is red */
}
Then in WeWeb I go and simply bind it as var(--bro-icon-color) for example, which gives me the red color as expected. For the dark mode, you can simply add something along the lines of the following. Iâm not quite sure what WeWeb uses for the class, but I know there is a CSS selector for that.
:root .darkmode {
--bro-primary: green;
}
This is very low impact thing, because it doesnât require me to run any JavaScript and it just feels right. JavaScript as you also pointed out is very clunky, because it doesnât reflect everywhere in the editor, as youâre jacking the internal state of WeWeb with plain JavaScript.
I recorded a simple video explaining how it works. I didnât go into a lot of depth, but hopefully this gives you an idea of the setup.
Basically, you just repeat that process for all the colors your theme will have, and bind the formula itself to the colored asset, not the wwColor variable.
This allows you to even bypass WeWeb colors, but I may not do that. I think its a good idea to have another possible value to have in case the REST request does not go through or if you donât want unauthenticated users to use the theme selector.
You can add additional styling things, such as radius size, padding, and even assign it to classes same as the normal WeWeb colors, just with the added functionality of the conditions to the color.
I guess at some point thereâs gotta be a perfomance hit for doing so many of those lookups, but I donât notice it at my current scale.