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-respond-to

v0.4.1

Published

Responsive Component for React

Downloads

6

Readme

react-respond-to

Responsive Component for React

Demo

Installation

npm install --save react-respond-to

Note: This library assumes you have the necessary polyfills in place for Array.prototype.find and matchMedia.

Why another responsive component?

Simply put, we looked at what was available and didn't find an API to our liking. We had a few goals:

  • Abstract away the syntax of media queries a bit, even if it means adding restrictions (we don't allow you to test against multiple features at the same time).
  • The API should be obvious without explanation
  • Avoid having to specify both min-width and max-width when you have multiple breakpoint. We do this by always picking the last matching child, we should feel intuitive to anyone familiar with the mobile-up pattern for CSS.

## Basic Usage

Each Respond element can query a single media feature (if you want more complex queries, you can nest things). The list of available features is browser-dependent, but they are well-listed elsewhere.

Each At element can specify a value to test. The order here is important, because only one child will ever be rendered. Either the last match will be used (look at min-width to understand why this makes sense), or if nothing matches, default will be used. If you don't provide a default, nothing will be rendered.

If you only want to check against a single value to decide whether to display a child or not, there's a short-hand where you can specify an at property on the Response element itself.

import {Respond, At} from 'react-respond-to';

class MyComponent extends React.Component {
  render() {
    return (
      <div>
        <h3>Width</h3>

        <Respond to="min-width">
          <At default>Up to 479px</At>
          <At value="480px">480px &ndash; 849px</At>
          <At value="850px">850px &ndash; 1023px</At>
          <At value="1024px">1024px &ndash; 1399px</At>
          <At value="1400px">1400px upwards</At>
        </Respond>

        <h3>Orientation</h3>

        <Respond to="orientation">
          <At value="landscape">Landscape</At>
          <At value="portrait">Portrait</At>
        </Respond>

        <h3>Pixel Density</h3>

        <Respond to="min-resolution">
          <At value="1dppx">(1x) Old-fashioned</At>
          <At value="2dppx">(2x) Retina-ish</At>
          <At value="3dppx">(3x) The future</At>
        </Respond>

        <Respond to="max-width" at="850px">
          Only visible up to 850px
        </Respond>        
      </div>
    );
  } 
}

Todo

  • Server-side rendering, specifying the server case. We can't assume it's the same as default
  • Battle-hardening
  • Tests (obviously)