Skip to content

Instantly share code, notes, and snippets.

@certainlyakey
Last active June 11, 2019 11:11
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 certainlyakey/6e8e3a9a8e0d65fd9784a472093ff811 to your computer and use it in GitHub Desktop.
Save certainlyakey/6e8e3a9a8e0d65fd9784a472093ff811 to your computer and use it in GitHub Desktop.
A mixin that applies colors from a map
$colors-by-name: (
dove-gray: #666666,
mine-shaft: #333333,
denim: #0f6bac,
niagara: #0fb3ac,
// ...
);
$colors-by-function: (
buttons: (
primary-button: (
background-color: map-get($colors-by-name, dove-gray),
border-color: map-get($colors-by-name, denim),
hover: (
background-color: map-get($colors-by-name, mine-shaft),
border-color: map-get($colors-by-name, niagara),
)
),
secondary-button: (
// ...
)
)
);
// A mixin for applying colors from a map
// Usage: u-generate-color-style('buttons', 'primary-button');
@mixin u-generate-color-style($group-name, $style-name, $colors: $colors-by-function) {
$group: map-get($colors, $group-name);
$properties: map-get($group, $style-name);
@each $property, $value in $properties {
@if type-of($value) == 'map' {
$subproperties: $value;
@if $property == 'hover' {
&:hover, &:focus {
@each $subproperty, $subvalue in $subproperties {
#{$subproperty}: $subvalue;
}
}
}
} @else {
#{$property}: $value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment