From a746b5f54dbcadc7211630d76ce78b4f4a34fc04 Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Tue, 19 Nov 2024 17:35:58 +0100 Subject: [PATCH] Android: improve the color token filters (#127) * Android: improve the color token filters to distinguish core and semantic tokens * Generate new tokens --- assets/android/src/SemanticColors.kt | 6 ++++++ assets/android/src/SemanticColorsDark.kt | 2 ++ assets/android/src/SemanticColorsDarkHc.kt | 2 ++ assets/android/src/SemanticColorsLight.kt | 2 ++ assets/android/src/SemanticColorsLightHc.kt | 2 ++ assets/android/src/internal/DarkColorTokens.kt | 2 -- assets/android/src/internal/DarkHcColorTokens.kt | 2 -- assets/android/src/internal/LightColorTokens.kt | 2 -- assets/android/src/internal/LightHcColorTokens.kt | 2 -- src/configs/getAndroidConfig.ts | 11 ++++++----- 10 files changed, 20 insertions(+), 13 deletions(-) diff --git a/assets/android/src/SemanticColors.kt b/assets/android/src/SemanticColors.kt index 634bdc8..b7b949a 100644 --- a/assets/android/src/SemanticColors.kt +++ b/assets/android/src/SemanticColors.kt @@ -59,6 +59,9 @@ data class SemanticColors( /** Default global background for the user interface. Elevation: Default (Level 0) */ val bgCanvasDefault: Color, + /** Default global background for the user interface. +Elevation: Level 1. */ + val bgCanvasDefaultLevel1: Color, /** Default background for disabled elements. There's no minimum contrast requirement. */ val bgCanvasDisabled: Color, /** High-contrast background color for critical state. State: Hover. */ @@ -89,6 +92,9 @@ Elevation: Default (Level 2). */ /** Low contrast surfaces. Elevation: Default (Level 1). */ val bgSubtleSecondary: Color, + /** Lower contrast surfaces. +Elevation: Level 0. */ + val bgSubtleSecondaryLevel0: Color, /** Subtle background colour for success state elements. State: Rest. */ val bgSuccessSubtle: Color, /** High-contrast border for critical state. State: Hover. */ diff --git a/assets/android/src/SemanticColorsDark.kt b/assets/android/src/SemanticColorsDark.kt index c77d38d..5539287 100644 --- a/assets/android/src/SemanticColorsDark.kt +++ b/assets/android/src/SemanticColorsDark.kt @@ -44,6 +44,7 @@ val compoundColorsDark = SemanticColors( bgActionSecondaryPressed = DarkColorTokens.colorAlphaGray300, bgActionSecondaryRest = DarkColorTokens.colorThemeBg, bgCanvasDefault = DarkColorTokens.colorThemeBg, + bgCanvasDefaultLevel1 = DarkColorTokens.colorGray300, bgCanvasDisabled = DarkColorTokens.colorGray200, bgCriticalHovered = DarkColorTokens.colorRed1000, bgCriticalPrimary = DarkColorTokens.colorRed900, @@ -58,6 +59,7 @@ val compoundColorsDark = SemanticColors( bgInfoSubtle = DarkColorTokens.colorBlue200, bgSubtlePrimary = DarkColorTokens.colorGray400, bgSubtleSecondary = DarkColorTokens.colorGray300, + bgSubtleSecondaryLevel0 = DarkColorTokens.colorThemeBg, bgSuccessSubtle = DarkColorTokens.colorGreen200, borderCriticalHovered = DarkColorTokens.colorRed1000, borderCriticalPrimary = DarkColorTokens.colorRed900, diff --git a/assets/android/src/SemanticColorsDarkHc.kt b/assets/android/src/SemanticColorsDarkHc.kt index 693d79a..f6161d3 100644 --- a/assets/android/src/SemanticColorsDarkHc.kt +++ b/assets/android/src/SemanticColorsDarkHc.kt @@ -44,6 +44,7 @@ val compoundColorsHcDark = SemanticColors( bgActionSecondaryPressed = DarkHcColorTokens.colorAlphaGray300, bgActionSecondaryRest = DarkHcColorTokens.colorThemeBg, bgCanvasDefault = DarkHcColorTokens.colorThemeBg, + bgCanvasDefaultLevel1 = DarkHcColorTokens.colorGray300, bgCanvasDisabled = DarkHcColorTokens.colorGray200, bgCriticalHovered = DarkHcColorTokens.colorRed1000, bgCriticalPrimary = DarkHcColorTokens.colorRed900, @@ -58,6 +59,7 @@ val compoundColorsHcDark = SemanticColors( bgInfoSubtle = DarkHcColorTokens.colorBlue200, bgSubtlePrimary = DarkHcColorTokens.colorGray400, bgSubtleSecondary = DarkHcColorTokens.colorGray300, + bgSubtleSecondaryLevel0 = DarkHcColorTokens.colorThemeBg, bgSuccessSubtle = DarkHcColorTokens.colorGreen200, borderCriticalHovered = DarkHcColorTokens.colorRed1000, borderCriticalPrimary = DarkHcColorTokens.colorRed900, diff --git a/assets/android/src/SemanticColorsLight.kt b/assets/android/src/SemanticColorsLight.kt index 66b3686..d2d7556 100644 --- a/assets/android/src/SemanticColorsLight.kt +++ b/assets/android/src/SemanticColorsLight.kt @@ -44,6 +44,7 @@ val compoundColorsLight = SemanticColors( bgActionSecondaryPressed = LightColorTokens.colorAlphaGray300, bgActionSecondaryRest = LightColorTokens.colorThemeBg, bgCanvasDefault = LightColorTokens.colorThemeBg, + bgCanvasDefaultLevel1 = LightColorTokens.colorThemeBg, bgCanvasDisabled = LightColorTokens.colorGray200, bgCriticalHovered = LightColorTokens.colorRed1000, bgCriticalPrimary = LightColorTokens.colorRed900, @@ -58,6 +59,7 @@ val compoundColorsLight = SemanticColors( bgInfoSubtle = LightColorTokens.colorBlue200, bgSubtlePrimary = LightColorTokens.colorGray400, bgSubtleSecondary = LightColorTokens.colorGray300, + bgSubtleSecondaryLevel0 = LightColorTokens.colorGray300, bgSuccessSubtle = LightColorTokens.colorGreen200, borderCriticalHovered = LightColorTokens.colorRed1000, borderCriticalPrimary = LightColorTokens.colorRed900, diff --git a/assets/android/src/SemanticColorsLightHc.kt b/assets/android/src/SemanticColorsLightHc.kt index ec8d4e9..d8413da 100644 --- a/assets/android/src/SemanticColorsLightHc.kt +++ b/assets/android/src/SemanticColorsLightHc.kt @@ -44,6 +44,7 @@ val compoundColorsHcLight = SemanticColors( bgActionSecondaryPressed = LightHcColorTokens.colorAlphaGray300, bgActionSecondaryRest = LightHcColorTokens.colorThemeBg, bgCanvasDefault = LightHcColorTokens.colorThemeBg, + bgCanvasDefaultLevel1 = LightHcColorTokens.colorThemeBg, bgCanvasDisabled = LightHcColorTokens.colorGray200, bgCriticalHovered = LightHcColorTokens.colorRed1000, bgCriticalPrimary = LightHcColorTokens.colorRed900, @@ -58,6 +59,7 @@ val compoundColorsHcLight = SemanticColors( bgInfoSubtle = LightHcColorTokens.colorBlue200, bgSubtlePrimary = LightHcColorTokens.colorGray400, bgSubtleSecondary = LightHcColorTokens.colorGray300, + bgSubtleSecondaryLevel0 = LightHcColorTokens.colorGray300, bgSuccessSubtle = LightHcColorTokens.colorGreen200, borderCriticalHovered = LightHcColorTokens.colorRed1000, borderCriticalPrimary = LightHcColorTokens.colorRed900, diff --git a/assets/android/src/internal/DarkColorTokens.kt b/assets/android/src/internal/DarkColorTokens.kt index 521d3e2..62b0da4 100644 --- a/assets/android/src/internal/DarkColorTokens.kt +++ b/assets/android/src/internal/DarkColorTokens.kt @@ -184,8 +184,6 @@ object DarkColorTokens { val colorAlphaYellow700 = Color(0xeb854200) val colorAlphaYellow800 = Color(0xff9e5c00) val colorAlphaYellow900 = Color(0xffbd7b00) - val colorBgCanvasDefaultLevel1 = colorGray300 - val colorBgSubtleSecondaryLevel0 = colorThemeBg val colorBlue100 = Color(0xff00055a) val colorBlue1000 = Color(0xff5e99f0) val colorBlue1100 = Color(0xff7aacf4) diff --git a/assets/android/src/internal/DarkHcColorTokens.kt b/assets/android/src/internal/DarkHcColorTokens.kt index 7324afb..ce9dd74 100644 --- a/assets/android/src/internal/DarkHcColorTokens.kt +++ b/assets/android/src/internal/DarkHcColorTokens.kt @@ -184,8 +184,6 @@ object DarkHcColorTokens { val colorAlphaYellow700 = Color(0xff995700) val colorAlphaYellow800 = Color(0xffb37100) val colorAlphaYellow900 = Color(0xffe6ac00) - val colorBgCanvasDefaultLevel1 = colorGray300 - val colorBgSubtleSecondaryLevel0 = colorThemeBg val colorBlue100 = Color(0xff00095d) val colorBlue1000 = Color(0xff9ac0f8) val colorBlue1100 = Color(0xffb2cffa) diff --git a/assets/android/src/internal/LightColorTokens.kt b/assets/android/src/internal/LightColorTokens.kt index 11ba178..0af6a10 100644 --- a/assets/android/src/internal/LightColorTokens.kt +++ b/assets/android/src/internal/LightColorTokens.kt @@ -184,8 +184,6 @@ object LightColorTokens { val colorAlphaYellow700 = Color(0xffe0a500) val colorAlphaYellow800 = Color(0xffbd7b00) val colorAlphaYellow900 = Color(0xff9e5a00) - val colorBgCanvasDefaultLevel1 = colorThemeBg - val colorBgSubtleSecondaryLevel0 = colorGray300 val colorBlue100 = Color(0xfff9fcff) val colorBlue1000 = Color(0xff0558c7) val colorBlue1100 = Color(0xff064ab1) diff --git a/assets/android/src/internal/LightHcColorTokens.kt b/assets/android/src/internal/LightHcColorTokens.kt index 371f98e..2d9f4aa 100644 --- a/assets/android/src/internal/LightHcColorTokens.kt +++ b/assets/android/src/internal/LightHcColorTokens.kt @@ -184,8 +184,6 @@ object LightHcColorTokens { val colorAlphaYellow700 = Color(0xffc28100) val colorAlphaYellow800 = Color(0xffa86500) val colorAlphaYellow900 = Color(0xff753700) - val colorBgCanvasDefaultLevel1 = colorThemeBg - val colorBgSubtleSecondaryLevel0 = colorGray300 val colorBlue100 = Color(0xfff4f8ff) val colorBlue1000 = Color(0xff053b9a) val colorBlue1100 = Color(0xff043088) diff --git a/src/configs/getAndroidConfig.ts b/src/configs/getAndroidConfig.ts index 035cfbd..d0f2a39 100644 --- a/src/configs/getAndroidConfig.ts +++ b/src/configs/getAndroidConfig.ts @@ -23,7 +23,7 @@ import type { TransformedToken, } from "style-dictionary/types"; import type { Theme } from "../@types"; -import { isCoreColor, isNotCoreColor } from "../filters/isCoreColor"; +import isCoreToken from "../filters/isCoreToken"; import isTypographyToken from "../filters/isTypographyToken"; import { ANDROID_INDENT_LEVEL } from "../utils/constants"; import createTemplate from "../utils/createTemplate"; @@ -173,9 +173,10 @@ export function getAndroidConfig(theme: Theme): PlatformConfig { { format: "compose/core-colors", destination: `internal/${className}ColorTokens.kt`, - filter: (token: TransformedToken) => isCoreColor.filter(token), + filter: (token: TransformedToken) => + token.type === "color" && isCoreToken.filter(token), options: withDefaultOptions({ - outputReferences: true, + outputReferences: false, import: ["androidx.compose.ui.graphics.Color"], isInternal: true, className: `${className}ColorTokens`, @@ -186,7 +187,7 @@ export function getAndroidConfig(theme: Theme): PlatformConfig { format: "compose/semantic-colors", destination: `SemanticColors${className}.kt`, filter: (token: TransformedToken) => - token.type === "color" && isNotCoreColor.filter(token), + token.type === "color" && !isCoreToken.filter(token), options: withDefaultOptions({ outputReferences: true, import: [ @@ -207,7 +208,7 @@ export function getAndroidConfig(theme: Theme): PlatformConfig { format: "compose/extra-colors", destination: "SemanticColors.kt", filter: (token: TransformedToken) => - token.type === "color" && isNotCoreColor.filter(token), + token.type === "color" && !isCoreToken.filter(token), options: withDefaultOptions({ outputReferences: true, import: [],