You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.9 KiB

  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-css-var: map-get($utility, css-var);
  35. $is-local-vars: map-get($utility, local-vars);
  36. $is-rtl: map-get($utility, rtl);
  37. @if $value != null {
  38. @if $is-rtl == false {
  39. /* rtl:begin:remove */
  40. }
  41. @if $is-css-var {
  42. .#{$property-class + $infix + $property-class-modifier} {
  43. --#{$variable-prefix}#{$property-class}: #{$value};
  44. }
  45. @each $pseudo in $state {
  46. .#{$property-class + $infix + $property-class-modifier}-#{$pseudo}:#{$pseudo} {
  47. --#{$variable-prefix}#{$property-class}: #{$value};
  48. }
  49. }
  50. } @else {
  51. .#{$property-class + $infix + $property-class-modifier} {
  52. @each $property in $properties {
  53. @if $is-local-vars {
  54. @each $local-var, $value in $is-local-vars {
  55. --#{$variable-prefix}#{$local-var}: #{$value};
  56. }
  57. }
  58. #{$property}: $value if($enable-important-utilities, !important, null);
  59. }
  60. }
  61. @each $pseudo in $state {
  62. .#{$property-class + $infix + $property-class-modifier}-#{$pseudo}:#{$pseudo} {
  63. @each $property in $properties {
  64. #{$property}: $value if($enable-important-utilities, !important, null);
  65. }
  66. }
  67. }
  68. }
  69. @if $is-rtl == false {
  70. /* rtl:end:remove */
  71. }
  72. }
  73. }
  74. }