Skip to content

Instantly share code, notes, and snippets.

@AdamStuartClark
Created August 15, 2017 09:28
Show Gist options
  • Save AdamStuartClark/274588535145efb69c8f82d34fb79260 to your computer and use it in GitHub Desktop.
Save AdamStuartClark/274588535145efb69c8f82d34fb79260 to your computer and use it in GitHub Desktop.
Using a function to call named colour tone variations from a sass map
// MAP: Colour names map (palette) with tone-baed sub-names (light, dark, base, etc)
$palettes: (
blue: (
base: hsla(220, 100%, 20%, 1),
light: hsla(220, 50%, 50%, 1),
dark: hsla(220, 50%, 10%, 1)
),
gold: (
base: hsla(45, 100%, 70%, 1),
light: hsla(45, 100%, 90%, 1),
dark: hsla(45, 100%, 10%, 1)
)
);
// FUNCTION
@function palette($palette, $tone: 'base') {
@return map-get(map-get($palettes, $palette), $tone);
}
// USAGE
a {
text-decoration: underline;
color: palette(blue);
&:hover {
text-decoration: none;
color: palette(blue, light);
}
&:active {
text-decoration: underline;
color: palette(blue, dark);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment