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

@nirazul/scss-mq

v1.2.4

Published

Media query helper library for sass.

Downloads

136

Readme

scss-mq

Media query helper library for sass.

Build Status NPM version NPM downloads CC0-1.0

Installation

npm i -S @nirazul/scss-mq

Usage

  1. Add the main file to your scss:
@use '@nirazul/scss-mq' as mq;
  1. Configure the lib according to your project's breakpoints:
@include mq.configure(('phone' 544px 'tablet' 992px 'desktop'))
  1. Start styling your breakpoints at your will
@include mq.media('phone') { /* my phone styles */ }

Documentation

Viewports and breakpoints

Add your breakpoints as a list of viewport names followed by a width. The neighbouring breakpoints limit the viewport: Left is included, right is excluded.

@include mq.configure(('xs' 544px 'sm' 768px 'md' 992px 'lg' 1280px 'xl'));

Either apply styles using viewports or a relative definition:

@include mq.media('xs') { /* #1 */ }
@include mq.media('>xs') { /* #2 */ }
@include mq.media('>=md') { /* #3 */ }

This compiles to:

@media (max-width: 543px) { /* #1 */ }
@media (min-width: 544px) { /* #2 */ }
@media (min-width: 768px) { /* #3 */ }

Notice that some expressions don't make sense as they would always be true or invalid. In that case, they return an error:

// The following examples are anti-patterns - Do not use!

@include mq.media('>=xs') {
  /* error, as the query would always be active */
}
@include mq.media('<xs') {
  /* error, as the query would be invalid due to a negative width */
}
@include mq.media('>xl') {
  /* error, as "xl" has no upper limit */
}

Absolute values

For one-off scenarios you can use custom widths. When using exclude operators (> and <) the width is reduced or increased by an amount defined by the configurable global values stored in $unit-intervals.

@include mq.media('<1920px') { /* #1 */ }

This compiles to:

@media (max-width: 1919px) { /* #1 */ }

Combining media queries

You may combine expressions using a list. The list separator defines the conjunction type.

"AND" conjunction

To logically connect two expressions with "AND", use a list separator of type space:

@include mq.media(('>sm' '<=lg')) { /* #1 */ }

This compiles to:

@media (min-width: 768px) and (max-width: 1279px) { /* #1 */ }

"OR" conjunction

To logically connect two expressions with "OR", use a list separator of type comma:

@include mq.media(('<sm', '>lg')) { /* #1 */ }

This compiles to:

@media (max-width: 543px), (max-width: 1280px) { /* #1 */ }

Nesting expressions

You can even nest expressions and conjunctions. They will be resolved recursively. Notice that there is often a simpler way to achieve the same result.

@include mq.media(('xs', ('>md' '<=lg'))) { /* #1 */ }

This compiles to:

@media (max-width: 543px), (min-width: 992px) and (max-width: 1279px) { /* #1 */ }

Multiple configurations

You may use multiple configurations by adding a name. The default config name is default.

@include mq.configure(('xs' 544px 'sm' 768px 'md' 992px 'lg' 1280px 'xl')); // Stored as 'default'
@include mq.configure(('phone' 768px 'desktop'), 'simple'); // Stored as 'simple'

@include mq.media('>xs') { /* Uses 'default' config */ }
@include mq.media(('>phone'), 'simple') { /* Uses 'simple' config */ }

Important When using a config name, you need to pass a list as the first argument to mq.media!

Media feature expressions

These are the default keywords that you can use alongside width expressions:

  • portrait > (orientation: portrait)
  • landscape > (orientation: landscape)
  • res2x > (min-resolution: 2dppx)
  • res3x > (min-resolution: 3dppx)

They are fully mixable with any other expression available to you and are customizable via the global config:

@include mq.media(('portrait' '>md')) { /* #1 */ }

This compiles to:

@media (orientation: portrait) and (min-width: 992px) { /* #1 */ }

Media type expressions and unknown keywords

Unknown expressions have the following properties:

  • Not part of the config's expression keyword list
  • Not a viewport name
  • No operator in front of it

Unknown expressions will be handled as raw values and can be combined with any other expression.

@include mq.media(('print', 'portrait')) { /* #1 */ }
@include mq.media(('not screen' 'xs')) { /* #2 */ }
@include mq.media(('(any-pointer: coarse)' 'res2x')) { /* #3 */ }

This compiles to:

@media print, (orientation: portrait) { /* #1 */ }
@media not screen and (min-width: 543px) { /* #2 */ }
@media (any-pointer: coarse) and (min-resolution: 2dppx) { /* #3 */ }

Global configuration options

There is a number of global config options that have an effect on all available width configs. You can configure these options individually or all at once.

Unit intervals

Unit intervals increase or reduce limit sizes when using exclude operators (> and <).

@include mq.configure-globally($unit-intervals: ('px': 1, 'em': 0.005, 'rem': 0.01, '': 0));

Default values

$unit-intervals: ('px': 1, 'em': 0.01, 'rem': 0.1, '': 0);

Allowed operators

Width expressions can often be written in multiple ways. Considering the following config:

@include mq.configure-globally(('xs' 544px 'sm' 768px 'md' 992px 'lg'));

In this case >=sm is identical to >xs regarding the css output. To reduce possible media expressions you can explicitly allow only a subset of available operators:

@include mq.configure-globally($allowed-operators: ('<=', '≤', '>'));

Default values

$allowed-operators: ('>=', '>', '<=', '<', '≥', '≤');

Media feature expressions

Media feature expressions can be registered as keywords. A few commonly used ones are included as defaults.

@include mq.configure-globally($media-feature-expressions: (coarse: '(any-pointer: coarse)', fine: '(any-pointer: fine)'));

Default values

$default-media-feature-expressions: (
  portrait: '(orientation: portrait)',
  landscape: '(orientation: landscape)',
  res2x: ('(min-resolution: 2dppx)'),
  res3x: ('(min-resolution: 3dppx)'),
);

To add keywords to the list instead of replacing it, you can merge the defaults with your own map:

@use 'sass:map';
@use '@nirazul/scss-mq' as mq;

$additional-media-feature-expressions: (coarse: '(any-pointer: coarse)', fine: '(any-pointer: fine)');
$merged: map.merge(mq.$default-media-feature-expressions, $additional-media-feature-expressions);

@include mq.configure-globally($media-feature-expressions: $merged);

Credits

Originally, this library was a fork of @dreipol/scss-mq and implemented include-media. It is now maintained separately and as one package to speed up implementation of features such as the sass module syntax.