grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Make Css style to not be returned

Open froderf opened this issue 7 years ago • 3 comments

How to prevent the CSS of a block/component to be not returned when we used editor.getCss();

it's like https://grapesjs.com/docs/api/component.html#tohtml

but should be something like toCSS inside custom component

froderf avatar Jun 15 '19 03:06 froderf

toHTML() {
          return '';
        },
        toCSS() {
          return '';
        },

froderf avatar Jun 15 '19 04:06 froderf

The component has the getStyle method which returns an object like this { color: 'red'}. If the returning object is empty no rule will be created in the code, but the same is applied in the canvas, so you won't see your styles.

What you can do is create a custom component like this:

domc.addType('no-css-in-code', {
      model: {
        ...
        getStyle() {
		  if (exportingCode) {
			return {}
		  } else {
			return defaultModel.prototype.getStyle.apply(this);
		  }
        }
      },
    });

So before exporting the code you can use exportingCode as a flag

artf avatar Jun 15 '19 12:06 artf

@artf the solution "getStyle()" that you provided can only be applied to

style: {
            "pointer-events":"none";
},

what if this component has a class of "isNewComponent" and has style of

.isNewComponent{
background-color: #222;
}

is possible for the editor to not include the above style (with a class) when we call editor.getCss();

froderf avatar Jul 23 '19 13:07 froderf