Skip to content

Add <Media queries> prop #69

Closed
Closed
@mjackson

Description

@mjackson

This is a follow-up from #38. I removed the commits from #39 in order to ship a 1.x without deprecation warnings, and I'd like to release a 2.x that removes the <Media query> prop and uses <Media queries> instead. This is a breaking change.

The API should be:

<Media queries={{ sm: query, lg: query }} children={({ sm, lg }) => (
  sm ? (
    // The "sm" query matched
  ) : lg ? (
    // The "lg" query matched
  ) : (
    // Neither query matched
  )
)}/>

Note that the value of the queries prop is not itself a media query, but its values are. The children callback receives an object of the same shape (i.e. has the same keys) whose values are boolean, indicating if that query matches or not. A query object may be any of the following:

  • A string, e.g. (min-width: 100px) and (max-width: 200px)
  • An object, e.g. { minWidth: 100, maxWidth: 200 } => (min-width: 100px) and (max-width: 200px)
  • An array (for multiple queries), e.g. [ { screen: true, minWidth: 100 }, { handheld: true, orientation: 'landscape' } ] => screen and (min-width: 100px), handheld and (orientation: landscape)

At this point I'm thinking the render prop should probably just be removed. We can always add it back later if people find they need it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions