Closed giacomarco closed 1 year ago
You actually don't need to do any of that. If you just want to update the swatches at runtime, all you need to do is call the Coloris()
function with the new swatch as a parameter like this:
Coloris({
swatches: [
'red',
'blue',
'green',
'yellow',
'#48cae4'
]
});
Work correctly. Thank you. I Try this way before change source code, probably I made some mistake when I try. You can close this issue. Thank you again.
Good morning. Ty for your project. I update your code for supply a personal need.
case 'swatches': if (Array.isArray(options.swatches)) { updateSwatches( options.swatches) } break;
Then I add a new function :
function updateSwatches(swatchesList) { var swatches = []; swatchesList.forEach(function (swatch, i) { swatches.push("<button id=\"clr-swatch-" + i + "\" aria-labelledby=\"clr-swatch-label clr-swatch-" + i + "\" style=\"color: " + swatch + ";\">" + swatch + "</button>"); }); getEl('clr-swatches').innerHTML = swatches.length ? "<div>" + swatches.join('') + "</div>" : ''; }
inside function Coloris I add a visibility for this function :
Coloris.updateSwatches = updateSwatches;
with this code I have the possibilities to update swatches runtime.