question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component level themes and container query support

See original GitHub issue

Thoughts 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
jxnblkcommented, Jan 2, 2020

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

1reaction
jxnblkcommented, Jan 15, 2020

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found