Skip to content

Commit

Permalink
Merge pull request #37 from larrybotha/fix/incorrect-wrap-width-order
Browse files Browse the repository at this point in the history
  • Loading branch information
larrybotha authored Apr 18, 2022
2 parents abaee50 + fe351f9 commit eedc35a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
26 changes: 15 additions & 11 deletions scss/custom/app/components/_wraps.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*------------------------------------*\
WRAPS
\*------------------------------------*/
@use "sass:map";
/**
* Generates classes for wraps defined in mixins/components/layout/_wraps.scss
* e.g.
Expand All @@ -9,16 +10,19 @@
.wrap { ... }
.wrap--small { ... }
*/
@each $wrap-name, $wrap-width in $wrap-widths {
@if $wrap-name == 'base' {
.wrap {
@include wrap-width($wrap-name);
@include wrap-base;
}
} @else {
.wrap--#{$wrap-name} {
@include wrap-width($wrap-name);
@include wrap-base;
}

@each $config in $wrap-base-configs {
.wrap {
@include wrap-base;
max-width: map-get($config, 'width');
}
}

@each $config in $wrap-modifier-configs {
$name: map-get($config, 'name');
$width: map-get($config, 'width');

.wrap--#{$name} {
max-width: $width;
}
}
40 changes: 21 additions & 19 deletions scss/custom/tools/mixins/components/_wraps.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
/*------------------------------------*\
WRAP MIXINS
\*------------------------------------*/
$wrap-widths: (
large: 1200px,
base: 960px,
small: 720px,
@use "sass:map";

$wrap-configs: (
("name": large, "width": 1200px, "type": modifier),
("name": base, "width": 960px, "type": base),
("name": small, "width": 720px, "type": modifier),
);

$wrap-base-configs: ();
$wrap-modifier-configs: ();

@each $config in $wrap-configs {
@if map-get($config, "type") == "base" {
$wrap-base-configs: append($wrap-base-configs, $config);
}
}

@each $config in $wrap-configs {
@if map-get($config, "type") == "modifier" {
$wrap-modifier-configs: append($wrap-modifier-configs, $config);
}
}

@mixin wrap-margin {
margin-inline-end: auto;
margin-inline-start: auto;
Expand All @@ -23,18 +40,3 @@ $wrap-widths: (
@include wrap-margin;
@include wrap-padding;
}

@mixin wrap-width($name){
$has-key: map-has-key($wrap-widths, $name);

@if $has-key == true {
max-width: map-get($wrap-widths, $name);
} @else {
@error "no key #{$name} in #{$wrap-widths}";
}
}

@mixin wrap($name) {
@include wrap-base;
@include wrap-width($name);
}

0 comments on commit eedc35a

Please sign in to comment.