diff --git a/packages/styles/scss/components/notification/_index.scss b/packages/styles/scss/components/notification/_index.scss new file mode 100644 index 000000000000..b4622b04e767 --- /dev/null +++ b/packages/styles/scss/components/notification/_index.scss @@ -0,0 +1,8 @@ +// +// Copyright IBM Corp. 2018, 2018 +// +// This source code is licensed under the Apache-2.0 license found in the +// LICENSE file in the root directory of this source tree. +// + +@forward 'tokens'; diff --git a/packages/styles/scss/components/notification/_tokens.scss b/packages/styles/scss/components/notification/_tokens.scss new file mode 100644 index 000000000000..d172d84ad1f2 --- /dev/null +++ b/packages/styles/scss/components/notification/_tokens.scss @@ -0,0 +1,126 @@ +// +// Copyright IBM Corp. 2018, 2018 +// +// This source code is licensed under the Apache-2.0 license found in the +// LICENSE file in the root directory of this source tree. +// + +@use 'sass:color'; +@use '../../colors'; +@use '../../theme' as *; +@use '../../themes'; +@use '../../utilities/component-tokens'; + +// prettier-ignore +$-tokens: ( + 'notification-background-error': ( + fallback: colors.$red-10, + values: ( + ( + theme: themes.$white, + value: colors.$red-10, + ), + ( + theme: themes.$g10, + value: colors.$red-10, + ), + ( + theme: themes.$g90, + value: $layer, + ), + ( + theme: themes.$g100, + value: $layer, + ), + ), + ), + 'notification-background-success': ( + fallback: colors.$green-10, + values: ( + ( + theme: themes.$white, + value: colors.$green-10, + ), + ( + theme: themes.$g10, + value: colors.$green-10, + ), + ( + theme: themes.$g90, + value: $layer, + ), + ( + theme: themes.$g100, + value: $layer, + ), + ), + ), + 'notification-background-info': ( + fallback: colors.$blue-10, + values: ( + ( + theme: themes.$white, + value: colors.$blue-10, + ), + ( + theme: themes.$g10, + value: colors.$blue-10, + ), + ( + theme: themes.$g90, + value: $layer, + ), + ( + theme: themes.$g100, + value: $layer, + ), + ), + ), + 'notification-background-warning': ( + fallback: mix(colors.$yellow-30, colors.$white-0, 15%), + values: ( + ( + theme: themes.$white, + value: mix(colors.$yellow-30, colors.$white-0, 15%), + ), + ( + theme: themes.$g10, + value: mix(colors.$yellow-30, colors.$white-0, 15%), + ), + ( + theme: themes.$g90, + value: $layer, + ), + ( + theme: themes.$g100, + value: $layer, + ), + ), + ), + 'notification-action-hover': ( + fallback: colors.$white-0, + values: ( + ( + theme: themes.$white, + value: colors.$white-0, + ), + ( + theme: themes.$g10, + value: colors.$white-0, + ), + ( + theme: themes.$g90, + value: $layer-hover, + ), + ( + theme: themes.$g100, + value: $layer-hover, + ), + ), + ), +); + +$white: component-tokens.get-tokens($-tokens, themes.$white); +$g10: component-tokens.get-tokens($-tokens, themes.$g10); +$g90: component-tokens.get-tokens($-tokens, themes.$g90); +$g100: component-tokens.get-tokens($-tokens, themes.$g100); diff --git a/packages/styles/scss/utilities/_component-tokens.scss b/packages/styles/scss/utilities/_component-tokens.scss new file mode 100644 index 000000000000..bc578c570792 --- /dev/null +++ b/packages/styles/scss/utilities/_component-tokens.scss @@ -0,0 +1,27 @@ +// +// Copyright IBM Corp. 2018, 2018 +// +// This source code is licensed under the Apache-2.0 license found in the +// LICENSE file in the root directory of this source tree. +// + +@use 'sass:map'; + +/// Extract the component tokens from a given theme +/// @param {SassMap} $tokens +/// @param {SassMap} $theme +/// @returns {SassMap} +@function get-tokens($tokens, $theme) { + $result: (); + + @each $key, $descriptor in $tokens { + $theme-values: map.get($descriptor, values); + @each $theme-value in $theme-values { + @if map.get($theme-value, theme) == $theme { + $result: map.set($result, $key, map.get($theme-value, value)); + } + } + } + + @return $result; +} diff --git a/packages/themes/scss/modules/_theme.scss b/packages/themes/scss/modules/_theme.scss index 7308f9b43618..67bfb4eb0a9c 100644 --- a/packages/themes/scss/modules/_theme.scss +++ b/packages/themes/scss/modules/_theme.scss @@ -14,7 +14,7 @@ $-custom-property-prefix: 'cds'; /// @access public /// @group @carbon/themes -@mixin theme($active-theme: $theme) { +@mixin theme($active-theme: $theme, $component-tokens...) { $parent-theme: $theme; $theme: $active-theme !global; @@ -22,6 +22,12 @@ $-custom-property-prefix: 'cds'; @include -custom-property($token, $value); } + @each $group in $component-tokens { + @each $token, $value in $group { + @include -custom-property($token, $value); + } + } + @content; $theme: $parent-theme !global;