Last active
November 4, 2021 11:56
-
-
Save benjclark/95bc3addbf11db9d5259de1572d72f9a to your computer and use it in GitHub Desktop.
global meta issue with spacing function and dart sass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $context--spacing: (0, 2, 4, 8, 16, 24, 32, 48, 64); | |
| $context--keyline-border-color: #ccc; | |
| @function spacing($keys...) { | |
| @if length($context--spacing) == 0 { | |
| @error 'No values found in $context--spacing.'; | |
| } | |
| @if length($keys) > 4 { | |
| @error 'spacing() accepts a maximum of 4 arguments.'; | |
| } | |
| $context--spacing-value: (); | |
| @each $key in $keys { | |
| @if index($context--spacing, $key) { | |
| $i: index($context--spacing, $key); | |
| $context--spacing-value: append($context--spacing-value, nth($context--spacing, $i) * 1px); // Add current item in loop to $context--spacing-value list | |
| } | |
| @else { | |
| @error '#{$key} is not defined in $context--spacing. Permitted values are #{$context--spacing}.'; | |
| } | |
| } | |
| // If the length is 1, don't return type 'list' | |
| // This allows maths operations to be done on a single value. E.g. spacing(12) * 2. | |
| @if length($context--spacing-value == 1) { | |
| @return nth($context--spacing-value, 1); | |
| } | |
| @else { | |
| @return $context--spacing-value; | |
| } | |
| } | |
| @mixin u-keyline($direction: bottom, $spacing: $context--keyline-spacing, $thickness: 1px) { | |
| $valid-directions: (top, right, bottom, left); | |
| @if index($valid-directions, $direction) { | |
| border-#{$direction}: $thickness solid $context--keyline-border-color; | |
| padding-#{$direction}: spacing($spacing); | |
| margin-#{$direction}: spacing($spacing); | |
| } | |
| @else { | |
| @warn '$direction should be one of #{$valid-directions}, but was #{$direction}'; | |
| } | |
| } | |
| $meta--keyline-spacing: spacing(8); | |
| .c-meta__item { | |
| @include u-keyline('right', $meta--keyline-spacing); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment