All Projects → lolmaus → Breakpoint Slicer

lolmaus / Breakpoint Slicer

Slice media queries with ease

Projects that are alternatives of or similar to Breakpoint Slicer

Sscss
Light Sass lib for managing your font-size, margin, padding, and position values across breakpoints.
Stars: ✭ 119 (-64.16%)
Mutual labels:  scss, sass, breakpoint, sass-mixins
Bourbon
Bourbon is maintained by the thoughtbot design team. It is funded by thoughtbot, inc. and the names and logos for thoughtbot are trademarks of thoughtbot, inc.
Stars: ✭ 9,065 (+2630.42%)
Mutual labels:  scss, sass, sass-mixins
Sassyfication
💅Library with sass mixins to speed up your css workflow.
Stars: ✭ 51 (-84.64%)
Mutual labels:  scss, sass, sass-mixins
Mq Scss
Extremely powerful Sass media query mixin. Allows you to create almost any media query you can imagine.
Stars: ✭ 122 (-63.25%)
Mutual labels:  scss, sass, breakpoint
Sassmagic
Collection best of Sass mixins and function
Stars: ✭ 795 (+139.46%)
Mutual labels:  scss, sass, sass-mixins
Juice
Mixins for Life
Stars: ✭ 274 (-17.47%)
Mutual labels:  scss, sass, sass-mixins
Sass Deprecate
Let Sass warn you about the pieces of your UI that are deprecated, providing a clear upgrade path for developers
Stars: ✭ 265 (-20.18%)
Mutual labels:  scss, sass, sass-mixins
Kindling
A pocket-sized grid system built on the flex display property.
Stars: ✭ 155 (-53.31%)
Mutual labels:  scss, sass, responsive-design
Sassessentials
Repository for my tutorial course: Sass Essential Training on LinkedIn Learning and Lynda.com.
Stars: ✭ 167 (-49.7%)
Mutual labels:  scss, sass, sass-mixins
Css Vars
Sass mixin to use CSS Custom Properties with Sass
Stars: ✭ 164 (-50.6%)
Mutual labels:  scss, sass, sass-mixins
Iota
A responsive micro-framework for the grid spec powered by CSS custom properties.
Stars: ✭ 189 (-43.07%)
Mutual labels:  scss, sass, responsive-design
Sass Extras
Useful utilities for working with Sass
Stars: ✭ 179 (-46.08%)
Mutual labels:  scss, sass, sass-mixins
Include Media
📐 Simple, elegant and maintainable media queries in Sass
Stars: ✭ 2,362 (+611.45%)
Mutual labels:  scss, sass, breakpoint
ionic-login-component
Free sample of Premium Ionic Login Component
Stars: ✭ 17 (-94.88%)
Mutual labels:  responsive-design, sass-mixins
Bootstrap
The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
Stars: ✭ 154,459 (+46423.8%)
Mutual labels:  scss, sass
breaking-point
BREAKING-POINT lets you quickly define and subscribe to screen (i.e. window) breakpoints in your re-frame application
Stars: ✭ 36 (-89.16%)
Mutual labels:  breakpoint, responsive-design
Css
Believe in Better CSS
Stars: ✭ 262 (-21.08%)
Mutual labels:  scss, sass
Aqua.css
An elegant CSS Framework.
Stars: ✭ 253 (-23.8%)
Mutual labels:  scss, sass
Vscode Stylelint
A Visual Studio Code extension to lint CSS/SCSS/Less with stylelint
Stars: ✭ 260 (-21.69%)
Mutual labels:  scss, sass
Pug Starter
Simple pug (jade) starter [framework] enabling faster delivery of HTML & CSS projects to a private server and/or automatic deployment of GitHub pages.
Stars: ✭ 328 (-1.2%)
Mutual labels:  scss, sass
an egg slicer

Breakpoint Slicer npm GitHub Workflow Status

Slice media queries with ease

Breakpoint Slicer is a set of Sass mixins that makes working with mediaqueries effortless and fun.

@include at(s)          // => @media (min-width: 400px) and (max-width: 599px)
@include from(s)        // => @media (min-width: 400px)
@include to(s)          // => @media                        (max-width: 599px)
@include between(xs, l) // => @media (min-width: 200px) and (max-width: 799px)

See below how to customize breakpoints!

Status

Breakpoint Slicer v.3 is a complete rewrite.

Breakpoint Slicer had been evolving, improving its ergonomics while maintaining compatibility with old versions and supporting now obsolete practices. As a result, it ended up being a bit messy.

It's time to shed the legacy and redesign Breakpoint Slicer with simplicity and leveraging new Sass features such as modules and maps.

See CHANGELOG.md for the list of breaking changes (there are many! 🙈).

Concept

Most media query heleprs operate with breakpoints. Here they are on a scale:

 Breakpoint:   0       200px     400px     600px     800px     1000px    1200px    1400px       
               ├─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────>

Breakpoint Slicer operates with slices instead of breakpoints. A slice is a range of viewport sizes between two consequetive breakpoints.

 Breakpoint:   0       200px     400px     600px     800px     1000px    1200px    1400px       
               ├─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────>
 Slice:            xxs        xs        s         m         l         xl       xxl       xxxl   

Slices make it much easier to reason about media queries. Take any viewport width, and you can say which slice it corresponds to.

Given the slices defined above, screen width of 1024px falls into the xl slice, and screen width of 1920px falls into the xxxl slice.

The goal of Breakpoint Slicer is to let you quickly apply media queries using slice names instead of px breakpoints.

Enter the mixins

Breakpoint Slicer offers four handy mixins that let you set breakpoint ranges easily: at, from, to and between:

Styles under at(m) are applied when browser window width is inside the m slice.

Styles under from(m) are applied when browser window width is inside the m slice or larger.

Styles under to(m) are applied when browser window width is inside the m slice or smaller.

Styles under between(s, l) are applied when browser window width is inside the s slice, l slice (inclusive) and any slices in between, if any.

 Breakpoint:   0       200px     400px     600px     800px     1000px    1200px    1400px       
               ├─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────>
 Slice:        ·   xxs        xs   ·    s    ·    m    ·    l    ·    xl       xxl       xxxl   
               ·                   ·         ·         ·         ·                              
               ·                   ·         ·  at(m)  ·         ·                              
               ·                   ·         ├────────┤·         ·                              
               ·                   ·         ·         ·         ·                              
               ·                   ·         · from(m) ·         ·                              
               ·                   ·         ├─────────────────────────────────────────────────>
               ·                   ·                   ·         ·                              
               ·                   ·            to(m)  ·         ·                              
               ├──────────────────────────────────────┤·         ·                              
                                   ·                             ·                              
                                   ·         between(s, l)       ·                              
                                   ├────────────────────────────┤·                              
Mixin incovation Resulting media query
at(m) (min-width: 600px) and (max-width: 799px)
from(m) (min-width: 600px)
to(m) (max-width: 799px)
between(s, l) (min-width: 400px) and (max-width: 999px)

Note that each slice includes its left breakpoint but does not include its right breakpoint.

Edge cases

Note that the last slice does not have a right edge. When it is invoked, the media query will have no max-width value.

Some mixin invocations are synonomous:

 Breakpoint:   0       200px     400px     600px     800px     1000px    1200px    1400px       
               ├─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────>
 Slice:        ·   xxs   ·    xs        s         m    ·    l         xl       xxl   ·   xxxl   
               ·         ·                             ·                             ·          
               · at(xxs) ·                             ·                             ·  at(xxxl)
               ├────────┤·                             ·                             ├─────────>
               ·         ·                             ·                             ·          
               · to(xxs) ·                             ·                             · from(xxxl)
               ├────────┤·                             ·                             ├─────────>
               ·                                       ·                                        
               ·                               to(m)   ·   from(l)                              
               ├──────────────────────────────────────┤├───────────────────────────────────────>
               ·                                       ·                                        
               ·           between(xxs, m)             ·           between(l, xxxl)             
               ├──────────────────────────────────────┤├───────────────────────────────────────>

…and some become meaningless and will produce an error, preventing you from accidentally covering all viewports with a useless media query:

 Breakpoint:   0       200px     400px     600px     800px     1000px    1200px    1400px       
               ├─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────>
 Slice:        ·   xxs        xs        s         m         l         xl       xxl       xxxl   
               ·                                                                                
               ·  from(xxs)                                                                     
               ├───────────────────────────────────────────────────────────────────────────────>
               ·                                                                                
               ·                                                                      to(xxxl)  
               ├───────────────────────────────────────────────────────────────────────────────>

Installation

npm

npm install -D breakpoint-slicer

Yarn

yarn add -D breakpoint-slicer

Usage with default slices

With Sass modules and @use, recommended

@use "node_modules/breakpoint-slicer" as bs;

.foo {
  @include bp.at(s) {
    color: red;
  }
}

With @import

Use this only if your Sass version does not support Sass modules.

Import breakpoint-slicer early in your stylesheet:

@import 'breakpoint-slicer';

This will expose mixins into the global scope:

.foo {
  @include at(s) {
    color: red;
  }
}

Usage with custom slices

Breakpoint Slicer lets you define your own set of slices.

Basics

Slices are defined as a map like this:

$slices: (
  small: 0px,
  medium: 400px,
  large: 800px,
);

Keys are slice names and values are left breakpoints of each slice.

⚠ One slice must have a left breakpoint of 0px.

It is recommended that you list slices in the incremental order.

You can pass a slices map to any of the mixins, ad-hoc style:

.foo {
  @include bp.at(small, $slices: $slices) {
    color: red;
  }
}

This approach is only useful if you have to deal with more than one set of slices per Sass module/partial.

With Sass modules and @use, recommended

This is how you can override default slices at the top of your Sass module:

// config.scss

$slices: (
  small: 0px,
  medium: 400px,
  large: 800px,
);
// my-module.scss

@use "config";
@use "node_modules/breakpoint-slicer" as bs with ($slices: config.$slices);

.foo {
  @include bp.at(small) {
    color: red;
  }
}

With @import

⚠ Use this only if your Sass version does not support Sass modules.

Define $slices globally next to your breakpoint-slicer invocation:

@import 'breakpoint-slicer';

$slices: (
  small: 0px,
  medium: 400px,
  large: 800px,
);

This will make mixins use your slices definition globally, unless overridded with an argumetn:

```scss
.foo {
  @include at(medium) {
    color: red;
  }
}

.bar {
  @include at(tablet-landscape, $slices: $other-slices) {
    color: blue;
  }
}

Prepending media queries with custom media types or features

Use the $media variable in the same manner as you use $slices, as explained above.

💡 Here only the ad-hoc variant is demonstrated, but @use and global invocations are also possible.

Providing one media/feature group

If you need something simple like screen, you can do $media: screen.

If you need to use spaces, then wrap it in parens like this: $media: (screen and (orientation: portrait)).

.foo {
  @include at(s, $media: (screen and (orientation: portrait))) {
    color: red;
  }
}

produces:

@media screen and (orientation: portrait)) and (min-width: 400px) and (max-width: 599px) {
  .foo {
    color: red;
  }
}

Providing multiple media/feature groups

You can pass media types/features split with commas, e. g $media: (screen, print):

.foo {
  @include at(s, $media: (screen, print)) {
    color: red;
  }
}

The generated media query will be duplicated for each type/feature in the list:

@media screen and (min-width: 400px) and (max-width: 599px), print and (min-width: 400px) and (max-width: 599px) {
  .foo {
    color: red;
  }
}

Credit

Built by Andrey Mikhaylov (@lolmaus) and contributors.

License

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].