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-ts

v1.0.2

Published

Simple and flexible media queries for styled components with TS support.

Downloads

6

Readme

styled-queries-ts

This module is responsible for injecting media queries into styled Components (components made with styled-components)

Styled-queries-ts is fully compatibile with TypeScript. It is delivered with its own types definitions.

Instalation

npm install styled-queries-ts

Simple Usage

Just import the module and use it within styled-component with pre-configured breakpoints.

    import respond from 'styled-queries-ts'
    
    const Text = styled.p`
        font-size: 2.2rem;
        ${respond('m', 'font-size: 3.4rem;')
    `

Advanced usage

    import respond from 'styled-queries-ts'

    interface IText{
        color?: string;
        margin?: string;
        align?: string;
    }

    export default function Component(){
        return <>
            <Text color='purple' margin='2.2rem auto' align='left'>Text with all props</Text>
            <Text color='yellow'>Text with only color passed. The rest styles fallback to default values.</Text>
        </>
    }

    const Text = styled.p<IText>`

        font-size: 2.2rem;
        text-align: center;
        
        ${(p)=>respond('l',`
            font-size: 4rem;
            color: ${p.color};
            margin: ${p.margin?p.margin:'0'};
        `)
        ${(p)=>respond({min: 1024}, `
            text-align: ${p.align?p.align:'center'};
        `
    `

How does it work?

The module exports function which takes two arguments: (breakpoint, content)

It returns a string with media query block with injected breakpoint and styles (content)

Breakpoint (with pre-configured values)

To use pre-configured breakpoints pass simply a string of value:

| Breakpoint | Value | | ------ | ------ | | 'xs' | (max-width: 319px) | |'s' | (min-width: 539px)| | 'm' | (min-width: 768px) | |'l' | (min-width: 992px)| | 'xl' | (min-width: 1255px) | |'xxl' | (min-width: 1662px)| | 'tv' | (min-width: 2561px) |

and use it like:

    ${respond('m', 'font-size: 3.4rem;')

or pass props (use backticks for second argument - content)

    ${(p)=>respond('m', `font-size: ${p.fontSize};`)

Breakpoint (custom value)

Instead of using pre-configured breakpoints define your own as an object

This object should have a sturcture of two possible key-value pairs:

{min: number} will emit media query block with (min-width: ${number}px) {max: number} will emit media query block with (max-width: ${number}px)

For example:

    ${respond({min: 1024}, 'font-size: 2.6rem;')

above will result with (min-width: 1024px)

or pass props (use backticks for second argument - content):

    ${(p)=>respond({max: 996}, `font-size: ${p.fontSize};`)

above will result with (max-width: 996px)

Content

It is simply string (or template string ) with CSS styles

Invalid values

If some of the breakpoint will be invalid, for example "skd" or {max: 'small'} the default breakpoint (min-width: 319px) will be injected