_utilities.responsive-spacings.scss 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* ==========================================================================
  2. #RESPONSIVE-SPACINGS
  3. ========================================================================== */
  4. /**
  5. * Utility classes enhancing the normal spacing classes by adding responsiveness
  6. * to them. By default, there are not responsive spacings defined. You can
  7. * generate responsive spacings by adding entries to the following three Sass
  8. * maps, e.g.:
  9. *
  10. * $inuit-responsive-spacing-directions: (
  11. * null: null,
  12. * bottom: bottom,
  13. * );
  14. *
  15. * $inuit-responsive-spacing-properties: (
  16. * "margin": "margin",
  17. * );
  18. *
  19. * $inuit-responsive-spacing-sizes: (
  20. * "-small": $inuit-global-spacing-unit-small,
  21. * );
  22. *
  23. * This would bring us the following classes:
  24. *
  25. * .u-margin-small@mobile {}
  26. * .u-margin-small@tablet {}
  27. * .u-margin-small@desktop {}
  28. * .u-margin-small@wide {}
  29. * .u-margin-bottom-small@mobile {}
  30. * .u-margin-bottom-small@tablet {}
  31. * .u-margin-bottom-small@desktop {}
  32. * .u-margin-bottom-small@wide {}
  33. *
  34. * You can change the generated CSS classes by further extending the Sass maps.
  35. * If you want every ‘normal’ spacing (those from `utilities.spacings`) also as
  36. * a responsive version, you can just mirror the ‘normal’ spacings:
  37. *
  38. * $inuit-responsive-spacing-directions: $inuit-spacing-directions !default;
  39. *
  40. * $inuit-responsive-spacing-properties: $inuit-spacing-properties !default;
  41. *
  42. * $inuit-responsive-spacing-sizes: $inuit-spacing-sizes !default;
  43. *
  44. * BUT BE AWARE: This can generate a huge chunk of extra CSS, depending on the
  45. * amount of breakpoints you defined. So please check your CSS’ output and
  46. * filesize!
  47. */
  48. // The responsive spacings just make sense and work properly when the ‘normal’
  49. // spacings are included, too. In case they're not, we set `_utilities.spacings`
  50. // to `null`.
  51. $inuit-spacing-directions: null !default;
  52. // If the ‘normal’ spacings partial is not included, we provide an error message
  53. // to indicate this.
  54. @if $inuit-spacing-directions == null {
  55. @error "In order to use responsive spacings, you also need to include `_utilities.spacings.scss`!";
  56. }
  57. @else {
  58. // When using Sass-MQ, this defines the separator for the breakpoints suffix
  59. // in the class name. By default, we are generating the responsive suffixes
  60. // for the classes with a `@` symbol so you get classes like:
  61. //
  62. // <div class="u-margin-bottom@mobile">
  63. //
  64. // Be aware that since the `@` symbol is a reserved symbol in CSS, it has to be
  65. // escaped with a `\`. In the markup though, you write your classes without the
  66. // backslash (e.g. `u-margin-bottom@mobile`).
  67. $inuit-widths-breakpoint-separator: \@ !default;
  68. $inuit-responsive-spacing-directions: null !default;
  69. $inuit-responsive-spacing-properties: null !default;
  70. $inuit-responsive-spacing-sizes: null !default;
  71. /* stylelint-disable max-nesting-depth */
  72. // Don't output anything if no responsive spacings are defined.
  73. @if ($inuit-responsive-spacing-properties != null) {
  74. @each $property-namespace, $property in $inuit-responsive-spacing-properties {
  75. @each $direction-namespace, $direction-rules in $inuit-responsive-spacing-directions {
  76. @each $size-namespace, $size in $inuit-responsive-spacing-sizes {
  77. @each $inuit-bp-name, $inuit-bp-value in $mq-breakpoints {
  78. @include mq($from: $inuit-bp-name) {
  79. .u-#{$property-namespace}#{$direction-namespace}#{$size-namespace}#{$inuit-widths-breakpoint-separator}#{$inuit-bp-name} {
  80. @each $direction in $direction-rules {
  81. #{$property}#{$direction}: $size !important;
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }
  90. /* stylelint-enable max-nesting-depth */
  91. }