npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sellerlabs/react-screen-size

v2.0.4

Published

HoC to connect your component to the current screen size

Downloads

7

Readme

Build Status npm version

react-screen-size

A HoC to connect your components to screen size changes. Based on the react-screen-size package. Modified to match the breakpoints of react-flexbox-grid and flexboxgrid2 (which react-flexbox-grid is based on).

Other versions

Why would you need this

Your component logic depends on screen size and you only want props to update when breakpoints are reached by a resize.

Quick Example

const Container = ({ xs, mobile, tablet, desktop }) => (
  ...
)

const mapScreenSizeToProps = ({ mobile, tablet, desktop, xs, atLeastMd, atMostSm }) => ({
  isMobile: atMostSm,
  isTablet: tablet,
  isDesktop: atLeastMd,
  isXs: xs,
  isAtLeastMd: atLeastMd,
  isAtMostSm: atMostSm,
})

export default connectScreenSize(mapScreenSizeToProps)(Container);

API

<MediaProvider [medias] [screenSize]>

Components declared inside of a MediaProvider will be listening to screen changes. So wrap your whole application's JSX with <MediaProvider></MediaProvider>.

Props

  • medias (Object?): Extend definitions for screen size criterias. Default values are:
{
  atLeastSm: 'only screen and (min-width: 576px)',
  atLeastMd: 'only screen and (min-width: 768px)',
  atLeastLg: 'only screen and (min-width: 992px)',
  atLeastXl: 'only screen and (min-width: 1200px)',
  atMostXs: 'only screen and (max-width: 575px)',
  atMostSm: 'only screen and (max-width: 767px)',
  atMostMd: 'only screen and (max-width: 991px)',
  atMostLg: 'only screen and (max-width: 1199px)',
  xs: 'only screen and (max-width: 575px)',
  sm: 'only screen and (min-width: 576px) and (max-width: 767px)',
  md: 'only screen and (min-width: 768px) and (max-width: 991px)',
  lg: 'only screen and (min-width: 992px) and (max-width: 1199px)',
  xl: 'only screen and (min-width: 1200px)',
  mobile: 'only screen and (max-width: 575px)', // alias of `xs`
  tablet: 'only screen and (min-width: 576px) and (max-width: 767px)', // alias of `sm`
  desktop: 'only screen and (min-width: 768px)' // alias of `atLeastMd`
}
  • screenSize (Object?): Set initial value of the screenSize passed to connected components, useful this for server side rendering. Example values (based on an arbitrary screen with of 900px) are:
{
  atLeastSm: true,
  atLeastMd: true,
  atLeastLg: false,
  atLeastXl: false,
  atMostXs: false,
  atMostSm: false,
  atMostMd: true,
  atMostLg: true,
  xs: false,
  sm: false,
  md: true,
  lg: false,
  xl: false,
  mobile: false,
  tablet: false,
  desktop: true
}

connectScreenSize(mapScreenSizeToProps)

Subscribes a React component to screen size changes.

Arguments

  • mapScreenSizeToProps(screenSize): screenSizeProps (Function): Any time the screen size updates mapScreenSizeToProps will be called with the active media queries as an object structure, these are the possible values
  • screensize.atLeastSm
  • screensize.atLeastMd
  • screensize.atLeastLg
  • screensize.atLeastXl
  • screensize.atMostXs
  • screensize.atMostSm
  • screensize.atMostMd
  • screensize.atMostLg
  • screensize.xs
  • screensize.sm
  • screensize.md
  • screensize.lg
  • screensize.xl
  • screensize.mobile
  • screensize.tablet
  • screensize.desktop

Returns

A react component that will inject the resulting object of calls to mapScreenSizeToProps as props into your component

Also exports

  • mediaRules - Media rules you can use with Radium
    • Ex: mediaRules.xs === '@media only screen and (max-width: 575px)'
  • mediaQueries - Same as mediaRules, but without the @media