_utilities.scss 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Utility generator
  2. // Used to generate utilities & print utilities
  3. @mixin generate-utility($utility, $infix, $is-rfs-media-query: false) {
  4. $values: map-get($utility, values);
  5. // If the values are a list or string, convert it into a map
  6. @if type-of($values) == "string" or type-of(nth($values, 1)) != "list" {
  7. $values: zip($values, $values);
  8. }
  9. @each $key, $value in $values {
  10. $properties: map-get($utility, property);
  11. // Multiple properties are possible, for example with vertical or horizontal margins or paddings
  12. @if type-of($properties) == "string" {
  13. $properties: append((), $properties);
  14. }
  15. // Use custom class if present
  16. $property-class: if(map-has-key($utility, class), map-get($utility, class), nth($properties, 1));
  17. $property-class: if($property-class == null, "", $property-class);
  18. // State params to generate pseudo-classes
  19. $state: if(map-has-key($utility, state), map-get($utility, state), ());
  20. $infix: if($property-class == "" and str-slice($infix, 1, 1) == "-", str-slice($infix, 2), $infix);
  21. // Don't prefix if value key is null (eg. with shadow class)
  22. $property-class-modifier: if($key, if($property-class == "" and $infix == "", "", "-") + $key, "");
  23. @if map-get($utility, rfs) {
  24. // Inside the media query
  25. @if $is-rfs-media-query {
  26. $val: rfs-value($value);
  27. // Do not render anything if fluid and non fluid values are the same
  28. $value: if($val == rfs-fluid-value($value), null, $val);
  29. }
  30. @else {
  31. $value: rfs-fluid-value($value);
  32. }
  33. }
  34. $is-rtl: map-get($utility, rtl);
  35. @if $value != null {
  36. @if $is-rtl == false {
  37. /* rtl:begin:remove */
  38. }
  39. .#{$property-class + $infix + $property-class-modifier} {
  40. @each $property in $properties {
  41. #{$property}: $value if($enable-important-utilities, !important, null);
  42. }
  43. }
  44. @each $pseudo in $state {
  45. .#{$property-class + $infix + $property-class-modifier}-#{$pseudo}:#{$pseudo} {
  46. @each $property in $properties {
  47. #{$property}: $value if($enable-important-utilities, !important, null);
  48. }
  49. }
  50. }
  51. @if $is-rtl == false {
  52. /* rtl:end:remove */
  53. }
  54. }
  55. }
  56. }