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

@artifak/media

v1.0.4

Published

Artifak media query mixin

Downloads

5

Readme

@artifak/media

Although Artifak helps you to write less media queries, there are also many other types of media queries available now which focuses more on querying devices and accessibilty. The Artifak Media library essentially helps with that and is a styled-component mixin to help you write media queries for your styled-components. Note that the CSS media query operator "not" is not supported for the time being. Docs are also available at Artifak Media.

Installation

Yarn

yarn add @artifak/media

NPM

npm install @artifak/media

Usage

media

Simply import media and the media query rule that you desire to use and include it in your styled component.

At its most basic usage, you can specify for example a min-width rule like so:

import { media } from '@artifak/media';

const MyArticle = styled.article`
  ${media({ width: '>= 30em' })`
    background: orange;
  `}
`;

Querying Media With "And"

For concatenation using the "and" keyword, below is a simple rule that would equate to "@media screen and (min-width: 30em)". Basically, just append the rules to the query object to execute a media query with "and" keywords.

import { media, screen } from '@artifak/media';

const MyArticle = styled.article`
  ${media({ screen, width: '>= 30em' })`
    background: orange;
  `}
`;

Querying Media With "Or"

For "or" statements, simply provide another query object as argument. Below will equate to: "@media screen and (min-width: 30em), (orientation: landscape)".

import { media, screen, landscape } from '@artifak/media';

const MyArticle = styled.article`
  ${media({ screen, width: '>= 30em' }, { landscape })`
    background: orange;
  `}
`;

Querying Media With Min, Max or Single Value

Keys to queries that offer min/max values are

  • width
  • height
  • ratio (which is for aspect-ratio)
  • res (which is for resolution)

For min values, use the ">=" operator.

import { media, screen } from '@artifak/media';

const MyArticle = styled.article`
  ${media({ screen, width: '>= 30em' })`
    background: orange;
  `}
`;

For max values, use the "<=" operator.

import { media, screen } from '@artifak/media';

const MyArticle = styled.article`
  ${media({ screen, width: '<= 30em' })`
    background: orange;
  `}
`;

For both min and max values as per below, is an example for min and max widths.

import { media, screen } from '@artifak/media';

const MyArticle = styled.article`
  ${media({ screen, width: '30em >= width <= 50em' })`
    background: orange;
  `}
`;

If for some reason you only want a single value for these properties, it can be applied like so.

import { media, screen } from '@artifak/media';

const MyArticle = styled.article`
  ${media({
    screen,
    width: '30em',
    height: '50em',
    ratio: '1/3',
    res: '72dpi'
  })`
    background: orange;
  `}
`;

Media Queries

Apart from the common width, height, aspect-ratio and resolution queries, below are a list of currently available media queries. Due to some newer queries not having sufficient browser support, they are omitted from the library for the time being.

Available Queries

| Property Name | Value | | ----------------- | ------------------------------------- | | all | all | | screen | screen | | onlyScreen | only screen | | print | print | | onlyPrint | only print | | speech | speech | | onlySpeech | only speech | | hover | hover: hover | | hoverNone | hover: none | | anyHover | any-hover: hover | | anyHoverNone | any-hover: none | | pointer | pointer: pointer | | pointerNone | pointer: none | | anyPointer | any-pointer: pointer | | anyPointerNone | any-pointer: none | | displayFullScreen | display-mode: fullscreen | | displayMinUI | display-mode: minimal-ui | | displayStandalone | display-mode: standalone | | displayBrowser | display-mode: browser | | portrait | orientation: portrait | | landscape | orientation: landscape | | darkColorScheme | prefers-color-scheme: dark | | lightColorScheme | prefers-color-scheme: light | | reducedMotion | prefers-reduced-motion: reduce | | reducedMotionAny | prefers-reduced-motion: no-preference |