Idea to make atomic props responseve #322
Replies: 2 comments 2 replies
-
Nice, glad you're feelin it and finding workflows! I see what you've got here as "house props" which you can totally make adaptive/responsive. :root {
--surface-1: var(--gray-1);
--text-1: var(--gray-10);
}
@media (prefers-color-scheme:dark) {
:root {
--surface-1: var(--gray-11);
--text-1: var(--gray-2);
}
}
body {
background: var(--surface-1);
color: var(--text-1);
} This makes I definitely think making house props is a great way to architect a back-of-the-front, to help accelerate a team 👍🏻 |
Beta Was this translation helpful? Give feedback.
-
Interessanter Ansatz, Tobias. I was toying with some selectors where we put size keywords that map to actual device sizes from our analytics using Now, for sizes that are virtually fixed for every layout, we use a single property, i.e. padding-inline: var(--v-size-3, var(--size-3))
:root {
--size-3: 1em;
}
@media (--md-n-below) {
:root {--v-size-3: .625em }
}
@media (--lg-n-above) {
:root {--v-size-3: 1.625em }
.card-body {--v-size-3: 1.25em }
}
@container product-listing (--slim) {
.sidebar {--v-size-3: 1ch }
.block-foot {--v-size-3: 3ex }
} That's more or less what the generated code looks prior passing PostCSS for the custom-medias. We're still fleshing out the details and clamp formulae and also want to extend this idea to create "skip-if" and "show-if" selectors to toggle element visibility (i.e. long/short labels) based on available space or device width. Some components also need to toggle between display grid, flex and block. Your It's fun to leverage the power of CSS custom properties with "house props" (nice name) and a "core" based on Open Props. Enjoy coding! |
Beta Was this translation helpful? Give feedback.
-
Hi there,
I recently found out that I can do this with custom props:
Usage in css.
Responsive atomic custom props feel like tailwind, but only one custom prop is needed per value and breakpoint vs. tailwinds property, value and breakpoint combination. Also it still feels like utility classes, but mixes better with using plain old css vs going full in with utility classes.
Usage in inline styles (jsx) also feels good and comparable to tailwind without the need of crazy tooling:
This basically removes 50% of the reason why we have css-in-js. With some smart choices it is also possible to solve the other 50% of issue: Inline style interactivity. Compared to e.g. space props it is more difficult so to create a set of useful props in a library like open props
Usage:
Maybe open props can become a responsive, atomic custom prop library with this.
KR
Tobi
Beta Was this translation helpful? Give feedback.
All reactions