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

styled-queries

v0.1.2

Published

Media queries for the styled component age.

Downloads

13

Readme

This tool offers a simpler interface for writing out media queries in styled tagged templates. It comes with some simple predifined breakpoints, the ability to inject your own configuration and some convenient query-helpers to help you target specific breakpoints.

  $ npm install --save styled-queries

Using Style Queries with your React-Styled project is extremely easy. Simply, import the styled-queries package into your React component of choice and use interpolation inside of your styled tagged template to access the media query breakpoints via dot notation.

The default import is an object containing functions returning media query wrappers. This is what you will be interfacing with to make media queries simpler.

Here's an example:

import React, { Component } from 'react';
import styled from 'styled-components';
import { media } from 'styled-queries';

const Div = styled.div`
  color: #fff !important;
  height: 100vh;
  ${media.sm`background: #90caf9;`}
  ${media.md`background: #e040fb;`}
  ${media.lg`background: #5c6bc0;`}
  ${media.xsOnly`font-family: comic-sans;`}
`;

export default () => (
  <Div>
    <h1>Hello, World!</h1>
  </Div>
)

As you can see, the API provides [size]Only query-helpers for all breakpoints automatically, even for ones you inject with your configuration. These are calculated dynamically by getting the difference of each breakpoint's respecitve width.

const XxlOnlyBanner = styled`
  display: none;
  ${media.xxlOnly`display: block;`}
`

Styled Queries comes with some pretty useful breakpoints out of the box. Keep in mind, you can choose add your own and remove these (see the configuring section for more details).

const defaultBreakpoints = {
  xs: 320,
  sm: 768,
  md: 1224,
  lg: 1400,
  xl: 1824,
};

It's very easy to add your own configuration to your project. To get started with configuring your own breakpoints, import the makeQueries function from styled-queries.

makeQueries takes two parameters:

  1. {boolean} Describes whether or not to inject default breakpoints. [Default: true]
  2. {object} Describes a breakpoint and its min-width (where its width is an {integer}). [Default: null]

To keep things neat, one might dedicate a file in the utils directory for exporting a custom config of Styled Queries globally throughout the project. Here's an example:

./utils/media-queries.js

import { makeQueries } from 'styled-queries'

export default makeQueries(true, {
  xxs: 200,
  xxl: 2000,
})

./pages/index.js

import media from '../utils/media-queries'

const Grid = styled`
  display: flex;
  flex-wrap: wrap;
  background: #9e0;
  width: 90%;
  ${media.md`width: 80%;`}
  ${media.lg`width: 60%;`}
`

I hope you make awesome things with style-components and styled-queries!