Created
June 23, 2022 14:27
-
-
Save norin89/db88efce02cbc7e347cc406948bc7de3 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
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
@use "sass:map"; | |
// Sass map, ideally imported from JSON (e.g. with https://github.com/pmowrer/node-sass-json-importer) | |
// Based on MUI palette example - https://mui.com/material-ui/customization/color/#picking-colors | |
$palette: ( | |
primary: ( | |
light: '#757ce8', | |
main: '#3f50b5', | |
dark: '#002884', | |
contrastText: '#fff', | |
), | |
secondary: ( | |
light: '#ff7961', | |
main: '#f44336', | |
dark: '#ba000d', | |
contrastText: '#000', | |
) | |
); | |
@function color-var($name, $variant, $wrap: true) { | |
$prop: --#{$name}-#{$variant}; | |
@if map.has-key($palette, $name, $variant) { | |
@if ($wrap) { | |
@return var($prop); | |
} | |
@return $prop; | |
} | |
// @warn "Color '#{$name}' or it's variant '#{$variant}' not found!"; | |
@return "Color '#{$name}' or it's variant '#{$variant}' not found!"; | |
} | |
:root { | |
@each $name, $variants in $palette { | |
@each $variant, $color in $variants { | |
#{color-var($name, $variant, false)}: #{$color}; | |
} | |
} | |
} | |
body { | |
background: color-var(primary, dark); | |
color: color-var(primary, contrastText); | |
border: color-var(primary, nonExisting); | |
} |
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
:root { | |
--primary-light: #757ce8; | |
--primary-main: #3f50b5; | |
--primary-dark: #002884; | |
--primary-contrastText: #fff; | |
--secondary-light: #ff7961; | |
--secondary-main: #f44336; | |
--secondary-dark: #ba000d; | |
--secondary-contrastText: #000; | |
} | |
body { | |
background: var(--primary-dark); | |
color: var(--primary-contrastText); | |
border: "Color 'primary' or it's variant 'nonExisting' not found!"; | |
} |
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
{ | |
"sass": { | |
"compiler": "dart-sass/1.32.12", | |
"extensions": {}, | |
"syntax": "SCSS", | |
"outputStyle": "expanded" | |
}, | |
"autoprefixer": false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment