Last active
June 9, 2017 16:33
-
-
Save alexgetty/c739b8a982b7e6517ccc63f114f72c3f to your computer and use it in GitHub Desktop.
A technique for organizing colors using Sass maps and a getter function
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
// Color Definition | |
$colors: ( | |
primary: ( | |
light: #67A1E9, | |
base: #428CE8, | |
dark: #3478CD | |
), | |
status: ( | |
success: #50E39A, | |
inactive: #B7BCC5, | |
warning: #F8C71C, | |
error: #FF388E, | |
disabled: #B7BCC5 | |
), | |
neutral: ( | |
lightest: #FFFFFF, | |
lighter: #F8FAFE, | |
light: #E7EAF1, | |
base: #B7BCC5, | |
dark: #494C50, | |
darker: #1E2124, | |
darkest: #000000 | |
) | |
); | |
// Getter Functions | |
@function color($palette: primary, $shade: base) { | |
@return map-get(map-get($colors, $palette), $shade); | |
} | |
@function color-rgba($alpha, $palette: primary, $shade: base) { | |
@return rgba(map-get(map-get($colors, $palette), $shade), $alpha); | |
} | |
// Usage Examples | |
h1 { | |
color: color(neutral, darker); | |
} | |
button { | |
background-color: getColor(primary); | |
} | |
.card { | |
border: 1px solid getColor(neutral); | |
} | |
.error { | |
color: color(status, error); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this, I am now using a very similar implementation.
You could use a function here so avoid the double map get:
and you would call it like this: