diff --git a/packages/elements/src/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/elements/src/__tests__/__snapshots__/PublicAPI-test.js.snap index a4f6233c395b..dcb23eb2696d 100644 --- a/packages/elements/src/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/elements/src/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -206,6 +206,7 @@ Array [ "moderate01", "moderate02", "motion", + "notificationTokens", "orange", "orange40", "orange60", diff --git a/packages/styles/scss/components/notification/_tokens.scss b/packages/styles/scss/components/notification/_tokens.scss index b6cc57aab5fb..aa6b791ff611 100644 --- a/packages/styles/scss/components/notification/_tokens.scss +++ b/packages/styles/scss/components/notification/_tokens.scss @@ -13,106 +13,123 @@ @use '../../themes'; @use '../../theme'; @use '../../utilities/component-tokens'; +@use '@carbon/themes/scss/component-tokens' as notification; + @use '../button/tokens' as button-tokens; $notification-background-error: ( - fallback: colors.$red-10, + fallback: map.get(notification.$notification-background-error, white-theme), values: ( ( theme: themes.$white, - value: colors.$red-10, + value: map.get(notification.$notification-background-error, white-theme), ), ( theme: themes.$g10, - value: colors.$red-10, + value: map.get(notification.$notification-background-error, g-10), ), ( theme: themes.$g90, - value: colors.$gray-80, + value: map.get(notification.$notification-background-error, g-90), ), ( theme: themes.$g100, - value: colors.$gray-90, + value: map.get(notification.$notification-background-error, g-100), ), ), ) !default; $notification-background-success: ( - fallback: colors.$green-10, + fallback: map.get(notification.$notification-background-success, white-theme), values: ( ( theme: themes.$white, - value: colors.$green-10, + value: map.get(notification.$notification-background-success, white-theme), ), ( theme: themes.$g10, - value: colors.$green-10, + value: map.get(notification.$notification-background-success, g-10), ), ( theme: themes.$g90, - value: colors.$gray-80, + value: map.get(notification.$notification-background-success, g-90), ), ( theme: themes.$g100, - value: colors.$gray-90, + value: map.get(notification.$notification-background-success, g-100), ), ), ) !default; $notification-background-info: ( - fallback: colors.$blue-10, + fallback: map.get(notification.$notification-background-info, white-theme), values: ( ( theme: themes.$white, - value: colors.$blue-10, + value: map.get(notification.$notification-background-info, white-theme), ), ( theme: themes.$g10, - value: colors.$blue-10, + value: map.get(notification.$notification-background-info, g-10), ), ( theme: themes.$g90, - value: colors.$gray-80, + value: map.get(notification.$notification-background-info, g-90), ), ( theme: themes.$g100, - value: colors.$gray-90, + value: map.get(notification.$notification-background-info, g-100), ), ), ) !default; $notification-background-warning: ( - fallback: color.mix(colors.$yellow-30, colors.$white-0, 15%), + fallback: + color.mix( + map.get(notification.$color-map, yellow-30), + map.get(notification.$color-map, white-0), + 15% + ), values: ( ( theme: themes.$white, - value: color.mix(colors.$yellow-30, colors.$white-0, 15%), + value: + color.mix( + map.get(notification.$color-map, yellow-30), + map.get(notification.$color-map, white-0), + 15% + ), ), ( theme: themes.$g10, - value: color.mix(colors.$yellow-30, colors.$white-0, 15%), + value: + color.mix( + map.get(notification.$color-map, yellow-30), + map.get(notification.$color-map, white-0), + 15% + ), ), ( theme: themes.$g90, - value: colors.$gray-80, + value: map.get(notification.$notification-background-warning, g-90), ), ( theme: themes.$g100, - value: colors.$gray-90, + value: map.get(notification.$notification-background-warning, g-100), ), ), ) !default; $notification-action-hover: ( - fallback: colors.$white-0, + fallback: map.get(notification.$notification-background-info, white-theme), values: ( ( theme: themes.$white, - value: colors.$white-0, + value: map.get(notification.$notification-background-info, white-theme), ), ( theme: themes.$g10, - value: colors.$white-0, + value: map.get(notification.$notification-background-info, g-10), ), ( theme: themes.$g90, @@ -127,70 +144,161 @@ $notification-action-hover: ( $notification-action-tertiary-inverse: ( fallback: map.get(button-tokens.$button-tokens, button-tertiary, fallback), - values: - component-tokens.get-inverse-theme-values( - map.get(button-tokens.$button-tokens, button-tertiary) + values: ( + ( + theme: themes.$white, + value: + map.get(notification.$notification-action-tertiary-inverse, white-theme), + ), + ( + theme: themes.$g10, + value: map.get(notification.$notification-action-tertiary-inverse, g-10), + ), + ( + theme: themes.$g90, + value: map.get(notification.$notification-action-tertiary-inverse, g-90), ), + ( + theme: themes.$g100, + value: map.get(notification.$notification-action-tertiary-inverse, g-100), + ), + ), ) !default; $notification-action-tertiary-inverse-active: ( fallback: map.get(button-tokens.$button-tokens, button-tertiary-active, fallback), - values: - component-tokens.get-inverse-theme-values( - map.get(button-tokens.$button-tokens, button-tertiary-active) + values: ( + ( + theme: themes.$white, + value: + map.get( + notification.$notification-action-tertiary-inverse-active, + white-theme + ), + ), + ( + theme: themes.$g10, + value: + map.get(notification.$notification-action-tertiary-inverse-active, g-10), + ), + ( + theme: themes.$g90, + value: + map.get(notification.$notification-action-tertiary-inverse-active, g-90), + ), + ( + theme: themes.$g100, + value: + map.get( + notification.$notification-action-tertiary-inverse-active, + g-100 + ), ), + ), ) !default; $notification-action-tertiary-inverse-hover: ( fallback: map.get(button-tokens.$button-tokens, button-tertiary-hover, fallback), - values: - component-tokens.get-inverse-theme-values( - map.get(button-tokens.$button-tokens, button-tertiary-hover) + values: ( + ( + theme: themes.$white, + value: + map.get( + notification.$notification-action-tertiary-inverse-hover, + white-theme + ), + ), + ( + theme: themes.$g10, + value: + map.get(notification.$notification-action-tertiary-inverse-hover, g-10), ), + ( + theme: themes.$g90, + value: + map.get(notification.$notification-action-tertiary-inverse-hover, g-90), + ), + ( + theme: themes.$g100, + value: + map.get(notification.$notification-action-tertiary-inverse-hover, g-100), + ), + ), ) !default; $notification-action-tertiary-inverse-text: ( - fallback: map.get(themes.$white, text-inverse), + fallback: + map.get( + notification.$notification-action-tertiary-inverse-text, + white-theme + ), values: ( ( theme: themes.$white, - value: map.get(themes.$g100, text-inverse), + value: + map.get( + notification.$notification-action-tertiary-inverse-text, + white-theme + ), ), ( theme: themes.$g10, - value: map.get(themes.$g90, text-inverse), + value: + map.get(notification.$notification-action-tertiary-inverse-text, g-10), ), ( theme: themes.$g90, - value: map.get(themes.$g10, text-inverse), + value: + map.get(notification.$notification-action-tertiary-inverse-text, g-90), ), ( theme: themes.$g100, - value: map.get(themes.$white, text-inverse), + value: + map.get(notification.$notification-action-tertiary-inverse-text, g-100), ), ), ) !default; $notification-action-tertiary-inverse-text-on-color-disabled: ( - fallback: map.get(themes.$white, text-on-color-disabled), + fallback: + map.get( + notification.$notification-action-tertiary-inverse-text-on-color-disabled, + white-theme + ), values: ( ( theme: themes.$white, - value: map.get(themes.$g100, text-on-color-disabled), + value: + map.get( + notification.$notification-action-tertiary-inverse-text-on-color-disabled, + white-theme + ), ), ( theme: themes.$g10, - value: map.get(themes.$g90, text-on-color-disabled), + value: + map.get( + notification.$notification-action-tertiary-inverse-text-on-color-disabled, + g-10 + ), ), ( theme: themes.$g90, - value: map.get(themes.$g10, text-on-color-disabled), + value: + map.get( + notification.$notification-action-tertiary-inverse-text-on-color-disabled, + g-90 + ), ), ( theme: themes.$g100, - value: map.get(themes.$white, text-on-color-disabled), + value: + map.get( + notification.$notification-action-tertiary-inverse-text-on-color-disabled, + g-100 + ), ), ), ) !default; diff --git a/packages/themes/scss/_component-tokens.scss b/packages/themes/scss/_component-tokens.scss index 053692cd7b23..a973dc1ef487 100644 --- a/packages/themes/scss/_component-tokens.scss +++ b/packages/themes/scss/_component-tokens.scss @@ -7,3 +7,4 @@ @forward 'generated/button-tokens'; @forward 'generated/tag-tokens'; +@forward 'generated/notification-tokens'; diff --git a/packages/themes/src/component-tokens/notification/index.js b/packages/themes/src/component-tokens/notification/index.js index e69de29bb2d1..7cfd258a2bd1 100644 --- a/packages/themes/src/component-tokens/notification/index.js +++ b/packages/themes/src/component-tokens/notification/index.js @@ -0,0 +1 @@ +export * as notificationTokens from './tokens'; diff --git a/packages/themes/src/component-tokens/notification/tokens.js b/packages/themes/src/component-tokens/notification/tokens.js new file mode 100644 index 000000000000..ccaf16094fdb --- /dev/null +++ b/packages/themes/src/component-tokens/notification/tokens.js @@ -0,0 +1,103 @@ +import { + red10, + gray80, + gray90, + green10, + blue10, + yellow30, + white0, +} from '@carbon/colors'; +import { + textInverse as textInverseWhite, + textOnColorDisabled as textOnColorDisabledWhite, +} from '../../white'; +import { + textInverse as textInverseG10, + textOnColorDisabled as textOnColorDisabledG10, +} from '../../g10'; +import { + textInverse as textInverseG90, + textOnColorDisabled as textOnColorDisabledG90, +} from '../../g90'; +import { + textInverse as textInverseG100, + textOnColorDisabled as textOnColorDisabledG100, +} from '../../g100'; +import { + buttonTertiaryActive, + buttonTertiaryHover, + buttonTertiary, +} from '../button/tokens'; + +export const notificationBackgroundError = { + whiteTheme: red10, + g10: red10, + g90: gray80, + g100: gray90, +}; + +export const notificationBackgroundSuccess = { + whiteTheme: green10, + g10: green10, + g90: gray80, + g100: gray90, +}; + +export const notificationBackgroundInfo = { + whiteTheme: blue10, + g10: blue10, + g90: gray80, + g100: gray90, +}; + +export const colorMap = { + yellow30, + white0, +}; + +export const notificationBackgroundWarning = { + whiteTheme: colorMap, + g10: colorMap, + g90: gray80, + g100: gray90, +}; + +export const notificationActionHover = { + whiteTheme: white0, + g10: white0, +}; + +export const notificationActionTertiaryInverse = { + whiteTheme: buttonTertiary.g100, + g10: buttonTertiary.g90, + g90: buttonTertiary.g10, + g100: buttonTertiary.whiteTheme, +}; + +export const notificationActionTertiaryInverseActive = { + whiteTheme: buttonTertiaryActive.g100, + g10: buttonTertiaryActive.g90, + g90: buttonTertiaryActive.g10, + g100: buttonTertiaryActive.whiteTheme, +}; + +export const notificationActionTertiaryInverseHover = { + whiteTheme: buttonTertiaryHover.g100, + g10: buttonTertiaryHover.g90, + g90: buttonTertiaryHover.g10, + g100: buttonTertiaryHover.whiteTheme, +}; + +export const notificationActionTertiaryInverseText = { + whiteTheme: textInverseG100, + g10: textInverseG90, + g90: textInverseG10, + g100: textInverseWhite, +}; + +export const notificationActionTertiaryInverseTextOnColorDisabled = { + whiteTheme: textOnColorDisabledG100, + g10: textOnColorDisabledG90, + g90: textOnColorDisabledG10, + g100: textOnColorDisabledWhite, +}; diff --git a/packages/themes/src/index.js b/packages/themes/src/index.js index f38d256b5f95..63a879bb4065 100644 --- a/packages/themes/src/index.js +++ b/packages/themes/src/index.js @@ -12,6 +12,7 @@ import * as g100 from './g100'; import * as v10 from './v10'; import * as buttonTokens from './component-tokens/button'; import * as tagTokens from './component-tokens/tag'; +import * as notificationTokens from './component-tokens/notification'; import { formatTokenName } from './tools'; import { unstable_metadata } from './tokens'; @@ -32,6 +33,7 @@ export { v10, buttonTokens, tagTokens, + notificationTokens, unstable_metadata, formatTokenName, }; diff --git a/packages/themes/tasks/build.js b/packages/themes/tasks/build.js index c95704b21cad..644d2eef065c 100644 --- a/packages/themes/tasks/build.js +++ b/packages/themes/tasks/build.js @@ -19,6 +19,7 @@ const buildModulesThemesFile = require('./builders/modules-themes'); const buildModulesTokensFile = require('./builders/modules-tokens'); const buildModulesButtonTokens = require('./builders/modules-button-tokens'); const buildModulesTagTokens = require('./builders/modules-tag-tokens'); +const buildModulesNotificationTokens = require('./builders/modules-notification-tokens'); async function build() { reporter.info('Building scss files for themes...'); @@ -62,6 +63,12 @@ async function build() { return buildModulesTagTokens(); }, }, + { + filepath: path.join(GENERATED_SCSS_DIR, '_notification-tokens.scss'), + builder() { + return buildModulesNotificationTokens(); + }, + }, ]; for (const { filepath, builder } of files) { diff --git a/packages/themes/tasks/builders/modules-notification-tokens.js b/packages/themes/tasks/builders/modules-notification-tokens.js new file mode 100644 index 000000000000..491b7ad26ebf --- /dev/null +++ b/packages/themes/tasks/builders/modules-notification-tokens.js @@ -0,0 +1,47 @@ +/** + * Copyright IBM Corp. 2015, 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 strict'; + +const { types: t } = require('@carbon/scss-generator'); +const { TokenFormat } = require('../../src/tokens'); +const { + notificationTokens, +} = require('../../src/component-tokens/notification'); +const { FILE_BANNER, primitive } = require('./shared'); +const { paramCase } = require('change-case'); + +function buildThemesFile() { + const imports = [t.SassModule('sass:map')]; + + const variables = Object.entries(notificationTokens).flatMap( + ([key, notificationToken]) => { + return [ + t.Newline(), + t.Assignment({ + id: t.Identifier(paramCase(key)), + init: t.SassMap({ + properties: Object.entries(notificationToken).map( + ([token, value]) => { + const id = TokenFormat.convert({ + name: token, + format: TokenFormat.formats.scss, + }); + return t.SassMapProperty(t.Identifier(id), primitive(value)); + } + ), + }), + default: true, + }), + ]; + } + ); + + return t.StyleSheet([FILE_BANNER, t.Newline(), ...imports, ...variables]); +} + +module.exports = buildThemesFile;