| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- //
- // Copyright 2017 Google Inc.
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- @use "sass:map";
- @use "sass:meta";
- @use "./functions";
- //
- // Main theme colors for your brand.
- //
- // If you're a user customizing your color scheme in SASS, these are probably the only variables you need to change.
- //
- $primary: #6200ee !default; // baseline purple, 500 tone
- $on-primary: if(functions.contrast-tone($primary) == "dark", #000, #fff) !default;
- // The $mdc-theme-accent variable is DEPRECATED - it exists purely for backward compatibility.
- // The $mdc-theme-secondary* variables should be used for all new projects.
- $accent: #018786 !default; // baseline teal, 600 tone
- $secondary: $accent !default;
- $on-secondary: if(functions.contrast-tone($secondary) == "dark", #000, #fff) !default;
- $background: #fff !default; // White
- $surface: #fff !default;
- $on-surface: if(functions.contrast-tone($surface) == "dark", #000, #fff) !default;
- $error: #b00020 !default;
- $on-error: if(functions.contrast-tone($error) == "dark", #000, #fff) !default;
- //
- // Text colors according to light vs dark and text type.
- //
- $text-colors: (
- dark: (
- primary: rgba(black, .87),
- secondary: rgba(black, .54),
- hint: rgba(black, .38),
- disabled: rgba(black, .38),
- icon: rgba(black, .38)
- ),
- light: (
- primary: white,
- secondary: rgba(white, .7),
- hint: rgba(white, .5),
- disabled: rgba(white, .5),
- icon: rgba(white, .5)
- )
- ) !default;
- $text-emphasis: (
- high: .87,
- medium: .6,
- disabled: .38,
- ) !default;
- @function ink-color-for-fill_($text-style, $fill-color) {
- $contrast-tone: functions.contrast-tone($fill-color);
- @return map.get(map.get($text-colors, $contrast-tone), $text-style);
- }
- //
- // Primary text colors for each of the theme colors.
- //
- $property-values: (
- // Primary
- primary: $primary,
- // Secondary
- secondary: $secondary,
- // Background
- background: $background,
- // Surface
- surface: $surface,
- // Error
- error: $error,
- on-primary: $on-primary,
- on-secondary: $on-secondary,
- on-surface: $on-surface,
- on-error: $on-error,
- // Text-primary on "background" background
- text-primary-on-background: ink-color-for-fill_(primary, $background),
- text-secondary-on-background: ink-color-for-fill_(secondary, $background),
- text-hint-on-background: ink-color-for-fill_(hint, $background),
- text-disabled-on-background: ink-color-for-fill_(disabled, $background),
- text-icon-on-background: ink-color-for-fill_(icon, $background),
- // Text-primary on "light" background
- text-primary-on-light: ink-color-for-fill_(primary, light),
- text-secondary-on-light: ink-color-for-fill_(secondary, light),
- text-hint-on-light: ink-color-for-fill_(hint, light),
- text-disabled-on-light: ink-color-for-fill_(disabled, light),
- text-icon-on-light: ink-color-for-fill_(icon, light),
- // Text-primary on "dark" background
- text-primary-on-dark: ink-color-for-fill_(primary, dark),
- text-secondary-on-dark: ink-color-for-fill_(secondary, dark),
- text-hint-on-dark: ink-color-for-fill_(hint, dark),
- text-disabled-on-dark: ink-color-for-fill_(disabled, dark),
- text-icon-on-dark: ink-color-for-fill_(icon, dark)
- ) !default;
- // If `$style` is a color (a literal color value, `currentColor`, or a CSS custom property), it is returned verbatim.
- // Otherwise, `$style` is treated as a theme property name, and the corresponding value from
- // `$mdc-theme-property-values` is returned. If this also fails, an error is thrown.
- //
- // This is mainly useful in situations where `mdc-theme-prop` cannot be used directly (e.g., `box-shadow`).
- //
- // Examples:
- //
- // 1. mdc-theme-prop-value(primary) => "#6200ee"
- // 2. mdc-theme-prop-value(blue) => "blue"
- //
- // NOTE: This function must be defined in _variables.scss instead of _functions.scss to avoid circular imports.
- @function prop-value($style) {
- @if functions.is-var-with-fallback_($style) {
- @return functions.get-var-fallback_($style);
- }
- @if is-valid-theme-prop-value_($style) {
- @return $style;
- }
- @if not map.has-key($property-values, $style) {
- @error "Invalid theme property: '#{$style}'. Choose one of: #{map.keys($property-values)}";
- }
- @return map.get($property-values, $style);
- }
- // NOTE: This function must be defined in _variables.scss instead of _functions.scss to avoid circular imports.
- @function accessible-ink-color($fill-color, $text-style: primary) {
- $fill-color-value: prop-value($fill-color);
- $color-map-for-tone: map.get($text-colors, functions.contrast-tone($fill-color-value));
- @if not map.has-key($color-map-for-tone, $text-style) {
- @error "Invalid $text-style: '#{$text-style}'. Choose one of: #{map.keys($color-map-for-tone)}";
- }
- @return map.get($color-map-for-tone, $text-style);
- }
- // NOTE: This function is depended upon by mdc-theme-prop-value (above) and thus must be defined in this file.
- @function is-valid-theme-prop-value_($style) {
- @return meta.type-of($style) == "color" or
- $style == "currentColor" or
- str_slice($style, 1, 4) == "var(" or
- $style == "inherit" or
- $style == "transparent" or
- // NOTE: `GrayText` is deprecated, but is the only feasible way to convey the
- // correct high-contrast mode colors in alignment with Windows system colors.
- $style == "GrayText";
- }
- @function text-emphasis($emphasis) {
- @return map.get($text-emphasis, $emphasis);
- }
|