Skip to content

Commit

Permalink
Android: improve the color token filters (#127)
Browse files Browse the repository at this point in the history
* Android: improve the color token filters to distinguish core and semantic tokens

* Generate new tokens
  • Loading branch information
jmartinesp authored Nov 19, 2024
1 parent 04dc58a commit a746b5f
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 13 deletions.
6 changes: 6 additions & 0 deletions assets/android/src/SemanticColors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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. */
Expand Down
2 changes: 2 additions & 0 deletions assets/android/src/SemanticColorsDark.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions assets/android/src/SemanticColorsDarkHc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions assets/android/src/SemanticColorsLight.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions assets/android/src/SemanticColorsLightHc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions assets/android/src/internal/DarkColorTokens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions assets/android/src/internal/DarkHcColorTokens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions assets/android/src/internal/LightColorTokens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions assets/android/src/internal/LightHcColorTokens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions src/configs/getAndroidConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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`,
Expand All @@ -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: [
Expand All @@ -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: [],
Expand Down

0 comments on commit a746b5f

Please sign in to comment.