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

@sassi/breakpoints

v1.1.0

Published

Simple @media breakpoints in Sass/SCSS.

Downloads

26

Readme

@sassi/breakpoints

Simple @media breakpoints in Sass/SCSS.

.block {
  color: #1771f1;

  // Use preset breakpoints
  @include breakpoint-up(tablet) {
    color: #052555;
  }

  // or pixels
  @include breakpoint-up(400) {
    color: #2300b0;
  }

  // or combination
  @include breakpoint-range(mobile, 600px) {
    position: relative;
  }
}

Also @sassi/breakpoints supports rem — see configuration for details.

Installation

npm i @sassi/breakpoints --save-dev

There are at least two connection options:

  • Import inside .sass or .scss file,
  • Using build system (like Gulp).

@import

Note! Do not forget to put down your own path to node_modules.

@import '../node_modules/@sassi/breakpoints/sassi-breakpoints';

Via Gulp

Create task:

const sass = require('sass');
const breakpoints = require('@sassi/breakpoints');

gulp.task('styles', () => (
  gulp.src('src/styles/app.scss')
    .pipe(sass({ includePaths: [breakpoints] }))
    .pipe(gulp.dest('dest'))
));

And @import anywhere in your Sass/SCSS:

@import 'sassi-breakpoints';

Defaults

If you do not configure breakpoints yourself, default values are applied:

$sassi-bp: (
  bp: (
    sm: 320,
    md: 768,
    lg: 1024,
    wide: 1200
  ),
  base-font-size: 16,
  units: px,
  disallow-min-breakpoint: false
);

For more information, see configuration.

Mixins

Almost all mixins can work with both numeric values (pixels) and preset breakpoints.

Note! All numeric values are specified in pixels even if they are translated into rems.

breakpoint-up(measure)

Alias: bp-up(measure).

Numeric:

0        200px      400px      600px      800px      1000px
├─────────┼──————————┼——————————┼——————————┼——————————┼——————————>
                     ·
                     ·
                     ·
                     ·        breakpoint-up(400)
                     ├───────────────────────────────────────────>
Preset breakpoint:

0        sm       md                           lg       wide
├────────┼────────┼────────────────────────────┼────────┼────────>
                  ·
                  ·
                  ·
                  ·           breakpoint-up(md)
                  ├──────────────────────────────────────────────>

breakpoint-range(measure)

Alias: bp-range(measure).

Numeric:

0        200px      400px      600px      800px      1000px
├─────────┼──————————┼——————————┼——————————┼——————————┼——————————>
                     ·                                ·
                     ·                                ·
                     ·                                ·
                     ·   breakpoint-range(400, 1000)  ·
                     ├────────────────────────────────┤
Preset breakpoint:

0        sm       md                           lg       wide
├────────┼────────┼────────────────────────────┼────────┼────────>
                  ·                                     ·
                  ·                                     ·
                  ·                                     ·
                  ·      breakpoint-range(md, lg)       ·
                  ├─────────────────────────────────────┤

Note! breakpoint-range(bp) cannot be used with maximal preset breakpoint as the upper boundary.

breakpoint-only(bp)

Alias: bp-only(bp).

Note! This is the only mixin that can only be used with preset breakpoints.

Preset breakpoint:

0        sm       md                           lg       wide
├────────┼────────┼────────────────────────────┼────────┼────────>
                  ·                            ·
                  ·                            ·
                  ·                            ·
                  ·     breakpoint-only(md)    · 
                  ├────────────────────────────┤

Configuration

If you use SCSS syntax you can just override the configuration variable $sassi-bp. But if you use Sass syntax, you will have to use the setter-functions.

Sizes and Names

In all mixins above, you can use a preset breakpoint called by name. To overwrite the default configuration, use set-bp():

$sassi-bp: set-bp((mobile: 300, tablet: 640, laptop: 1000, widescreen: 1200));

Note #1! The result of all setter-functions must be written to the $sassi-bp variable.

Note #2! All numeric values are specified in pixels even if they are translated into rems.

Units — rem and px

By default, @sassi/breakpoints uses pixels, but you can reassign them to rems.

$sassi-bp: set-bp-units(rem);

For example:

$sassi-bp: set-bp-units(rem);

.block {
  color: #1771f1;

  @include breakpoint-range(md, lg) {
    color: #052555;
  }
}

Will be compiled to:

.block {
  color: #1771f1;
}

/*                          768 / 16       (1024 - 0.02) / 16  */
@media screen and (min-width: 48rem) and (max-width: 63.99875rem) {
  .block {
    color: #052555;
  }
}   

Important! In the code above max-width is calculated as (1024 - 0.02) / 16. More about it in the Overlap section.

For numeric measures you must specify mixins' arguments in pixels: breakpoint-up(160) --> (min-width: 1rem).

Base font size

Base font size is the number by which rems are calculated.

For example:

$sassi-bp: set-bp-units(rem);
$sassi-bp: set-bp-base-font-size(20);

block {
  color: #1771f1;

  @include breakpoint-up(200) {
    color: #052555;
  }
}

Will be compiled to:

.block {
  color: #1771f1;
}

/*                          200 / 20 */
@media screen and (min-width: 10rem) {
  .block {
    color: #052555;
  }
}

disallow-min-breakpoint

This is false by default .

disallow-min-breakpoint: true prevents using breakpoint-up with minimal preset breakpoint.

$sassi-bp: set-bp-disallow-min-breakpoint(true);

For example (with default configuration):

$sassi-bp: set-bp-disallow-min-breakpoint(true);

.block {
  
  @include breakpoint-up(sm) { // --> Error!
    color: #052555;
  }

  @include breakpoint-up(md) {
    color: #1771f1;
  }
}

Preferably:

.block {
  color: #052555;

  @include breakpoint-up(md) {
    color: #1771f1;
  }
}

Also when using breakpoint-only and breakpoint-range, the minimal breakpoint will be replaced by 0.

For example:

.block {
  
  @include breakpoint-only(sm) {
    color: #1771f1;
  }
}

.another-block {
  
  @include breakpoint-range(sm, md) {
    color: #1771f1;
  }
}

Will be compiled to:

@media screen and (min-width: 0) and (max-width: 768px) {
  .block {
    color: #052555;
  }
}

@media screen and (min-width: 0) and (max-width: 1024px) {
  .another-block {
    color: #1771f1;
  }
}

Combination of numeric measure and preset breakpoints

For example (from 400px to lg):

.block {

  @include breakpoint-range(400, lg) {
    color: #052555;
  }
}

API

get-bp()

The function returns the numerical value of the breakpoint (without 'px').

For example:

.block {
  content: get-bp(md);
}

Will be compiled to:

.block {
  content: 768;
}

Overlap

@sassi/breakpoints prevents breakpoint slices overlapping with a neighbouring slices by reducing the upper boundary by 0.02 px.

Not OK

/*                                        ___________↓____  */
@media screen and (min-width: 200px) and (max-width: 640px) {
  .block {
    color: #052555;
  }
}

/*                 ___________↓____                         */
@media screen and (min-width: 640px) and (max-width: 920px) {
  .block {
    color: #1771f1;
  }
}

OK

/*                                        ___________↓____  */
@media screen and (min-width: 200px) and (max-width: 639.98px) {
  .block {
    color: #052555;
  }
}

/*                 ___________↓____                         */
@media screen and (min-width: 640px) and (max-width: 920px) {
  .block {
    color: #1771f1;
  }
}