Skip to content

Instantly share code, notes, and snippets.

@nathansmith
Last active August 14, 2020 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathansmith/cb147a94a2638dd0d9e8755f8ef6c48f to your computer and use it in GitHub Desktop.
Save nathansmith/cb147a94a2638dd0d9e8755f8ef6c48f to your computer and use it in GitHub Desktop.
How to create Sass feature flags
@function rkv-map-merge($maps...) {
$collection: ();
@each $map in $maps {
$collection: map-merge($collection, $map);
}
@return $collection;
}
// ====================
// 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;
@mixin rkv-feature-flag($flag: '') {
@if map-get($-rkv-merged-feature-map, $flag) == true {
@content;
}
}
@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