UNPKG

2.27 kBSCSSView Raw
1// ** Two main functions for users **
2// md-palette: used for defining your theme in terms of Material hues.
3// md-color: apply colors to components from the palette. Consumes the output of md-palette
4
5// Implement the rem unit with SCSS so we don't have to actually set a font-size on
6// the user's body element.
7@function rem($multiplier) {
8 $font-size: 10px;
9 @return $multiplier * $font-size;
10}
11
12// For a given hue in a palette, return the contrast color from the map of contrast palettes.
13@function md-contrast($color-map, $hue, $contrast-color-map) {
14 @return map-get(map-get($contrast-color-map, $color-map), $hue);
15}
16
17
18// Creates a map of hues to colors for a theme.
19// $color-map
20// $primary
21// $lighter
22// $darker
23@function md-palette($color-map, $primary, $lighter, $darker, $contrast-color-map) {
24 $result: map_merge($color-map, (
25 default: map-get($color-map, $primary),
26 lighter: map-get($color-map, $lighter),
27 darker: map-get($color-map, $darker),
28
29 default-contrast: md-contrast($color-map, $primary, $contrast-color-map),
30 lighter-contrast: md-contrast($color-map, $lighter, $contrast-color-map),
31 darker-contrast: md-contrast($color-map, $darker, $contrast-color-map)
32 ));
33
34 // For each hue in the palette, add a "-contrast" color to the map.
35 @each $hue, $color in $color-map {
36 $result: map_merge($result, (
37 '#{$hue}-contrast': md-contrast($color-map, $hue, $contrast-color-map)
38 ));
39 }
40
41 @return $result;
42}
43
44// Gets a color for a material design component.
45// $color-map: a map of {key: color}.
46// $hue-key: key used to lookup the color in $colorMap. Defaults to 'default'
47// If $hue-key is a number between 0 and 1, it will be treated as $opacity.
48// $opacity: the opacity to apply to the color.
49@function md-color($color-map, $hue-key: default, $opacity: 1) {
50 // If hueKey is a number between zero and one, then it actually contains an
51 // opacity value, so recall this function with the default hue and that given opacity.
52 @if type-of($hue-key) == number and $hue-key >= 0 and $hue-key <= 1 {
53 @return md-color($color-map, default, $hue-key);
54 }
55
56 $color: map-get($color-map, $hue-key);
57 $opacity: if(opacity($color) < 1, opacity($color), $opacity);
58
59 @return rgba($color, $opacity);
60}
61
62