_variables.scss 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // Copyright 2017 Google Inc.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. @use "sass:map";
  23. @use "sass:meta";
  24. @use "./functions";
  25. //
  26. // Main theme colors for your brand.
  27. //
  28. // If you're a user customizing your color scheme in SASS, these are probably the only variables you need to change.
  29. //
  30. $primary: #6200ee !default; // baseline purple, 500 tone
  31. $on-primary: if(functions.contrast-tone($primary) == "dark", #000, #fff) !default;
  32. // The $mdc-theme-accent variable is DEPRECATED - it exists purely for backward compatibility.
  33. // The $mdc-theme-secondary* variables should be used for all new projects.
  34. $accent: #018786 !default; // baseline teal, 600 tone
  35. $secondary: $accent !default;
  36. $on-secondary: if(functions.contrast-tone($secondary) == "dark", #000, #fff) !default;
  37. $background: #fff !default; // White
  38. $surface: #fff !default;
  39. $on-surface: if(functions.contrast-tone($surface) == "dark", #000, #fff) !default;
  40. $error: #b00020 !default;
  41. $on-error: if(functions.contrast-tone($error) == "dark", #000, #fff) !default;
  42. //
  43. // Text colors according to light vs dark and text type.
  44. //
  45. $text-colors: (
  46. dark: (
  47. primary: rgba(black, .87),
  48. secondary: rgba(black, .54),
  49. hint: rgba(black, .38),
  50. disabled: rgba(black, .38),
  51. icon: rgba(black, .38)
  52. ),
  53. light: (
  54. primary: white,
  55. secondary: rgba(white, .7),
  56. hint: rgba(white, .5),
  57. disabled: rgba(white, .5),
  58. icon: rgba(white, .5)
  59. )
  60. ) !default;
  61. $text-emphasis: (
  62. high: .87,
  63. medium: .6,
  64. disabled: .38,
  65. ) !default;
  66. @function ink-color-for-fill_($text-style, $fill-color) {
  67. $contrast-tone: functions.contrast-tone($fill-color);
  68. @return map.get(map.get($text-colors, $contrast-tone), $text-style);
  69. }
  70. //
  71. // Primary text colors for each of the theme colors.
  72. //
  73. $property-values: (
  74. // Primary
  75. primary: $primary,
  76. // Secondary
  77. secondary: $secondary,
  78. // Background
  79. background: $background,
  80. // Surface
  81. surface: $surface,
  82. // Error
  83. error: $error,
  84. on-primary: $on-primary,
  85. on-secondary: $on-secondary,
  86. on-surface: $on-surface,
  87. on-error: $on-error,
  88. // Text-primary on "background" background
  89. text-primary-on-background: ink-color-for-fill_(primary, $background),
  90. text-secondary-on-background: ink-color-for-fill_(secondary, $background),
  91. text-hint-on-background: ink-color-for-fill_(hint, $background),
  92. text-disabled-on-background: ink-color-for-fill_(disabled, $background),
  93. text-icon-on-background: ink-color-for-fill_(icon, $background),
  94. // Text-primary on "light" background
  95. text-primary-on-light: ink-color-for-fill_(primary, light),
  96. text-secondary-on-light: ink-color-for-fill_(secondary, light),
  97. text-hint-on-light: ink-color-for-fill_(hint, light),
  98. text-disabled-on-light: ink-color-for-fill_(disabled, light),
  99. text-icon-on-light: ink-color-for-fill_(icon, light),
  100. // Text-primary on "dark" background
  101. text-primary-on-dark: ink-color-for-fill_(primary, dark),
  102. text-secondary-on-dark: ink-color-for-fill_(secondary, dark),
  103. text-hint-on-dark: ink-color-for-fill_(hint, dark),
  104. text-disabled-on-dark: ink-color-for-fill_(disabled, dark),
  105. text-icon-on-dark: ink-color-for-fill_(icon, dark)
  106. ) !default;
  107. // If `$style` is a color (a literal color value, `currentColor`, or a CSS custom property), it is returned verbatim.
  108. // Otherwise, `$style` is treated as a theme property name, and the corresponding value from
  109. // `$mdc-theme-property-values` is returned. If this also fails, an error is thrown.
  110. //
  111. // This is mainly useful in situations where `mdc-theme-prop` cannot be used directly (e.g., `box-shadow`).
  112. //
  113. // Examples:
  114. //
  115. // 1. mdc-theme-prop-value(primary) => "#6200ee"
  116. // 2. mdc-theme-prop-value(blue) => "blue"
  117. //
  118. // NOTE: This function must be defined in _variables.scss instead of _functions.scss to avoid circular imports.
  119. @function prop-value($style) {
  120. @if functions.is-var-with-fallback_($style) {
  121. @return functions.get-var-fallback_($style);
  122. }
  123. @if is-valid-theme-prop-value_($style) {
  124. @return $style;
  125. }
  126. @if not map.has-key($property-values, $style) {
  127. @error "Invalid theme property: '#{$style}'. Choose one of: #{map.keys($property-values)}";
  128. }
  129. @return map.get($property-values, $style);
  130. }
  131. // NOTE: This function must be defined in _variables.scss instead of _functions.scss to avoid circular imports.
  132. @function accessible-ink-color($fill-color, $text-style: primary) {
  133. $fill-color-value: prop-value($fill-color);
  134. $color-map-for-tone: map.get($text-colors, functions.contrast-tone($fill-color-value));
  135. @if not map.has-key($color-map-for-tone, $text-style) {
  136. @error "Invalid $text-style: '#{$text-style}'. Choose one of: #{map.keys($color-map-for-tone)}";
  137. }
  138. @return map.get($color-map-for-tone, $text-style);
  139. }
  140. // NOTE: This function is depended upon by mdc-theme-prop-value (above) and thus must be defined in this file.
  141. @function is-valid-theme-prop-value_($style) {
  142. @return meta.type-of($style) == "color" or
  143. $style == "currentColor" or
  144. str_slice($style, 1, 4) == "var(" or
  145. $style == "inherit" or
  146. $style == "transparent" or
  147. // NOTE: `GrayText` is deprecated, but is the only feasible way to convey the
  148. // correct high-contrast mode colors in alignment with Windows system colors.
  149. $style == "GrayText";
  150. }
  151. @function text-emphasis($emphasis) {
  152. @return map.get($text-emphasis, $emphasis);
  153. }