bootstrap-4-grid-styl
Version:
Bootstrap 4 grid system and layout utilities using Stylus
110 lines (101 loc) • 4.13 kB
text/stylus
// Breakpoint viewport sizes and media queries.
//
// Breakpoints are defined as a map of (name: minimum width), order from small to large:
//
// (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)
//
// The map defined in the `$grid-breakpoints` global variable is used as the `$breakpoints` argument by default.
// Name of the next breakpoint, or null for the last breakpoint.
//
// >> breakpoint-next(sm)
// md
// >> breakpoint-next(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
// md
// >> breakpoint-next(sm, $breakpoint-names: (xs sm md lg xl))
// md
breakpoint-next($name, $breakpoints = $grid-breakpoints, $breakpoint-names = keys($breakpoints))
$n = index($breakpoint-names, $name)
if $n < length($breakpoint-names)
$breakpoint-names[$n + 1]
else
null
// Minimum breakpoint width. Null for the smallest (first) breakpoint.
//
// >> breakpoint-min(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
// 576px
breakpoint-min($name, $breakpoints = $grid-breakpoints)
$min = $breakpoints[$name]
if $min != 0
$min
else
null
// Maximum breakpoint width. Null for the largest (last) breakpoint.
// The maximum value is calculated as the minimum of the next one less 0.02px
// to work around the limitations of `min-` and `max-` prefixes and viewports with fractional widths.
// See https://www.w3.org/TR/mediaqueries-4/#mq-min-max
// Uses 0.02px rather than 0.01px to work around a current rounding bug in Safari.
// See https://bugs.webkit.org/show_bug.cgi?id=178261
//
// >> breakpoint-max(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
// 767.98px
breakpoint-max($name, $breakpoints = $grid-breakpoints)
$next = breakpoint-next($name, $breakpoints)
if $next
breakpoint-min($next, $breakpoints) - .02px
else
null
// Returns a blank string if smallest breakpoint, otherwise returns the name with a dash in front.
// Useful for making responsive utilities.
//
// >> breakpoint-infix(xs, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
// "" (Returns a blank string)
// >> breakpoint-infix(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
// "-sm"
breakpoint-infix($name, $breakpoints = $grid-breakpoints)
if breakpoint-min($name, $breakpoints) == null
""
else
"-"+$name
// Media of at least the minimum breakpoint width. No query for the smallest breakpoint.
// Makes the @content apply to the given breakpoint and wider.
media-breakpoint-up($name, $breakpoints = $grid-breakpoints)
$min = breakpoint-min($name, $breakpoints)
if $min
(min-width: $min)
{block}
else
{block}
// Media of at most the maximum breakpoint width. No query for the largest breakpoint.
// Makes the @content apply to the given breakpoint and narrower.
media-breakpoint-down($name, $breakpoints = $grid-breakpoints)
$max = breakpoint-max($name, $breakpoints)
if $max
(max-width: $max)
{block}
else
{block}
// Media that spans multiple breakpoint widths.
// Makes the @content apply between the min and max breakpoints
media-breakpoint-between($lower, $upper, $breakpoints = $grid-breakpoints)
$min = breakpoint-min($lower, $breakpoints)
$max = breakpoint-max($upper, $breakpoints)
if $min != null and $max != null
(min-width: $min) and (max-width: $max)
{block}
else if $max == null
media-breakpoint-up($lower, $breakpoints)
else if $min == null
media-breakpoint-down($upper, $breakpoints)
// Media between the breakpoint's minimum and maximum widths.
// No minimum for the smallest breakpoint, and no maximum for the largest one.
// Makes the @content apply only to the given breakpoint, not viewports any wider or narrower.
media-breakpoint-only($name, $breakpoints = $grid-breakpoints)
$min = breakpoint-min($name, $breakpoints)
$max = breakpoint-max($name, $breakpoints)
if $min != null and $max != null
(min-width: $min) and (max-width: $max)
{block}
else if $max == null
media-breakpoint-up($name, $breakpoints)
else if $min == null
media-breakpoint-down($name, $breakpoints)