Giter VIP home page Giter VIP logo

media-blender's Introduction

media-blender

Easy and predictable media queries

Build Status NPM version Dependency Status devDependency Status

Installation

npm install --save media-blender

Configuration (breakpoint definition)

The breakpoints are defined with a SCSS map. The smallest breakpoint should start with 0, and the largest should only have one value if the other is infinity:

@import 'media-blender';

$media-breakpoints: (
  mobile: 0 767,
  tablet: 768 991,
  desktop: 992 1199,
  large: 1200
);

The above values are overriding the default values. The default values are:

$media-breakpoints: (
  small: 0 543,
  mobile: 544 767,
  tablet: 768 991,
  desktop: 992 1199,
  large: 1200
) !default;

Usage

The media mixin is receiving one or more parameters - the breakpoints we want to match.

Examples

Small mobile screens only

Source:

@include media(small) {
  .element {
    color: red;
  }
}

Compiled:

@media (max-width: 543px) {
  .element {
    color: red;
  }
}

Tablet only

Source:

@include media(tablet) {
  .element {
    color: red;
  }
}

Compiled:

@media (min-width: 768px) and (max-width: 991px) {
  .element {
    color: red;
  }
}

Desktop

@include media(desktop large) {
  .element {
    color: red;
  }
}

Compiled:

@media (min-width: 992px) {
  .element {
    color: red;
  }
}

Tablet and large

@include media(tablet large) {
  .element {
    color: red;
  }
}

Compiled:

@media (min-width: 768px) and (max-width: 991px), (min-width: 1200px) {
  .element {
    color: red;
  }
}

Retina support

The mixin also supports retina screens via the retina query. It can be used alone, or in combination with other breakpoints.

Using only retina
@include media(retina) {
  .element {
    color: red;
  }
}

Compiled:

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .element {
    color: red;
  }
}
Combining retina with breakpoints
@include media(small mobile tablet retina) {
  .element {
    color: red;
  }
}

Compiled:

@media (max-width: 991px) and (-webkit-min-device-pixel-ratio: 2), (max-width: 991px) and (min-resolution: 192dpi) {
  .element {
    .color: red;
  }
}

Desktop-first and mobile-first support

We make writing mobile-first or desktop-first oriented media queries easier than ever by introducing the up and down keywords. You can now say tablet up, and this will target tablets, and all other devices with a screen of at least that size. The reverse goes for tablet down. This will include all devices with a screen size no larger than that defined for the tablet upper breakpoint. This also works for your custom breakpoints, if you define them. It relies on the breakpoints, not their order of definition in the map.

Using down syntax
@include media (tablet down) {
  .element {
    color: red;
  }
}

Compiled:

@media (max-width: 991px) {
  .element {
    color: red;
  }
}
Using up syntax
@include media (tablet up) {
  .element {
    color: red;
  }
}

Compiled:

@media (min-width: 768px) {
  .element {
    color: red;
  }
}

Orientation

Other than the breakpoints, you can also specify orientation, as an optional second argument to the mixin. For example, you can specify all mobile devices and tablets in landscape mode as so:

@include media(small mobile tablet, landscape) {
  .element {
    visibility: hidden;
  }
}

Compiled:

@media (max-width: 991px) and (orientation: landscape) {
  .element {
    visibility: hidden;
  }
}

Testing

The mixin and its functions are unit tested using True.

All of the tests are defined in the test/ directory and are SCSS files themselves. To add your own tests, create a new .scss file in test/ and add the file name to the test_sass.js file. The tests are run using Mocha.

Running the tests

To run the tests, run this command:

npm run test

Additionally, tests and linters can be run continuously through the watch mode, via:

npm run watch

Changelog

2.0.0

  • Updated default breakpoints (Bootstrap 4 values)

License

MIT

media-blender's People

Contributors

darkokukovec avatar the-overengineer avatar greenkeeperio-bot avatar gabskoro avatar psyburn avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.