1
0
Fork 0
mirror of https://github.com/twbs/bootstrap.git synced 2022-11-09 12:25:43 -05:00
twbs--bootstrap/scss/mixins/_utilities.scss

69 lines
2.2 KiB
SCSS
Raw Normal View History

2019-05-23 05:56:03 -04:00
// Utility generator
// Used to generate utilities & print utilities
2020-02-15 06:01:32 -05:00
@mixin generate-utility($utility, $infix, $is-rfs-media-query: false) {
2019-05-23 05:56:03 -04:00
$values: map-get($utility, values);
// If the values are a list or string, convert it into a map
@if type-of($values) == "string" or type-of(nth($values, 1)) != "list" {
$values: zip($values, $values);
}
@each $key, $value in $values {
2019-05-23 05:56:03 -04:00
$properties: map-get($utility, property);
// Multiple properties are possible, for example with vertical or horizontal margins or paddings
@if type-of($properties) == "string" {
$properties: append((), $properties);
}
// Use custom class if present
$property-class: if(map-has-key($utility, class), map-get($utility, class), nth($properties, 1));
$property-class: if($property-class == null, "", $property-class);
// State params to generate pseudo-classes
$state: if(map-has-key($utility, state), map-get($utility, state), ());
$infix: if($property-class == "" and str-slice($infix, 1, 1) == "-", str-slice($infix, 2), $infix);
2019-05-23 05:56:03 -04:00
// Don't prefix if value key is null (eg. with shadow class)
$property-class-modifier: if($key, if($property-class == "" and $infix == "", "", "-") + $key, "");
2019-05-23 05:56:03 -04:00
2020-02-15 06:01:32 -05:00
@if map-get($utility, rfs) {
// Inside the media query
@if $is-rfs-media-query {
$val: rfs-value($value);
// Do not render anything if fluid and non fluid values are the same
$value: if($val == rfs-fluid-value($value), null, $val);
}
@else {
$value: rfs-fluid-value($value);
}
}
$is-rtl: map-get($utility, rtl);
2020-02-15 06:01:32 -05:00
@if $value != null {
@if $is-rtl == false {
/* rtl:begin:remove */
}
2020-02-15 06:01:32 -05:00
.#{$property-class + $infix + $property-class-modifier} {
@each $property in $properties {
#{$property}: $value if($enable-important-utilities, !important, null);
}
2019-05-23 05:56:03 -04:00
}
@each $pseudo in $state {
.#{$property-class + $infix + $property-class-modifier}-#{$pseudo}:#{$pseudo} {
@each $property in $properties {
#{$property}: $value if($enable-important-utilities, !important, null);
}
}
}
@if $is-rtl == false {
/* rtl:end:remove */
}
2019-05-23 05:56:03 -04:00
}
}
}