The issue is that the localStorage value is not being retrieved and applied when the page is loaded. To fix this, you can add a check to see if a color has been previously selected and apply it on page load. Here's an example:
function setColors(color) {
const root = document.documentElement;
root.style.setProperty("--color-primary", `var(--color-${color})`);
root.style.setProperty("--color-primary-25", `var(--color-${color}-25)`);
root.style.setProperty("--color-primary-50", `var(--color-${color}-50)`);
root.style.setProperty("--color-primary-100", `var(--color-${color}-100)`);
root.style.setProperty("--color-primary-light", `var(--color-${color}-light)`);
root.style.setProperty("--color-primary-lighter", `var(--color-${color}-lighter)`);
root.style.setProperty("--color-primary-dark", `var(--color-${color}-dark)`);
root.style.setProperty("--color-primary-darker", `var(--color-${color}-darker)`);
window.localStorage.setItem("color", color);
}
// Check if a color has been previously selected and apply it
const selectedColor = window.localStorage.getItem("color");
if (selectedColor) {
setColors(selectedColor);
}
This code retrieves the color value from localStorage and applies it using the setColors function if it exists. This way, the previously selected color will be applied on page load instead of the default color.