Skip to content

Commit

Permalink
rewrite required fields check
Browse files Browse the repository at this point in the history
  • Loading branch information
Psixodelik authored and mdo committed Apr 12, 2022
1 parent 2ce0447 commit b162865
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions scss/_functions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ $_luminance-list: .0008 .001 .0011 .0013 .0015 .0017 .002 .0022 .0025 .0027 .003
@return $result;
}

@mixin validate-utilities-field($utility, $utility-name, $field) {
@mixin _validate-utilities-field($utility, $utility-name, $field) {
@if (not map-has-key($utility, $field)) {
@warn "Required field «#{$field}» is empty. Check the field name for the «#{$utility-name}» utility";
@warn "Missing '#{$field}' for '#{$utility-name}' utility";
}
}
19 changes: 10 additions & 9 deletions scss/mixins/_utilities.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Utility generator
// Used to generate utilities & print utilities
@mixin generate-utility($utility, $utility-name, $infix, $is-rfs-media-query: false) {
@mixin generate-utility($utility, $infix, $is-rfs-media-query: false, $utility-name: null) {
// Check Requires Fields

$required-fields: (
"property",
"values",
);

@each $field in $required-fields {
@include validate-utilities-field($utility, $utility-name, $field);
@if ($utility-name) {
$required-fields: (
"property",
"values",
);

@each $field in $required-fields {
@include _validate-utilities-field($utility, $utility-name, $field);
}
}

// End Check Requires Fields
Expand Down
6 changes: 3 additions & 3 deletions scss/utilities/_api.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// The utility can be disabled with `false`, thus check if the utility is a map first
// Only proceed if responsive media queries are enabled or if it's the base media query
@if type-of($utility) == "map" and (map-get($utility, responsive) or $infix == "") {
@include generate-utility($utility, $key, $infix);
@include generate-utility($utility, $infix, $utility-name: $key);
}
}
}
Expand All @@ -27,7 +27,7 @@
// The utility can be disabled with `false`, thus check if the utility is a map first
// Only proceed if responsive media queries are enabled or if it's the base media query
@if type-of($utility) == "map" and map-get($utility, rfs) and (map-get($utility, responsive) or $infix == "") {
@include generate-utility($utility, $key, $infix, true);
@include generate-utility($utility, $infix, true, $utility-name: $key);
}
}
}
Expand All @@ -41,7 +41,7 @@
// The utility can be disabled with `false`, thus check if the utility is a map first
// Then check if the utility needs print styles
@if type-of($utility) == "map" and map-get($utility, print) == true {
@include generate-utility($utility, $key, "-print");
@include generate-utility($utility, "-print", $utility-name: $key);
}
}
}

0 comments on commit b162865

Please sign in to comment.