Last active
August 14, 2020 15:40
-
-
Save nathansmith/cb147a94a2638dd0d9e8755f8ef6c48f to your computer and use it in GitHub Desktop.
How to create Sass feature flags
This file contains 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
@function rkv-map-merge($maps...) { | |
$collection: (); | |
@each $map in $maps { | |
$collection: map-merge($collection, $map); | |
} | |
@return $collection; | |
} |
This file contains 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
// ==================== | |
// Default placeholder. | |
// ==================== | |
/* | |
This is empty by default, but the intent | |
is that it would be overwritten by another | |
variable for a custom site implementation. | |
*/ | |
// prettier-ignore | |
$-rkv-custom-feature-map: ( | |
// Leave this blank! | |
) !default; | |
// =============================== | |
// Features. Private to this file. | |
// =============================== | |
// prettier-ignore | |
$-rkv-default-feature-map: ( | |
charts: true, | |
extras: true, | |
gravity-forms: true, | |
grid: true, | |
storybook: true, | |
syntax: true, | |
wordpress: true, | |
) !default; | |
// =================== | |
// Merge feature maps. | |
// =================== | |
// prettier-ignore | |
$-rkv-merged-feature-map: rkv-map-merge( | |
$-rkv-default-feature-map, | |
$-rkv-custom-feature-map | |
) !default; |
This file contains 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
@mixin rkv-feature-flag($flag: '') { | |
@if map-get($-rkv-merged-feature-map, $flag) == true { | |
@content; | |
} | |
} |
This file contains 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
@include rkv-feature-flag($flag: gravity-forms) { | |
@import './gravity-forms'; | |
} | |
@include rkv-feature-flag($flag: storybook) { | |
@import './storybook'; | |
} | |
@include rkv-feature-flag($flag: wordpress) { | |
@import './wordpress'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment