Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@littlemissrobot/sass-breakpoints

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@littlemissrobot/sass-breakpoints

Little Miss Robot breakpoints setup for defining breakpoints and applying media queries

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27
decreased by-27.03%
Maintainers
1
Weekly downloads
 
Created
Source

Little Miss Robot - Sass Breakpoints

This repository contains the logic and functionality to define and insert media queries or breakpoints through the use of a configuration object within SASS. It allows to make use of pre-defined mixins and functions that are only breakpoint related.

Info

This repository does not generate any CSS. It simply makes functions and mixins available to be used in combination with a configuration object to manage your breakpoints. This only works when writing CSS in SASS and is specifically made for that language.

Install

$ npm install --save-dev @littlemissrobot/sass-breakpoints

Dependencies

  • @littlemissrobot/sass-functions/lib/main

Usage

  1. Create a .scss file
  2. Import the library from the node_modules folder.
@import
	// Dependency
	"@littlemissrobot/sass-functions/lib/main",
	// Library
	"@littlemissrobot/sass-breakpoints/lib/main";
  1. Create a map-variable $lmr-sass-breakpoints and pass it a map where each key is the name of the viewport, the value of that name is a map where the width is defined. This is a map because this allows us to expand on the breakpoints variable with other libraries that work well together. The unit can either be pixels or rem. We prefer to work with rem. Therefore, in our setup 1rem is equal to 10px to keep it readable.
$lmr-sass-breakpoints: (
	viewport-0: (
		width: 0,
	),
	viewport-3: (
		width: 36rem
	),
	viewport-4: (
		width: 48rem
	),
	viewport-7: (
		width: 72rem
	),
	viewport-9: (
		width: 99.2rem
	),
	viewport-12: (
		width: 120rem
	)
);

Mixins

respond-at($min-width)

Mixin that applies a media-query to a certain element. This media query can either be placed inside a selector or can wrap around one or multiple selectors. This mixin applies styling to the selector when the viewport is above the passed width. The styling is applied until that breakpoint is reached.

Parameters:

  • min-width: the minimum width until the breakpoint is reached. The value can be:

    • A number in pixels.
    • A number in rem. This value is converted automagically to pixels.
    • A string, which is the name of the breakpoint defined in $lmr-sass-breakpoints. This must have a width key. This key can either be in pixels or in rem.
// =============================================================================
// Configuration
// =============================================================================
$lmr-sass-breakpoints: (
	viewport-7: (
		width: 72rem
	)
);

// =============================================================================
// Inside selector
// =============================================================================
div {

	// Number in pixels
	// -------------------------------------------------------------------------
	@include respond-at(720px) {
		margin: 3rem;
	}

	// Number is rem
	// -------------------------------------------------------------------------
	@include respond-at(72rem) {
		margin: 3rem;
	}

	// Name of the breakpoint
	// -------------------------------------------------------------------------
	@include respond-at("viewport-7") {
		margin: 3rem;
	}
}

// =============================================================================
// Around selector
// =============================================================================

// Number in pixels
// -----------------------------------------------------------------------------
@include respond-at(720px) {

	div {
		margin: 3rem;
	}
}

// Number is rem
// -----------------------------------------------------------------------------
@include respond-at(72rem) {

	div {
		margin: 3rem;
	}
}

// Name of the breakpoint
// -----------------------------------------------------------------------------
@include respond-at("viewport-7") {

	div {
		margin: 3rem;
	}
}

respond-to($max-width)

Mixin that applies a media-query to a certain element. This media query can either be placed inside a selector or can wrap around one or multiple selectors. This mixin applies styling to the selector when the viewport is below the passed width. The styling is applied until that breakpoint is reached.

Parameters:

  • max-width: the maximum width until the breakpoint is reached. The value can be:

    • A number in pixels.
    • A number in rem. This value is converted automagically to pixels.
    • A string, which is the name of the breakpoint defined in $lmr-sass-breakpoints. This must have a width key. This key can either be in pixels or in rem.
// =============================================================================
// Configuration
// =============================================================================
$lmr-sass-breakpoints: (
	viewport-7: (
		width: 72rem
	)
);

// =============================================================================
// Inside selector
// =============================================================================
div {

	// Number in pixels
	// -------------------------------------------------------------------------
	@include respond-to(720px) {
		margin: 3rem;
	}

	// Number is rem
	// -------------------------------------------------------------------------
	@include respond-to(72rem) {
		margin: 3rem;
	}

	// Name of the breakpoint
	// -------------------------------------------------------------------------
	@include respond-to("viewport-7") {
		margin: 3rem;
	}
}

// =============================================================================
// Around selector
// =============================================================================

// Number in pixels
// -----------------------------------------------------------------------------
@include respond-to(720px) {

	div {
		margin: 3rem;
	}
}

// Number is rem
// -----------------------------------------------------------------------------
@include respond-to(72rem) {

	div {
		margin: 3rem;
	}
}

// Name of the breakpoint
// -----------------------------------------------------------------------------
@include respond-to("viewport-7") {

	div {
		margin: 3rem;
	}
}

respond-between($min-width, $max-width)

Mixin that applies a media-query to a certain element. This media query can either be placed inside a selector or can wrap around one or multiple selectors. This mixin applies styling to the selector when the viewport is between the passed widths.

Parameters:

  • min-width: the minimum width, when below this width, the styling is not applied.
  • max-width: the maximum width, when above this width, the styling is not applied.

These parameters can both either be:

* A number in pixels.
* A number in rem. This value is converted automagically to pixels.
* A string, which is the name of the breakpoint defined in
$lmr-sass-breakpoints. This must have a width key. This key can either be
in pixels or in rem.
// =============================================================================
// Configuration
// =============================================================================
$lmr-sass-breakpoints: (
	viewport-7: (
		width: 72rem
	),
	viewport-9: (
		width: 96rem
	)
);

// =============================================================================
// Inside selector
// =============================================================================
div {

	// Number in pixels
	// -------------------------------------------------------------------------
	@include respond-between(720px, 960px) {
		margin: 3rem;
	}

	// Number is rem
	// -------------------------------------------------------------------------
	@include respond-between(72rem, 96rem) {
		margin: 3rem;
	}

	// Name of the breakpoint
	// -------------------------------------------------------------------------
	@include respond-between("viewport-7", "viewport-9") {
		margin: 3rem;
	}

	// Combined
	// -------------------------------------------------------------------------
	@include respond-between(720px, 96rem) {
		margin: 3rem;
	}

	@include respond-between("viewport-7", 960px) {
		margin: 3rem;
	}

	@include respond-between(72rem, "viewport-9") {
		margin: 3rem;
	}
}

// =============================================================================
// Around selector
// =============================================================================

// Number in pixels
// -----------------------------------------------------------------------------
@include respond-between(720px, 960px) {

	div {
		margin: 3rem;
	}
}

// Number is rem
// -----------------------------------------------------------------------------
@include respond-between(72rem, 96rem) {

	div {
		margin: 3rem;
	}
}

// Name of the breakpoint
// -----------------------------------------------------------------------------
@include respond-between("viewport-7", "viewport-9") {

	div {
		margin: 3rem;
	}
}

// Combined
// -----------------------------------------------------------------------------
@include respond-between(720px, 96rem) {

	div {
		margin: 3rem;
	}
}

@include respond-between("viewport-7", 960px) {

	div {
		margin: 3rem;
	}
}

@include respond-between(72rem, "viewport-9") {

	div {
		margin: 3rem;
	}
}

Functions

get-width($name)

Function that returns the value of the width key defined within the a breakpoint in the $lmr-sass-breakpoints map. These can be used to retrieve the value and make a calculation or can be used with other media queries.

Parameters:

  • $name: the name of the breakpoint in the $lmr-sass-breakpoints map.
// =============================================================================
// Configuration
// =============================================================================
$lmr-sass-breakpoints: (
	viewport-7: (
		width: 72rem
	),
	viewport-9: (
		width: 960px
	)
);

// =============================================================================
// Function
// =============================================================================

// Returns 72rem
get-width("viewport-7");

// Returns 960px
get-width("viewport-9");

// =============================================================================
// With media queries
// =============================================================================
div {

	// same as respond-at("viewport-9")
	@include respond-at(get-width("viewport-9")) {
		margin: 3rem;
	}

	// same as respond-to("viewport-7")
	@include respond-to(get-width("viewport-7")) {
		margin: 3rem;
	}

	// same as respond-between("viewport-7", "viewport-9")
	@include respond-between(get-width("viewport-7"), get-width("viewport-9")) {
		margin: 3rem;
	}
}

Keywords

FAQs

Package last updated on 04 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc