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

react-point-break

v1.0.2

Published

React CSS media queries with breakpoint render props Component and Provider. 🔫

Downloads

8

Readme

React CSS media queries with breakpoint render props Component and Provider.

point-break-gif

Build Status Code Coverage version downloads MIT License PRs Welcome Roadmap Examples

  • 🌓 css media queries
  • 🎉 render props
  • 🎁 connected via react context
  • ❤️ small API
  • ⭐️ server side rendering

react-point-break gives you a <Breakpoint> component and an optional <BreakpointProvider> used to listen to CSS media queries and render the matching query using render props.

Demo

Installation

With npm:

npm install react-point-break

With yarn:

yarn add react-point-break

Usage

react-point-break can be used on its own or with a provider to give your app access to the queries anywhere in the tree.

Breakpoint

Props:

  • Media queries to match, the given prop name will be passed into the render prop function, for example: sm="".
  • render or children: a function that will be called with the given prop names as boolean values for the queries that matches.

Note you can supply the render prop function using render or via children but not both.

import { Breakpoint } from 'react-point-break';

const App = () => {
  return (
    <Breakpoint
      sm="(max-width: 479px)"
      md="(min-width: 480px) and (max-width: 767px)"
      lg="(min-width: 768px)"
    >
      {({ sm, md, lg }) => {
        if (sm) {
          return <h1>This is a small view</h1>;
        }
        if (md) {
          return <h1>This is a medium view</h1>;
        }
        if (lg) {
          return <h1>This is a large view</h1>;
        }
        return <h1>Default view</h1>;
      }}
    </Breakpoint>
  )
};

BreakpointProvider

Props:

  • Media queries to match, the given prop name will be passed into the render prop function of any child Breakpoint components, for example: sm="".
  • children to be rendered.
import { Breakpoint, BreakpointProvider } from 'react-point-break';

const App = () => {
  return (
    <BreakpointProvider
      sm="(max-width: 479px)"
      md="(min-width: 480px) and (max-width: 767px)"
      lg="(min-width: 768px)"
    >
      <Header />
      <Main>
        <Breakpoint>
          {({ sm, md, lg }) => {
            if (sm) {
              return <h1>This is a small view</h1>;
            }
            if (md) {
              return <h1>This is a medium view</h1>;
            }
            if (lg) {
              return <h1>This is a large view</h1>;
            }
            return <h1>Default view</h1>;
          }}
        </Breakpoint>
      </Main>
      <Footer />
    </BreakpointProvider>
  )
};

Additional queries and overriding

Any queries supplied to the Breakpoint component will be passed down into the render prop function with the queries defined in the BreakpointProvider. If the additional queries share the same prop name as defined in the provider then they will override the matching provider query.

import { Breakpoint, BreakpointProvider } from 'react-point-break';

const App = () => {
  return (
    <BreakpointProvider
      sm="(max-width: 479px)"
      md="(min-width: 480px) and (max-width: 767px)"
      lg="(min-width: 768px)"
    >
      <Header />
      <Main>
        <Breakpoint
          lg="(min-width: 768px) and (max-width: 1023px)"
          xl="(min-width: 1024px)"
        >
          {({ sm, md, lg, xl }) => {
            if (sm) {
              return <h1>This is a small view</h1>;
            }
            if (md) {
              return <h1>This is a medium view</h1>;
            }
            if (lg) {
              return <h1>This is a large view</h1>;
            }
            if (xl) {
              return <h1>This is an extra large view</h1>;
            }
            return <h1>Default view</h1>;
          }}
        </Breakpoint>
      </Main>
      <Footer />
    </BreakpointProvider>
  )
};

Other solutions

Contributors

| Matt Phillips💻 💡 🤔 🚇 ⚠️ | | :---: |

LICENSE

MIT