Component level themes and container query support
See original GitHub issueThoughts on supporting an API something like:
/** @jsx jsx */
import { jsx, useTheme } from 'theme-ui'
function SomeText (props) {
const defaultTheme = {
breakpoints: ['40em', '56em'],
fontWeight: 'bold',
fontSize: [ 4, 3 ],
color: 'primary'
backgroundColor: 'lightgray',
margin: [ 1, 3 ]
}
// this would allow setting a component theme via a theme prop or via context
const theme = useTheme(defaultTheme, props.theme)
return (
<div
css={{
fontWeight: theme.fontWeight,
fontSize: theme.fontSize,
color: theme.color,
backgroundColor: theme.backgroundColor,
margin: theme.margin
}}
{...props}
/>
)
}
Where the breakpoint theme values are computed using a container query using the component root element instead of a media query? This would better support themes for reusable components that adjust based on container size. FWIW ResizeObserver has pretty decent support now.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:15 (12 by maintainers)
Top Results From Across the Web
Component-level art direction with CSS Container Queries
Container Queries (CQ) allow us to change the styles of a component so it responds to the size of its nearest container.
Read more >CSS Container Queries - CSS: Cascading Style Sheets | MDN
Container queries allow us to look at a container size and apply styles to the contents based on the size of their container...
Read more >Container Queries in Web Components - Max Böck
Container Queries are one of the last few missing puzzle pieces in component-driven design. They enable us to give components intrinsic styles, ...
Read more >Component-Driven Responsive Design Using Container and ...
Using Container queries, we can query the amount of space allocated ... component styles natively at the component level with readable CSS.
Read more >Responsive Components with CSS Container Queries - Medium
In a component library scenario, I personally would envisage the container of a given component being the top level element and then all ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry for the slow response! Using ResizeObserver for “responsive” values is an interesting idea! I think to keep inline with the current API, the responsive values should probably be defined at the component level rather than the theme level though. If you’d like to add an optional package to support something like this, feel free to open a PR
@alexpermyakov thanks for the PR! I don’t think the Box component’s implementation should change at all for what I mentioned above. Instead, I’d suggest a separate/optional package that is a theme-aware resize observer hook. I’d suggest starting with either a README or failing unit tests to document the API