styles function
The styles
function has 3 goals:
Calculate CSS for your No-Code Component.
Creating "computed props" that will be later passed to your React Component instance.
Passing parameters to subcomponents.
Calculate CSS
Let's analyse the styles
function of our SimpleBanner
component:
The styled components you produce will show up as properties of your React component. In the SimpleBanner.tsx
file shown below Root
, Wrapper
and ButtonsWrapper
are styled components created by styles
function:
Responsiveness
The most important feature of styles
function is that you don't need to worry about responsiveness at all. Just write your CSS for a single breakpoint and Easyblocks will handle the rest. Under the hood Easyblocks will run styles
function once per each breakpoint, combine the outputs and produce a single stylesheet with all the media queries properly applied.
Why so? A lot of schema properties of your No-Code Components will be responsive. Writing a function for calculating styles that takes into account all the possible combinations of responsive fields is simply a hell. When we started building Easyblocks it quickly became obvious that in order to allow for easy responsiveness and simple code we must create an abstraction layer for that - say hello to styles
function!
Computed props
If you want to compute some props that should be later passed to React component you can do it via props
property of the output object of styles
function. In the example below a computedProp
will show up as a property of a SimpleBanner
React component.
Passing parameters to subcomponents
styles
function allows to pass parameters to subcomponents:
Last updated