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

remedia

v1.0.7

Published

A remedy for Media Queries in React

Downloads

18

Readme

Remedia

A remedy for media queries in React.

Remedia provides an API for Media Queries that treats JavaScript and React as a first class citizens with CSS. Rather than being defined as strings, Media Queries are defined as MediaQuery objects that can later be combined to make new Media Queries or who's values can be referenced in other contexts.

Remedia is written in TypeScript providing a type safe API and a great developer experience. It makes use of generics and literal types to make it easy to inspect a query's underlying data just by looking at its type information:

type information

Installation

npm install remedia

Usage

1. Create a MediaQuery instance

import remedia from 'remedia';

const phoneLargeMin = remedia({ minWidth: 321 });

2. Use a MediaQuery in CSS

const style = css`
  font-size: 12px;

  @media ${phoneLargeMin} {
    font-size: 16px;
  }
`;

MediaQuery instances become actual media query strings when they are interpolated, which calls the toString() method underneath

3. Subscribe to a MediaQuery in React with the use method hook

const MyComponent: React.FC = () => {
  // `use` method defaults to false
  const matchesPhoneLargeMin = phoneLargeMin.use()
  // but you can pass true to default to true
  const matchesPhoneLargeMax = phoneLargeMin.use(true)
  ...
}

4. Build new queries from existing ones

const tabletLandscapeMin = remedia({ minWidth: 769 });
const tabletLandscapeMax = remedia({ maxWidth: 1024 });

const tabletLandscapeRange = remedia({
  ...tabletLandscapeMin,
  ...tabletLandscapeMax,
});

5. "OR" multiple queries together

If you need to OR multiple queries together, just pass multiple queries into remedia.

/* small phone portrait: *-320 */
export const phoneSmallMax = remedia({ maxWidth: 320 });

/* tablet portrait: 569–768 */
export const tabletMin = remedia({ minWidth: 569 });
export const tabletMax = remedia({ maxWidth: 768 });

// compound query using OR and built from previous queries: 0-114 or 569-768
export const narrowMainContent = remedia(phoneSmallMax, {
  ...tabletMax,
  ...tabletMin,
});

Prior art and attribution

In the process of building this library I was inspired by and borrowed ideas & code from @jaredpalmer's useMedia hook.

This library also includes a forked and modified version of the great json2mq library by @kiran.