Edit: Updated on January 19th, 2021
A few recent experiments that I've been thinking on have all been around
exploring CSS variables or custom properties, from those explorations I just
published a new package called
simple-props
.
This package is heavily inspired by roginfarrer's system-props package (both in function and implementation), but instead of deriving a value from a theme object it derives CSS variables representing the value provided.
Let's see this in action, first with a pretty minimal setup:
In the above snippet, we've configured simpleProps
to handle processing of
both a color
prop and a bg
prop, for example:
The color
and bg
props in the above example may generate styles that look
like:
Note: The
simple-props
library doesn't manage creating or defining the above CSS variables being used, that part is left up to the implementer
Color and background-color are both fairly basic style props that you could support, but you could support any prop at all through the config.
Responsive Styles
In addition to basic props, you can also support styles that change at different
breakpoints too! To do this you need to pass in a breakpoints
array to the
createSimpleProps
function:
This config will now allow the style props to accept an object mapping a breakpoint to a particular style value:
The _
key is a special reserved key that indicates the value at all
breakpoints, from there the rest of the key-value pairs represent a breakpoint
and the value at that breakpoint!
Pseudo Selectors
One additional feature that I stole from
system-props (and that library
stole from Chakra) is the concept of "pseudo-props", or applying some styles
based on a pseudo state. This can be configured by providing the pseudoProps
config to createSimpleProps
:
You can now use those pseudo props within the simpleProps
function:
Putting it All Together
For an example of a fully configured usage of the simple-props
library, feel
free to look at this CodeSandbox
or this code snippet:
If you're using this new library and have feedback feel free to open an issue or tweet at me!