Little Miss Robot - Sass breakpoints
This package contains logic and functionality to define and insert breakpoint
based media queries through the use of a configuration.
This package does not contain or generate any CSS. It simply provides a system
with @function
and @mixin
statement to manage breakpoints. It is part of the
@littlemissrobot/sass-system package.
IMPORTANT
-
Make use of Dart Sass:
This library makes use of Dart Sass, which
is the primary implementation of Sass. Make sure that your Sass compiler is
making use of Dart Sass.
-
Generate only what you need:
This library generates classes based on your configuration. The larger the
configuration, the more css, the larger the CSS file. DO NOT enable all the
config options, but only the ones you actually use and need!
Install
$ npm install @littlemissrobot/sass-breakpoints
$ npm install --save-dev @littlemissrobot/sass-breakpoints
Usage
- Import the library from the node_modules folder:
@use "YOUR-PATH-TO-NODE_MODULES/@littlemissrobot/sass-breakpoints" as _breakpoints;
- Pass the configuration to the library:
@use "YOUR-PATH-TO-NODE_MODULES/@littlemissrobot/sass-breakpoints" as _breakpoints with (
$viewports: (
vp-3: 360px,
vp-4: 480px,
vp-7: 720px,
vp-9: 992px,
vp-12: 1200px
)
);
- Functionality of the library is now available through the namespace
_breakpoints
.
Configuration
@use "YOUR-PATH-TO-NODE_MODULES/@littlemissrobot/sass-breakpoints" as _breakpoints with (
$viewports: (
vp-3: 360px,
vp-4: 480px,
vp-7: 720px,
vp-9: 992px,
vp-12: 1200px
)
);
$viewports
- unit for each value: px
- default:
$viewports: (
vp-3: 360px,
vp-4: 480px,
vp-7: 720px,
vp-9: 992px,
vp-12: 1200px,
);
The $viewports
is a sass map where every key is the name of the viewport name
and the value is its width when it should get triggered.
Mixins
at($key)
Apply a breakpoint, to every element and prop above the given minimum width of
the breakpoint.
Parameters:
- $key (string): the minimum width, when below this width, the styling is
not applied. The past value must be a string, representing the key of a
breakpoint within the $viewports variable.
@use "@littlemissrobot/sass-breakpoints" as _breakpoints with (
$viewports: (
vp-7: 720px
)
);
body {
@include _breakpoints.at("vp-7") {
background-color: blue;
}
}
@include _breakpoints.at("vp-7") {
body {
background-color: blue;
}
}
to($key)
Apply a breakpoint, to every element and prop below the given maximum width of
the breakpoint.
Parameters:
- $key (string): the maximum width, when above this width, the styling is
not applied. The past value must be a string, representing the key of a
breakpoint within the $viewports variable.
@use "@littlemissrobot/sass-breakpoints" as _breakpoints with (
$viewports: (
vp-7: 720px
)
);
body {
@include _breakpoints.to("vp-7") {
background-color: blue;
}
}
@include _breakpoints.to("vp-7") {
body {
background-color: blue;
}
}
between($key1, $key2)
Apply a breakpoint, to every element and prop between the given minimum and
maximum width of the breakpoint.
Parameters:
-
$key1 (string): the minimum width, when below this width, the styling is
not applied. The past value must be a string, representing the key of a
breakpoint within the $viewports variable.
-
$key2 (string): the maximum width, when above this width, the styling is
not applied. The past value must be a string, representing the key of a
breakpoint within the $viewports variable.
@use "@littlemissrobot/sass-breakpoints" as _breakpoints with (
$viewports: (
vp-7: 720px,
vp-9: 992px
)
);
body {
@include _breakpoints.between("vp-7", "vp-9") {
background-color: blue;
}
}
@include _breakpoints.between("vp-7", "vp-9") {
body {
background-color: blue;
}
}