_utilities.sass 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. @use 'sass:list'
  2. @use 'sass:map'
  3. @use 'sass:meta'
  4. =generate-utility($utility, $infix, $forceDir)
  5. $values: map.get($utility, values)
  6. // If the values are a list or string, convert it into a map
  7. @if meta.type-of($values) == "string" or meta.type-of(list.nth($values, 1)) != "list"
  8. $values: list.zip($values, $values)
  9. @each $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 meta.type-of($properties) == 'string'
  13. $properties: list.append((), $properties)
  14. // Property can be a map, where the key is a mixin to include
  15. @if meta.type-of($properties) == 'map'
  16. @each $dir in $properties
  17. $mixin: list.nth($dir, 1)
  18. // SASS doesn't support dynamic mixin invocation
  19. // https://github.com/sass/sass/issues/626
  20. @if $mixin == 'ltr'
  21. .v-locale--is-ltr
  22. +generate-utility-body($utility, list.nth($dir, 2), $value, $infix)
  23. @else if $mixin == 'rtl'
  24. .v-locale--is-rtl
  25. +generate-utility-body($utility, list.nth($dir, 2), $value, $infix)
  26. @else
  27. @error 'Only RTL and LTR are supported'
  28. @else
  29. @if $forceDir == 'ltr'
  30. .v-locale--is-ltr
  31. +generate-utility-body($utility, $properties, $value, $infix)
  32. @else if $forceDir == 'rtl'
  33. .v-locale--is-rtl
  34. +generate-utility-body($utility, $properties, $value, $infix)
  35. @else
  36. +generate-utility-body($utility, $properties, $value, $infix)
  37. =generate-utility-body($utility, $properties, $value, $infix)
  38. // Use custom class if present
  39. $property-class: map.get($utility, class)
  40. $property-class: if($property-class, $property-class, list.nth($properties, 1))
  41. // Don't prefix if value key is null (eg. with shadow class)
  42. $property-class-modifier: if(list.nth($value, 1), "-" + list.nth($value, 1), "")
  43. $value: list.nth($value, 2)
  44. .#{$property-class + $infix + $property-class-modifier}
  45. @for $i from 1 through list.length($properties)
  46. $property: list.nth($properties, $i)
  47. $val: $value
  48. @if meta.type-of($value) == 'list' and list.length($properties) == list.length($value)
  49. $val: list.nth($value, $i)
  50. @if $val != false
  51. // Check if unimportant property exists.
  52. // This allows you to conditional skip
  53. // defining a property as important.
  54. $unimportant: map.get($utility, unimportant)
  55. #{$property}: #{meta.inspect($val) if(list.index($unimportant, $property), null, !important)}