Skip to content

Instantly share code, notes, and snippets.

@Undistraction
Created September 25, 2014 17:12
Show Gist options
  • Save Undistraction/06c06d5f4db56af96481 to your computer and use it in GitHub Desktop.
Save Undistraction/06c06d5f4db56af96481 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.4)
// Compass (v1.0.1)
// Sassy Maps (v0.4.0)
// ----
@import "sassy-maps";
//
// Functionality missing from Sass and Sassy Maps
//
// Note: I have a PR open adding this to Sassy maps
// -------------------------------------------------------------------------------------------------
// Perform a deep merge of two maps, optionally overwriting existing values
@function map-merge-deep($map-old, $map-new, $overwrite: true) {
// Iterate through each value of the new map
@each $key, $new-value in $map-new {
// Check if that value already exists on the old map
@if map-has-key($map-old, $key) {
// There is an existing key
$old-value: map-get($map-old, $key);
@if type-of($new-value) == map and type-of($old-value) == map {
// If both are maps, recurse regardless of $overwrite
$merged-value: map-merge-deep($old-value, $new-value, $overwrite);
$map-old: map-set($map-old, $key, $merged-value);
}@else{
// Otherwise check $overwrite
@if $overwrite{
$map-old: map-set($map-old, $key, $new-value);
}
}
}@else{
// There is no existing key so add
$map-old: map-set($map-old, $key, $new-value);
}
}
@return $map-old;
}
$palette-map: ();
// Look up a color value in the palette map
@function c($palette-path...) {
@return map-get-deep($palette-map, $palette-path);
}
// Register a palette to make it available using the c() function
// If no name is given, the values in $palette are added to $palette map's top level
@function register-palette($name:null, $palette:null, $overwrite:true) {
// Merge, overriding existing values
@if $name {
$palette-map: map-merge-deep($palette-map, ($name: $palette), $overwrite) !global;
}@else{
$palette-map: map-merge-deep($palette-map, $palette, $overwrite) !global;
}
@return none;
}
// Because sass doesn't support function invocation at a root level it has to be done from within a mixin
@mixin register-palette($name:null, $palette:null, $overwrite: true){
$temp: register-palette($name, $palette, $overwrite);
}
@include register-palette(default,
(
default:
(
background-color: white,
text-color: black,
text-color-quiet: lighten(black, 15),
title-color: black,
divider-color: darken(white, 2)
)
)
);
@include register-palette(default,
(
default:
(
background-color: red
)
),
false
);
.Button {
background-color: c(default, default, background-color);
color: c(default, default, text-color);
&-icon {
color: c(default, default, text-color-quiet);
}
}
.Button {
background-color: white;
color: black;
}
.Button-icon {
color: #262626;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment