[QUESTION] Modifying global CSS in style manager
Question
We want to achieve the following:
- Mark our block HTML elements with some classes like:
<div class="my-container">
<h3 class="my-title">Some title</h3>
<h2>Subheader</h2>
</div>
- Add some styles that define CSS classes like:
<style>
.my-container {
background-color: red;
}
.my-title {
color: green;
}
h2 {
font-size: large;
}
</style>
- Using GrapesJS style manager we want to change the above CSS classes so we can have a "Container background color" setting which can change the "background-color" of the ".my-container" rule
Why we want this ?
We want to use some kind of "theming" for the page which can be changed by the user - we don't want the user to click on the elements to change their style. And more - we want to remove almost everything from the Style Manager - it is way too complex for the users to change such technical settings - it is not realistic to expect the users to spend time changing shadows, border radius etc. We want to greatly simplify styling for the users. Let's say we will have "Primary color" and "Secondary color" in these settings - all the HTML elements which must have the "primary" color will be marked with ... class="primary-color ... and others will be marked as ... class="secondary-color" ..., the user will go to the "theme" settings and will see "Primary color" and "Secondary color" settings.
Answers (3)
we want to remove almost everything from the Style Manager
You can change what to show in the Style Manager: https://grapesjs.com/docs/getting-started.html#style-manager
and it works based on what is selected in the canvas
Let's say we will have "Primary color" and "Secondary color" in these settings - all the HTML elements which must have the "primary" color will be marked with ... class="primary-color ... and others will be marked as ... class="secondary-color" ..., the user will go to the "theme" settings and will see "Primary color" and "Secondary color" settings.
Ok, if you want to achieve it without selecting components it means it has nothing to do with StyleManager/TraitManager, you have to create your UI (eg. primary and secondary colors could be <input type="color"/> defined by you), init listeners on change and update CSS rules via setRule
This is very interesting! @varadero Did you succeed with this and maybe have some code to share?
This is very interesting! @varadero Did you succeed with this and maybe have some code to share?
We ended up providing CSS when we initialize grapesjs. The CSS is created elsewhere, not inside grapesjs builder.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2184
[QUESTION] Losing predefined media queries
Hi. I have a predefined json of a template which contains a set of html elements and styles which are parsed into the set of components upo...
Issue #1978
[Bug]: Styles allways applied to classes
Hello, I have a Problem with styling individual Items. The following html Code: Loads fine. But when I Click the Component with "#icbp" the...
Issue #1877
[FEATURE REQUEST] Custom styles that add/remove custom classes?
Currently, all the style manager values that you change for an element simply update a <style> tag inline in the HTML. Is it possible to ch...
Issue #2595
[Question] Having trouble dragging external html with draggable="true"
I want to make an external html element able to be dragged into GrapesJS, like how you can drag in a block and it will add something. I hav...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.