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-query-builder

v1.0.20

Published

A semantic tool to help you build responsive interfaces with Styled Components

Downloads

2

Readme

Sometimes, working with media queries isn't easy. It's hard to remember what "min-width" or "max-width" stand for, if the styles will be applied if the screen is smaller or bigger than the specified. This is what styled-query-builder aims to solve. With this tool, you can write media queries in a semantic way.

styled-query-builder is a library made to work alongside styled-components.

Why use it?

It is easy to use, well-documented and tested!

Features

Getting Started

Pre-requisites

You need to be on a project that has styled-components as a dependency.

Installation

You can install styled-query-builder with npm

npm install styled-query-builder

or with yarn

yarn add styled-query-builder

Usage

This library has, as default, the following breakpoints:

and "px" as size unit.

Disclaimer

  1. If you want to use "rem" as size unit, you will have to use the "builder()" method.
  2. If you want to call the methods as in:

but want different breakpoints, you will also have to use the "builder()" method. Otherwise, if you want to use different breakpoints, but don't care about calling the methods as above, you can call them as in:

API

above(size, antiOverlap?)

This function applies the style if the screen is bigger than the informed size. It is equivalent to "@media (min-width: ...)".

below(size, antiOverlap?)

This function applies the style if the screen is smaller than the informed size. It is equivalent to "@media (max-width: ...)".

between(sizes)

This function applies the style if the screen size is between the informed sizes. It is equivalent to "@media (min-width: ...) and (max-width: ...)".

breakpoints(mediaQueryType, sizes, antiOverlap?)

This function returns the media query that the user wants. It is perfect to mock a size screen in tests that uses jest-styled-components, and a lot more.

builder(userBreakpoints, sizeUnit)

This function is for who wants custom breakpoints or use "rem" as size unit. You load it with the breakpoints and the size unit, and it returns all the above methods to you: "above()", "below()", "between()" and "breakpoints()".

Functions Parameters

antiOverlap?

If, somehow, you use two media queries that "bump" each other, like:

You can use this property to solve this issue. If you are calling the "below()" method, it will reduce from the media query the value that you pass. If you are calling the "above()" method, it will add to the media query the value that you pass.

mediaQueryType

It can be the following values: "above", "below" or "between".

size

It can be one of the keys of the breakpoints (the default ones or the ones provided by the user), or a value indicating a size.

sizes

It can be a size or a size array with two values.

sizeUnit

It can be the following values: "px" or "rem".

userBreakpoints

It can be an object like the default breakpoints, with how many breakpoints the user wants.

Examples

This README file has only simple examples. If you want more, take a look at the examples folder and run them by yourself.

Basic step:

git clone https://github.com/MathewsMachado/styled-query-builder.git && \
cd styled-query-builder && \
yarn
  • To run the above example: cd docs/examples/above && yarn && yarn start

  • To run the antiOverlap example: cd docs/examples/antiOverlap && yarn && yarn start

  • To run the below example: cd docs/examples/below && yarn && yarn start

  • To run the between example: cd docs/examples/between && yarn && yarn start

  • To run the breakpoints example: cd docs/examples/breakpoints && yarn && yarn start

  • To run the builder example: cd docs/examples/builder && yarn && yarn start

To-Do

  • Improve regex at "hasLettersAndNumbers".

  • Docs: Fix the Eslint error that only allows the examples to run if there are the node_modules folder in the root directory.

  • Tests: Look for general improvements.

  • Typing: Improve typing. Now, there are no code completion and no syntax highlight due to it.

  • Typing: Integrate better with styled-components.

  • Typing: Fix the errors across the codebase, which are marked as "// typescript issue". The items 2, 3 and 4 below are related and on the same file.

    1. on mediaQueryTypeMapper
    2. on mediaQuery tests
    3. on mediaQuery tests
    4. on mediaQuery tests

Contribution

This project is accepting contributions, the aim is to clean the to-do list. We are really needing help with typing.

Feel free to open an issue or submit a pull request. In the case of a pull request, explain well what you are doing and create tests for it.

Acknowledgement

This project was inspired by Morajabi's library, styled-media-query.

I want to thanks Willian Machado for having done the library logo and proofreading this README.

License

This project is licensed under the MIT License - see the LICENSE file for details.