From df53a1a8804b90b6a1f2a290fa6d1c2977c317ec Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 4 Jul 2024 16:50:04 +0200 Subject: [PATCH] Generate android semantic colors (#85) * Git ignore IntelliJ folder. * Generate SemanticColors objects for Android --- .gitignore | 2 + assets/android/src/SemanticColorsDark.kt | 105 ++++++++++++++++++ assets/android/src/SemanticColorsDarkHc.kt | 105 ++++++++++++++++++ assets/android/src/SemanticColorsLight.kt | 105 ++++++++++++++++++ assets/android/src/SemanticColorsLightHc.kt | 105 ++++++++++++++++++ src/configs/getAndroidConfig.ts | 67 +++++++++++ .../compose/semantic-colors.kt.template | 25 +++++ 7 files changed, 514 insertions(+) create mode 100644 assets/android/src/SemanticColorsDark.kt create mode 100644 assets/android/src/SemanticColorsDarkHc.kt create mode 100644 assets/android/src/SemanticColorsLight.kt create mode 100644 assets/android/src/SemanticColorsLightHc.kt create mode 100644 src/formats/templates/compose/semantic-colors.kt.template diff --git a/.gitignore b/.gitignore index ad933ef8..92754a03 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ node_modules storybook-static .swiftpm/ + +.idea diff --git a/assets/android/src/SemanticColorsDark.kt b/assets/android/src/SemanticColorsDark.kt new file mode 100644 index 00000000..4faa1d7c --- /dev/null +++ b/assets/android/src/SemanticColorsDark.kt @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * !!! WARNING !!! + * + * THIS IS AN AUTOGENERATED FILE. + * DO NOT EDIT MANUALLY. + */ + + + +@file:Suppress("all") +package io.element.android.compound.tokens.generated + +import io.element.android.compound.annotations.CoreColorToken +import io.element.android.compound.tokens.generated.internal.DarkColorTokens + +/** + * Semantic colors for the dark Compound theme. + */ +@OptIn(CoreColorToken::class) +val compoundColorsDark = SemanticColors( + bgAccentHovered = DarkColorTokens.colorGreen1000, + bgAccentPressed = DarkColorTokens.colorGreen1100, + bgAccentRest = DarkColorTokens.colorGreen900, + bgActionPrimaryDisabled = DarkColorTokens.colorGray700, + bgActionPrimaryHovered = DarkColorTokens.colorGray1200, + bgActionPrimaryPressed = DarkColorTokens.colorGray1100, + bgActionPrimaryRest = DarkColorTokens.colorGray1400, + bgActionSecondaryHovered = DarkColorTokens.colorAlphaGray200, + bgActionSecondaryPressed = DarkColorTokens.colorAlphaGray300, + bgActionSecondaryRest = DarkColorTokens.colorThemeBg, + bgCanvasDefault = DarkColorTokens.colorThemeBg, + bgCanvasDisabled = DarkColorTokens.colorGray200, + bgCriticalHovered = DarkColorTokens.colorRed1000, + bgCriticalPrimary = DarkColorTokens.colorRed900, + bgCriticalSubtle = DarkColorTokens.colorRed200, + bgCriticalSubtleHovered = DarkColorTokens.colorRed300, + bgDecorative1 = DarkColorTokens.colorLime300, + bgDecorative2 = DarkColorTokens.colorCyan300, + bgDecorative3 = DarkColorTokens.colorFuchsia300, + bgDecorative4 = DarkColorTokens.colorPurple300, + bgDecorative5 = DarkColorTokens.colorPink300, + bgDecorative6 = DarkColorTokens.colorOrange300, + bgInfoSubtle = DarkColorTokens.colorBlue200, + bgSubtlePrimary = DarkColorTokens.colorGray400, + bgSubtleSecondary = DarkColorTokens.colorGray300, + bgSuccessSubtle = DarkColorTokens.colorGreen200, + borderCriticalHovered = DarkColorTokens.colorRed1000, + borderCriticalPrimary = DarkColorTokens.colorRed900, + borderCriticalSubtle = DarkColorTokens.colorRed500, + borderDisabled = DarkColorTokens.colorGray500, + borderFocused = DarkColorTokens.colorBlue900, + borderInfoSubtle = DarkColorTokens.colorBlue500, + borderInteractiveHovered = DarkColorTokens.colorGray1100, + borderInteractivePrimary = DarkColorTokens.colorGray800, + borderInteractiveSecondary = DarkColorTokens.colorGray600, + borderSuccessSubtle = DarkColorTokens.colorGreen500, + iconAccentPrimary = DarkColorTokens.colorGreen900, + iconAccentTertiary = DarkColorTokens.colorGreen800, + iconCriticalPrimary = DarkColorTokens.colorRed900, + iconDisabled = DarkColorTokens.colorGray700, + iconInfoPrimary = DarkColorTokens.colorBlue900, + iconOnSolidPrimary = DarkColorTokens.colorThemeBg, + iconPrimary = DarkColorTokens.colorGray1400, + iconPrimaryAlpha = DarkColorTokens.colorAlphaGray1400, + iconQuaternary = DarkColorTokens.colorGray700, + iconQuaternaryAlpha = DarkColorTokens.colorAlphaGray700, + iconSecondary = DarkColorTokens.colorGray900, + iconSecondaryAlpha = DarkColorTokens.colorAlphaGray900, + iconSuccessPrimary = DarkColorTokens.colorGreen900, + iconTertiary = DarkColorTokens.colorGray800, + iconTertiaryAlpha = DarkColorTokens.colorAlphaGray800, + textActionAccent = DarkColorTokens.colorGreen900, + textActionPrimary = DarkColorTokens.colorGray1400, + textCriticalPrimary = DarkColorTokens.colorRed900, + textDecorative1 = DarkColorTokens.colorLime1100, + textDecorative2 = DarkColorTokens.colorCyan1100, + textDecorative3 = DarkColorTokens.colorFuchsia1100, + textDecorative4 = DarkColorTokens.colorPurple1100, + textDecorative5 = DarkColorTokens.colorPink1100, + textDecorative6 = DarkColorTokens.colorOrange1100, + textDisabled = DarkColorTokens.colorGray800, + textInfoPrimary = DarkColorTokens.colorBlue900, + textLinkExternal = DarkColorTokens.colorBlue900, + textOnSolidPrimary = DarkColorTokens.colorThemeBg, + textPlaceholder = DarkColorTokens.colorGray800, + textPrimary = DarkColorTokens.colorGray1400, + textSecondary = DarkColorTokens.colorGray900, + textSuccessPrimary = DarkColorTokens.colorGreen900, + isLight = false, +) diff --git a/assets/android/src/SemanticColorsDarkHc.kt b/assets/android/src/SemanticColorsDarkHc.kt new file mode 100644 index 00000000..e9ef5e70 --- /dev/null +++ b/assets/android/src/SemanticColorsDarkHc.kt @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * !!! WARNING !!! + * + * THIS IS AN AUTOGENERATED FILE. + * DO NOT EDIT MANUALLY. + */ + + + +@file:Suppress("all") +package io.element.android.compound.tokens.generated + +import io.element.android.compound.annotations.CoreColorToken +import io.element.android.compound.tokens.generated.internal.DarkHcColorTokens + +/** + * Semantic colors for the high contrast dark Compound theme. + */ +@OptIn(CoreColorToken::class) +val compoundColorsHcDark = SemanticColors( + bgAccentHovered = DarkHcColorTokens.colorGreen1000, + bgAccentPressed = DarkHcColorTokens.colorGreen1100, + bgAccentRest = DarkHcColorTokens.colorGreen900, + bgActionPrimaryDisabled = DarkHcColorTokens.colorGray700, + bgActionPrimaryHovered = DarkHcColorTokens.colorGray1200, + bgActionPrimaryPressed = DarkHcColorTokens.colorGray1100, + bgActionPrimaryRest = DarkHcColorTokens.colorGray1400, + bgActionSecondaryHovered = DarkHcColorTokens.colorAlphaGray200, + bgActionSecondaryPressed = DarkHcColorTokens.colorAlphaGray300, + bgActionSecondaryRest = DarkHcColorTokens.colorThemeBg, + bgCanvasDefault = DarkHcColorTokens.colorThemeBg, + bgCanvasDisabled = DarkHcColorTokens.colorGray200, + bgCriticalHovered = DarkHcColorTokens.colorRed1000, + bgCriticalPrimary = DarkHcColorTokens.colorRed900, + bgCriticalSubtle = DarkHcColorTokens.colorRed200, + bgCriticalSubtleHovered = DarkHcColorTokens.colorRed300, + bgDecorative1 = DarkHcColorTokens.colorLime300, + bgDecorative2 = DarkHcColorTokens.colorCyan300, + bgDecorative3 = DarkHcColorTokens.colorFuchsia300, + bgDecorative4 = DarkHcColorTokens.colorPurple300, + bgDecorative5 = DarkHcColorTokens.colorPink300, + bgDecorative6 = DarkHcColorTokens.colorOrange300, + bgInfoSubtle = DarkHcColorTokens.colorBlue200, + bgSubtlePrimary = DarkHcColorTokens.colorGray400, + bgSubtleSecondary = DarkHcColorTokens.colorGray300, + bgSuccessSubtle = DarkHcColorTokens.colorGreen200, + borderCriticalHovered = DarkHcColorTokens.colorRed1000, + borderCriticalPrimary = DarkHcColorTokens.colorRed900, + borderCriticalSubtle = DarkHcColorTokens.colorRed500, + borderDisabled = DarkHcColorTokens.colorGray500, + borderFocused = DarkHcColorTokens.colorBlue900, + borderInfoSubtle = DarkHcColorTokens.colorBlue500, + borderInteractiveHovered = DarkHcColorTokens.colorGray1100, + borderInteractivePrimary = DarkHcColorTokens.colorGray800, + borderInteractiveSecondary = DarkHcColorTokens.colorGray600, + borderSuccessSubtle = DarkHcColorTokens.colorGreen500, + iconAccentPrimary = DarkHcColorTokens.colorGreen900, + iconAccentTertiary = DarkHcColorTokens.colorGreen800, + iconCriticalPrimary = DarkHcColorTokens.colorRed900, + iconDisabled = DarkHcColorTokens.colorGray700, + iconInfoPrimary = DarkHcColorTokens.colorBlue900, + iconOnSolidPrimary = DarkHcColorTokens.colorThemeBg, + iconPrimary = DarkHcColorTokens.colorGray1400, + iconPrimaryAlpha = DarkHcColorTokens.colorAlphaGray1400, + iconQuaternary = DarkHcColorTokens.colorGray700, + iconQuaternaryAlpha = DarkHcColorTokens.colorAlphaGray700, + iconSecondary = DarkHcColorTokens.colorGray900, + iconSecondaryAlpha = DarkHcColorTokens.colorAlphaGray900, + iconSuccessPrimary = DarkHcColorTokens.colorGreen900, + iconTertiary = DarkHcColorTokens.colorGray800, + iconTertiaryAlpha = DarkHcColorTokens.colorAlphaGray800, + textActionAccent = DarkHcColorTokens.colorGreen900, + textActionPrimary = DarkHcColorTokens.colorGray1400, + textCriticalPrimary = DarkHcColorTokens.colorRed900, + textDecorative1 = DarkHcColorTokens.colorLime1100, + textDecorative2 = DarkHcColorTokens.colorCyan1100, + textDecorative3 = DarkHcColorTokens.colorFuchsia1100, + textDecorative4 = DarkHcColorTokens.colorPurple1100, + textDecorative5 = DarkHcColorTokens.colorPink1100, + textDecorative6 = DarkHcColorTokens.colorOrange1100, + textDisabled = DarkHcColorTokens.colorGray800, + textInfoPrimary = DarkHcColorTokens.colorBlue900, + textLinkExternal = DarkHcColorTokens.colorBlue900, + textOnSolidPrimary = DarkHcColorTokens.colorThemeBg, + textPlaceholder = DarkHcColorTokens.colorGray800, + textPrimary = DarkHcColorTokens.colorGray1400, + textSecondary = DarkHcColorTokens.colorGray900, + textSuccessPrimary = DarkHcColorTokens.colorGreen900, + isLight = false, +) diff --git a/assets/android/src/SemanticColorsLight.kt b/assets/android/src/SemanticColorsLight.kt new file mode 100644 index 00000000..a75eed82 --- /dev/null +++ b/assets/android/src/SemanticColorsLight.kt @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * !!! WARNING !!! + * + * THIS IS AN AUTOGENERATED FILE. + * DO NOT EDIT MANUALLY. + */ + + + +@file:Suppress("all") +package io.element.android.compound.tokens.generated + +import io.element.android.compound.annotations.CoreColorToken +import io.element.android.compound.tokens.generated.internal.LightColorTokens + +/** + * Semantic colors for the light Compound theme. + */ +@OptIn(CoreColorToken::class) +val compoundColorsLight = SemanticColors( + bgAccentHovered = LightColorTokens.colorGreen1000, + bgAccentPressed = LightColorTokens.colorGreen1100, + bgAccentRest = LightColorTokens.colorGreen900, + bgActionPrimaryDisabled = LightColorTokens.colorGray700, + bgActionPrimaryHovered = LightColorTokens.colorGray1200, + bgActionPrimaryPressed = LightColorTokens.colorGray1100, + bgActionPrimaryRest = LightColorTokens.colorGray1400, + bgActionSecondaryHovered = LightColorTokens.colorAlphaGray200, + bgActionSecondaryPressed = LightColorTokens.colorAlphaGray300, + bgActionSecondaryRest = LightColorTokens.colorThemeBg, + bgCanvasDefault = LightColorTokens.colorThemeBg, + bgCanvasDisabled = LightColorTokens.colorGray200, + bgCriticalHovered = LightColorTokens.colorRed1000, + bgCriticalPrimary = LightColorTokens.colorRed900, + bgCriticalSubtle = LightColorTokens.colorRed200, + bgCriticalSubtleHovered = LightColorTokens.colorRed300, + bgDecorative1 = LightColorTokens.colorLime300, + bgDecorative2 = LightColorTokens.colorCyan300, + bgDecorative3 = LightColorTokens.colorFuchsia300, + bgDecorative4 = LightColorTokens.colorPurple300, + bgDecorative5 = LightColorTokens.colorPink300, + bgDecorative6 = LightColorTokens.colorOrange300, + bgInfoSubtle = LightColorTokens.colorBlue200, + bgSubtlePrimary = LightColorTokens.colorGray400, + bgSubtleSecondary = LightColorTokens.colorGray300, + bgSuccessSubtle = LightColorTokens.colorGreen200, + borderCriticalHovered = LightColorTokens.colorRed1000, + borderCriticalPrimary = LightColorTokens.colorRed900, + borderCriticalSubtle = LightColorTokens.colorRed500, + borderDisabled = LightColorTokens.colorGray500, + borderFocused = LightColorTokens.colorBlue900, + borderInfoSubtle = LightColorTokens.colorBlue500, + borderInteractiveHovered = LightColorTokens.colorGray1100, + borderInteractivePrimary = LightColorTokens.colorGray800, + borderInteractiveSecondary = LightColorTokens.colorGray600, + borderSuccessSubtle = LightColorTokens.colorGreen500, + iconAccentPrimary = LightColorTokens.colorGreen900, + iconAccentTertiary = LightColorTokens.colorGreen800, + iconCriticalPrimary = LightColorTokens.colorRed900, + iconDisabled = LightColorTokens.colorGray700, + iconInfoPrimary = LightColorTokens.colorBlue900, + iconOnSolidPrimary = LightColorTokens.colorThemeBg, + iconPrimary = LightColorTokens.colorGray1400, + iconPrimaryAlpha = LightColorTokens.colorAlphaGray1400, + iconQuaternary = LightColorTokens.colorGray700, + iconQuaternaryAlpha = LightColorTokens.colorAlphaGray700, + iconSecondary = LightColorTokens.colorGray900, + iconSecondaryAlpha = LightColorTokens.colorAlphaGray900, + iconSuccessPrimary = LightColorTokens.colorGreen900, + iconTertiary = LightColorTokens.colorGray800, + iconTertiaryAlpha = LightColorTokens.colorAlphaGray800, + textActionAccent = LightColorTokens.colorGreen900, + textActionPrimary = LightColorTokens.colorGray1400, + textCriticalPrimary = LightColorTokens.colorRed900, + textDecorative1 = LightColorTokens.colorLime1100, + textDecorative2 = LightColorTokens.colorCyan1100, + textDecorative3 = LightColorTokens.colorFuchsia1100, + textDecorative4 = LightColorTokens.colorPurple1100, + textDecorative5 = LightColorTokens.colorPink1100, + textDecorative6 = LightColorTokens.colorOrange1100, + textDisabled = LightColorTokens.colorGray800, + textInfoPrimary = LightColorTokens.colorBlue900, + textLinkExternal = LightColorTokens.colorBlue900, + textOnSolidPrimary = LightColorTokens.colorThemeBg, + textPlaceholder = LightColorTokens.colorGray800, + textPrimary = LightColorTokens.colorGray1400, + textSecondary = LightColorTokens.colorGray900, + textSuccessPrimary = LightColorTokens.colorGreen900, + isLight = true, +) diff --git a/assets/android/src/SemanticColorsLightHc.kt b/assets/android/src/SemanticColorsLightHc.kt new file mode 100644 index 00000000..27815570 --- /dev/null +++ b/assets/android/src/SemanticColorsLightHc.kt @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * !!! WARNING !!! + * + * THIS IS AN AUTOGENERATED FILE. + * DO NOT EDIT MANUALLY. + */ + + + +@file:Suppress("all") +package io.element.android.compound.tokens.generated + +import io.element.android.compound.annotations.CoreColorToken +import io.element.android.compound.tokens.generated.internal.LightHcColorTokens + +/** + * Semantic colors for the high contrast light Compound theme. + */ +@OptIn(CoreColorToken::class) +val compoundColorsHcLight = SemanticColors( + bgAccentHovered = LightHcColorTokens.colorGreen1000, + bgAccentPressed = LightHcColorTokens.colorGreen1100, + bgAccentRest = LightHcColorTokens.colorGreen900, + bgActionPrimaryDisabled = LightHcColorTokens.colorGray700, + bgActionPrimaryHovered = LightHcColorTokens.colorGray1200, + bgActionPrimaryPressed = LightHcColorTokens.colorGray1100, + bgActionPrimaryRest = LightHcColorTokens.colorGray1400, + bgActionSecondaryHovered = LightHcColorTokens.colorAlphaGray200, + bgActionSecondaryPressed = LightHcColorTokens.colorAlphaGray300, + bgActionSecondaryRest = LightHcColorTokens.colorThemeBg, + bgCanvasDefault = LightHcColorTokens.colorThemeBg, + bgCanvasDisabled = LightHcColorTokens.colorGray200, + bgCriticalHovered = LightHcColorTokens.colorRed1000, + bgCriticalPrimary = LightHcColorTokens.colorRed900, + bgCriticalSubtle = LightHcColorTokens.colorRed200, + bgCriticalSubtleHovered = LightHcColorTokens.colorRed300, + bgDecorative1 = LightHcColorTokens.colorLime300, + bgDecorative2 = LightHcColorTokens.colorCyan300, + bgDecorative3 = LightHcColorTokens.colorFuchsia300, + bgDecorative4 = LightHcColorTokens.colorPurple300, + bgDecorative5 = LightHcColorTokens.colorPink300, + bgDecorative6 = LightHcColorTokens.colorOrange300, + bgInfoSubtle = LightHcColorTokens.colorBlue200, + bgSubtlePrimary = LightHcColorTokens.colorGray400, + bgSubtleSecondary = LightHcColorTokens.colorGray300, + bgSuccessSubtle = LightHcColorTokens.colorGreen200, + borderCriticalHovered = LightHcColorTokens.colorRed1000, + borderCriticalPrimary = LightHcColorTokens.colorRed900, + borderCriticalSubtle = LightHcColorTokens.colorRed500, + borderDisabled = LightHcColorTokens.colorGray500, + borderFocused = LightHcColorTokens.colorBlue900, + borderInfoSubtle = LightHcColorTokens.colorBlue500, + borderInteractiveHovered = LightHcColorTokens.colorGray1100, + borderInteractivePrimary = LightHcColorTokens.colorGray800, + borderInteractiveSecondary = LightHcColorTokens.colorGray600, + borderSuccessSubtle = LightHcColorTokens.colorGreen500, + iconAccentPrimary = LightHcColorTokens.colorGreen900, + iconAccentTertiary = LightHcColorTokens.colorGreen800, + iconCriticalPrimary = LightHcColorTokens.colorRed900, + iconDisabled = LightHcColorTokens.colorGray700, + iconInfoPrimary = LightHcColorTokens.colorBlue900, + iconOnSolidPrimary = LightHcColorTokens.colorThemeBg, + iconPrimary = LightHcColorTokens.colorGray1400, + iconPrimaryAlpha = LightHcColorTokens.colorAlphaGray1400, + iconQuaternary = LightHcColorTokens.colorGray700, + iconQuaternaryAlpha = LightHcColorTokens.colorAlphaGray700, + iconSecondary = LightHcColorTokens.colorGray900, + iconSecondaryAlpha = LightHcColorTokens.colorAlphaGray900, + iconSuccessPrimary = LightHcColorTokens.colorGreen900, + iconTertiary = LightHcColorTokens.colorGray800, + iconTertiaryAlpha = LightHcColorTokens.colorAlphaGray800, + textActionAccent = LightHcColorTokens.colorGreen900, + textActionPrimary = LightHcColorTokens.colorGray1400, + textCriticalPrimary = LightHcColorTokens.colorRed900, + textDecorative1 = LightHcColorTokens.colorLime1100, + textDecorative2 = LightHcColorTokens.colorCyan1100, + textDecorative3 = LightHcColorTokens.colorFuchsia1100, + textDecorative4 = LightHcColorTokens.colorPurple1100, + textDecorative5 = LightHcColorTokens.colorPink1100, + textDecorative6 = LightHcColorTokens.colorOrange1100, + textDisabled = LightHcColorTokens.colorGray800, + textInfoPrimary = LightHcColorTokens.colorBlue900, + textLinkExternal = LightHcColorTokens.colorBlue900, + textOnSolidPrimary = LightHcColorTokens.colorThemeBg, + textPlaceholder = LightHcColorTokens.colorGray800, + textPrimary = LightHcColorTokens.colorGray1400, + textSecondary = LightHcColorTokens.colorGray900, + textSuccessPrimary = LightHcColorTokens.colorGreen900, + isLight = true, +) diff --git a/src/configs/getAndroidConfig.ts b/src/configs/getAndroidConfig.ts index 60d007e9..387a8b57 100644 --- a/src/configs/getAndroidConfig.ts +++ b/src/configs/getAndroidConfig.ts @@ -59,6 +59,13 @@ function composeCoreColors(args: FormatterArguments) { ); } +function composeSemanticColors(args: FormatterArguments) { + return createTemplate( + "../formats/templates/compose/semantic-colors.kt.template", + args + ); +} + function composeIcons(args: FormatterArguments) { return createTemplate( "../formats/templates/compose/icons.kt.template", @@ -104,11 +111,50 @@ export function getAndroidConfig(theme: Theme): Platform { name: "compose/core-colors", formatter: composeCoreColors, }); + StyleDictionary.registerFormat({ + name: "compose/semantic-colors", + formatter: composeSemanticColors, + }); StyleDictionary.registerFormat({ name: "compose/icons", formatter: composeIcons, }); const className = _.upperFirst(_.camelCase(theme)); + let valName = ""; + let themeName = ""; + let tokenClassName = ""; + switch(className) { + case "Light": { + valName = "compoundColorsLight"; + themeName = "light"; + tokenClassName = "LightColorTokens"; + break; + } + case "LightHc": { + valName = "compoundColorsHcLight"; + themeName = "high contrast light"; + tokenClassName = "LightHcColorTokens"; + break; + } + case "Dark": { + valName = "compoundColorsDark"; + themeName = "dark"; + tokenClassName = "DarkColorTokens"; + break; + } + case "DarkHc": { + valName = "compoundColorsHcDark"; + themeName = "high contrast dark"; + tokenClassName = "DarkHcColorTokens"; + break; + } + default: { + valName = "Error"; + themeName = "Error"; + tokenClassName = "Error"; + break; + } + } return { transforms: [ "camelCaseDecimal", @@ -134,6 +180,27 @@ export function getAndroidConfig(theme: Theme): Platform { isInternal: true, }), }, + { + format: "compose/semantic-colors", + destination: `SemanticColors${className}.kt`, + className: className + "ColorTokens", + packageName: packageName, + filter: function (token: TransformedToken) { + return token.type == "color" && isNotCoreColor.matcher(token); + }, + options: withDefaultOptions({ + outputReferences: true, + import: [ + "io.element.android.compound.annotations.CoreColorToken", + "io.element.android.compound.tokens.generated.internal." + tokenClassName + ], + isInternal: true, + valName: valName, + themeName: themeName, + tokenClassName: tokenClassName, + isLight: className.startsWith("Light"), + }), + }, // If we find a way to describe semantic colors, it might be possible to move this to 'common' { format: "compose/extra-colors", diff --git a/src/formats/templates/compose/semantic-colors.kt.template b/src/formats/templates/compose/semantic-colors.kt.template new file mode 100644 index 00000000..7322aede --- /dev/null +++ b/src/formats/templates/compose/semantic-colors.kt.template @@ -0,0 +1,25 @@ +<%= options.license ?? '' %> +<%= fileHeader({file, commentStyle: 'long'}) %> + +@file:Suppress("all") +package <%= file.packageName %> + +<%= options.import.map(function(item) { + return 'import ' + item + }).join('\n') +%> + +/** + * Semantic colors for the <%= options.themeName %> Compound theme. + */ +@OptIn(CoreColorToken::class) +val <%= options.valName %> = SemanticColors( + <%= allProperties.map(function(prop) { + let result = formatProperty(prop) + result = result + .replace("= ", "= " + options.tokenClassName + ".") + .replace("color", "") + return result[0].toLowerCase() + result.slice(1); + }).sort().join(',\n' + options.indentLevel ) %>, + isLight = <%= options.isLight %>, +)