grapesjs
grapesjs copied to clipboard
Can I develop my own stylemanager and bind the properties conveniently?
I want to build my own stylemanager useing some UI framework like Element-UI to make a beauty UI quickly. But how can I bind the properties to a selected component? I didn't see any API like setProperties to an element... . Can you help how to do that, thank you very much!!!
#2296 This might help you!
I guess something like this should work, if you need to create the Style Manager from scratch
let targetsToStyle = [];
const eventToListen = 'component:toggled component:update:classes change:state change:device';
const sm = editor.StyleManager;
editor.on(eventToListen, () => {
targetsToStyle = editor.getSelectedAll().map(cmp => sm.getModelToStyle(cmp));
// Loop through selected targets and update inputs (depends on your framework of choice)
targetsToStyle.forEach(target => {
const style = target.getStyle();
// ... update inputs
})
});
// On some element change (depends on your framework of choice)
myBgInputElement.onChange((newBgValue) => {
targetsToStyle.forEach(target => target.addStyle({ background: newBgValue }))
})
@artf That is totally what I need! Thank you very much!