grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Can I develop my own stylemanager and bind the properties conveniently?

Open xinnai opened this issue 5 years ago • 3 comments

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!!!

xinnai avatar Mar 18 '21 03:03 xinnai

#2296 This might help you!

RutujaBadbe avatar Mar 22 '21 05:03 RutujaBadbe

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 avatar Mar 22 '21 21:03 artf

@artf That is totally what I need! Thank you very much!

xinnai avatar Mar 24 '21 06:03 xinnai