diff --git a/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenCategory.kt b/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenCategory.kt index cfbff986..15002602 100644 --- a/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenCategory.kt +++ b/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenCategory.kt @@ -16,11 +16,11 @@ import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.compose.runtime.Immutable import com.orange.ouds.app.R -import com.orange.ouds.app.ui.utilities.getTokenName import com.orange.ouds.theme.tokens.OudsBorderKeyToken import com.orange.ouds.theme.tokens.OudsColorKeyToken import com.orange.ouds.theme.tokens.OudsElevationKeyToken import com.orange.ouds.theme.tokens.OudsGridKeyToken +import com.orange.ouds.theme.tokens.OudsKeyToken import com.orange.ouds.theme.tokens.OudsOpacityKeyToken import com.orange.ouds.theme.tokens.OudsSizeKeyToken import com.orange.ouds.theme.tokens.OudsSpaceKeyToken @@ -50,7 +50,7 @@ sealed class TokenCategory( R.string.app_tokens_border_label, R.drawable.ic_border, R.string.app_tokens_border_description_text, - getTokenValueCode(), + getTokenValueCode(OudsBorderKeyToken.Width.None), listOf(TokenProperty.BorderWidth, TokenProperty.BorderRadius, TokenProperty.BorderStyle), ) @@ -58,7 +58,7 @@ sealed class TokenCategory( R.string.app_tokens_color_label, R.drawable.ic_palette, R.string.app_tokens_color_description_text, - getTokenValueCode(), + getTokenValueCode(OudsColorKeyToken.Action.Disabled), listOf( TokenProperty.ColorAction, TokenProperty.ColorAlways, @@ -81,7 +81,7 @@ sealed class TokenCategory( R.string.app_tokens_dimension_space_label, R.drawable.ic_dimension, R.string.app_tokens_dimension_space_description_text, - getTokenValueCode(), + getTokenValueCode(OudsSpaceKeyToken.Scaled.None), listOf( TokenProperty.SpaceScaled, TokenProperty.SpaceFixed, @@ -97,7 +97,7 @@ sealed class TokenCategory( R.string.app_tokens_dimension_size_label, R.drawable.ic_dimension, R.string.app_tokens_dimension_size_description_text, - getTokenValueCode(), + getTokenValueCode(OudsSizeKeyToken.Icon.Decorative.ExtraExtraSmall), listOf(TokenProperty.SizeIconDecorative, TokenProperty.SizeIconWithText), ) } @@ -106,7 +106,7 @@ sealed class TokenCategory( R.string.app_tokens_elevation_label, R.drawable.ic_layers, R.string.app_tokens_elevation_description_text, - getTokenValueCode(), + getTokenValueCode(OudsElevationKeyToken.None), listOf(TokenProperty.Elevation) ) @@ -114,7 +114,7 @@ sealed class TokenCategory( R.string.app_tokens_grid_label, R.drawable.ic_menu_grid, R.string.app_tokens_grid_description_text, - getTokenValueCode(), + getTokenValueCode(OudsGridKeyToken.MinWidth), listOf(TokenProperty.Grid) ) @@ -122,7 +122,7 @@ sealed class TokenCategory( R.string.app_tokens_opacity_label, R.drawable.ic_filter_effects, R.string.app_tokens_opacity_description_text, - getTokenValueCode(), + getTokenValueCode(OudsOpacityKeyToken.Invisible), listOf(TokenProperty.Opacity) ) @@ -130,9 +130,9 @@ sealed class TokenCategory( R.string.app_tokens_typography_label, R.drawable.ic_typography, R.string.app_tokens_typography_description_text, - getTokenValueCode(), + getTokenValueCode(OudsTypographyKeyToken.Display.Large), listOf(TokenProperty.Typography) ) } -private inline fun getTokenValueCode() = "${T::class.getTokenName()}.value" \ No newline at end of file +private fun getTokenValueCode(keyToken: OudsKeyToken) = "${keyToken.name}.value" \ No newline at end of file diff --git a/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenProperty.kt b/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenProperty.kt index 9940a412..9a60bceb 100644 --- a/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenProperty.kt +++ b/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenProperty.kt @@ -14,12 +14,13 @@ package com.orange.ouds.app.ui.tokens import androidx.annotation.StringRes import com.orange.ouds.app.R -import com.orange.ouds.app.ui.utilities.getTokenName -import com.orange.ouds.app.ui.utilities.getTokens +import com.orange.ouds.app.ui.utilities.getSealedSubclasses +import com.orange.ouds.core.theme.value import com.orange.ouds.theme.tokens.OudsBorderKeyToken import com.orange.ouds.theme.tokens.OudsColorKeyToken import com.orange.ouds.theme.tokens.OudsElevationKeyToken import com.orange.ouds.theme.tokens.OudsGridKeyToken +import com.orange.ouds.theme.tokens.OudsKeyToken import com.orange.ouds.theme.tokens.OudsOpacityKeyToken import com.orange.ouds.theme.tokens.OudsSizeKeyToken import com.orange.ouds.theme.tokens.OudsSpaceKeyToken @@ -34,91 +35,91 @@ sealed class TokenProperty( data object BorderRadius : TokenProperty( nameRes = R.string.app_tokens_border_radius_label, - tokens = OudsBorderKeyToken.Radius::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Border::class ) data object BorderStyle : TokenProperty( nameRes = R.string.app_tokens_border_style_label, - tokens = OudsBorderKeyToken.Style::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Border::class ) data object BorderWidth : TokenProperty( nameRes = R.string.app_tokens_border_width_label, - tokens = OudsBorderKeyToken.Width::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Border::class ) data object ColorAction : TokenProperty( nameRes = R.string.app_tokens_color_action_label, - tokens = OudsColorKeyToken.Action::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Color::class ) data object ColorAlways : TokenProperty( nameRes = R.string.app_tokens_color_always_label, - tokens = OudsColorKeyToken.Always::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Color::class ) data object ColorBackground : TokenProperty( nameRes = R.string.app_tokens_color_background_label, - tokens = OudsColorKeyToken.Background::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Color::class ) data object ColorBorder : TokenProperty( nameRes = R.string.app_tokens_color_border_label, - tokens = OudsColorKeyToken.Border::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Color::class ) data object ColorContent : TokenProperty( nameRes = R.string.app_tokens_color_content_label, - tokens = OudsColorKeyToken.Content::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Color::class ) data object ColorDecorative : TokenProperty( nameRes = R.string.app_tokens_color_decorative_label, - tokens = OudsColorKeyToken.Decorative::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Color::class ) data object ColorOverlay : TokenProperty( nameRes = R.string.app_tokens_color_overlay_label, - tokens = OudsColorKeyToken.Overlay::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Color::class ) data object ColorSurface : TokenProperty( nameRes = R.string.app_tokens_color_surface_label, - tokens = OudsColorKeyToken.Surface::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Color::class ) data object Elevation : TokenProperty( nameRes = null, - tokens = OudsElevationKeyToken::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Elevation::class ) data object Grid : TokenProperty( nameRes = null, - tokens = OudsGridKeyToken::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Grid::class ) data object Opacity : TokenProperty( nameRes = null, - tokens = OudsOpacityKeyToken::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Opacity::class ) data object SizeIconDecorative : TokenProperty( nameRes = R.string.app_tokens_dimension_size_iconDecorative_label, - tokens = OudsSizeKeyToken.Icon.Decorative::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Dimension.Size::class ) @@ -137,60 +138,118 @@ sealed class TokenProperty( OudsSizeKeyToken.Icon.WithLabel.Medium::class, OudsSizeKeyToken.Icon.WithLabel.Small::class, ).flatMap { keyTokenClass -> - keyTokenClass.getTokens(tokenName = { it.getTokenName(OudsSizeKeyToken.Icon::class).removePrefix("With") }) + getTokens(keyTokenClass, tokenName = { it.getRelativeName(OudsSizeKeyToken.Icon::class).removePrefix("With") }) }, categoryClass = TokenCategory.Dimension.Size::class ) data object SpaceColumnGap : TokenProperty( nameRes = R.string.app_tokens_dimension_space_columnGap_label, - tokens = OudsSpaceKeyToken.ColumnGap::class.getTokens(recursive = false), + tokens = getTokens(recursive = false), categoryClass = TokenCategory.Dimension.Space::class ) data object SpaceFixed : TokenProperty( nameRes = R.string.app_tokens_dimension_space_fixed_label, - tokens = OudsSpaceKeyToken.Fixed::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Dimension.Space::class ) data object SpacePaddingInline : TokenProperty( nameRes = R.string.app_tokens_dimension_space_paddingInline_label, - tokens = OudsSpaceKeyToken.PaddingInline::class.getTokens(recursive = false), + tokens = getTokens(recursive = false), categoryClass = TokenCategory.Dimension.Space::class ) data object SpacePaddingInset : TokenProperty( nameRes = R.string.app_tokens_dimension_space_paddingInset_label, - tokens = OudsSpaceKeyToken.Inset::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Dimension.Space::class ) data object SpacePaddingStack : TokenProperty( nameRes = R.string.app_tokens_dimension_space_paddingStack_label, - tokens = OudsSpaceKeyToken.PaddingBlock::class.getTokens(recursive = false), + tokens = getTokens(recursive = false), categoryClass = TokenCategory.Dimension.Space::class ) data object SpaceRowGap : TokenProperty( nameRes = R.string.app_tokens_dimension_space_rowGap_label, - tokens = OudsSpaceKeyToken.RowGap::class.getTokens(recursive = false), + tokens = getTokens(recursive = false), categoryClass = TokenCategory.Dimension.Space::class ) data object SpaceScaled : TokenProperty( nameRes = R.string.app_tokens_dimension_space_scaled_label, - tokens = OudsSpaceKeyToken.Scaled::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Dimension.Space::class ) data object Typography : TokenProperty( nameRes = null, - tokens = OudsTypographyKeyToken::class.getTokens(), + tokens = getTokens(), categoryClass = TokenCategory.Typography::class ) } +inline fun getTokens( + recursive: Boolean = true, + noinline tokenName: (T) -> String = { it.getRelativeName(T::class) } +): List> where T : OudsKeyToken { + return getTokens(T::class, recursive, tokenName) +} + +fun getTokens( + clazz: KClass, + recursive: Boolean = true, + tokenName: (T) -> String = { it.getRelativeName(clazz) } +): List> where T : OudsKeyToken { + return clazz.getSealedSubclasses(recursive) + .mapNotNull { it.objectInstance } + .sortedBy { keyToken -> + when (keyToken) { + is OudsBorderKeyToken.Radius -> keyToken.order + is OudsBorderKeyToken.Width -> keyToken.order + is OudsElevationKeyToken -> keyToken.order + is OudsOpacityKeyToken -> keyToken.order + is OudsSizeKeyToken.Icon -> keyToken.order + is OudsSpaceKeyToken.ColumnGap -> keyToken.order + is OudsSpaceKeyToken.Fixed -> keyToken.order + is OudsSpaceKeyToken.Inset -> keyToken.order + is OudsSpaceKeyToken.PaddingBlock -> keyToken.order + is OudsSpaceKeyToken.PaddingInline -> keyToken.order + is OudsSpaceKeyToken.RowGap -> keyToken.order + is OudsSpaceKeyToken.Scaled -> keyToken.order + else -> 0 + } + }.map { keyToken -> + Token( + name = tokenName(keyToken), + value = { + when (keyToken) { + is OudsBorderKeyToken.Radius -> keyToken.value + is OudsBorderKeyToken.Style -> keyToken.value + is OudsBorderKeyToken.Width -> keyToken.value + is OudsColorKeyToken -> keyToken.value + is OudsElevationKeyToken -> keyToken.value + is OudsGridKeyToken -> keyToken.value + is OudsOpacityKeyToken -> keyToken.value + is OudsSizeKeyToken -> keyToken.value + is OudsSpaceKeyToken -> keyToken.value + is OudsTypographyKeyToken -> keyToken.value + else -> null + } + } + ) + } +} + +fun T.getRelativeName(parent: KClass): String where T : S, S : OudsKeyToken { + val parentPackageName = parent.java.`package`?.name.orEmpty() + val prefix = parent.qualifiedName.orEmpty().removePrefix("$parentPackageName.") + return name.removePrefix("$prefix.") +} + val OudsBorderKeyToken.Radius.order: Int get() = when (this) { OudsBorderKeyToken.Radius.None -> 0 diff --git a/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenPropertyIllustration.kt b/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenPropertyIllustration.kt index ee49a358..10dc9af2 100644 --- a/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenPropertyIllustration.kt +++ b/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenPropertyIllustration.kt @@ -43,7 +43,6 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.orange.ouds.app.R -import com.orange.ouds.app.ui.utilities.getTokens import com.orange.ouds.core.theme.value import com.orange.ouds.foundation.extensions.asOrNull import com.orange.ouds.foundation.extensions.orElse @@ -137,7 +136,7 @@ fun SizeIconWithTextIllustrationRow(size: Dp, tokenName: String) { contentDescription = null ) val tokenTypography = tokenName.split('.').take(2).joinToString(".") - val style = OudsTypographyKeyToken::class.getTokens() + val style = getTokens() .asOrNull>>() ?.firstOrNull { typographyToken -> typographyToken.name.replace(".Strong", "") == tokenTypography diff --git a/app/src/main/java/com/orange/ouds/app/ui/utilities/KClassExt.kt b/app/src/main/java/com/orange/ouds/app/ui/utilities/KClassExt.kt index 2c661a2b..5509c50c 100644 --- a/app/src/main/java/com/orange/ouds/app/ui/utilities/KClassExt.kt +++ b/app/src/main/java/com/orange/ouds/app/ui/utilities/KClassExt.kt @@ -12,88 +12,12 @@ package com.orange.ouds.app.ui.utilities -import com.orange.ouds.app.ui.tokens.Token -import com.orange.ouds.app.ui.tokens.order -import com.orange.ouds.core.theme.value -import com.orange.ouds.foundation.extensions.asOrNull -import com.orange.ouds.foundation.extensions.orElse -import com.orange.ouds.theme.tokens.OudsBorderKeyToken -import com.orange.ouds.theme.tokens.OudsColorKeyToken -import com.orange.ouds.theme.tokens.OudsElevationKeyToken -import com.orange.ouds.theme.tokens.OudsGridKeyToken -import com.orange.ouds.theme.tokens.OudsOpacityKeyToken -import com.orange.ouds.theme.tokens.OudsSizeKeyToken -import com.orange.ouds.theme.tokens.OudsSpaceKeyToken -import com.orange.ouds.theme.tokens.OudsTypographyKeyToken import kotlin.reflect.KClass -fun KClass<*>.getTokens( - recursive: Boolean = true, - tokenName: (KClass<*>) -> String = { it.getTokenName(this) } -): List> { - return getNestedObjects(getRootKeyTokenSuperclass(), recursive).sortedBy { keyToken -> - when (keyToken) { - is OudsBorderKeyToken.Radius -> keyToken.order - is OudsBorderKeyToken.Width -> keyToken.order - is OudsElevationKeyToken -> keyToken.order - is OudsOpacityKeyToken -> keyToken.order - is OudsSizeKeyToken.Icon -> keyToken.order - is OudsSpaceKeyToken.ColumnGap -> keyToken.order - is OudsSpaceKeyToken.Fixed -> keyToken.order - is OudsSpaceKeyToken.Inset -> keyToken.order - is OudsSpaceKeyToken.PaddingBlock -> keyToken.order - is OudsSpaceKeyToken.PaddingInline -> keyToken.order - is OudsSpaceKeyToken.RowGap -> keyToken.order - is OudsSpaceKeyToken.Scaled -> keyToken.order - else -> 0 - } - }.map { keyToken -> - Token( - name = tokenName(keyToken::class), - value = { - when (keyToken) { - is OudsBorderKeyToken.Radius -> keyToken.value - is OudsBorderKeyToken.Style -> keyToken.value - is OudsBorderKeyToken.Width -> keyToken.value - is OudsColorKeyToken -> keyToken.value - is OudsElevationKeyToken -> keyToken.value - is OudsGridKeyToken -> keyToken.value - is OudsOpacityKeyToken -> keyToken.value - is OudsSizeKeyToken -> keyToken.value - is OudsSpaceKeyToken -> keyToken.value - is OudsTypographyKeyToken -> keyToken.value - else -> null - } - } - ) - } -} - -fun KClass<*>.getTokenName(fromParent: KClass<*>? = null): String { - val prefix = if (fromParent != null) "${fromParent.qualifiedName.orEmpty()}." else "${java.`package`?.name.orEmpty()}." - - return qualifiedName.orEmpty() - .removePrefix(prefix) - .removeSuffix(".Companion") -} - -private fun KClass<*>.getNestedObjects(clazz: KClass, recursive: Boolean = true): List { - return getNestedClasses(recursive).mapNotNull { it.objectInstance }.filterIsInstance(clazz.java) -} - -private fun KClass<*>.getNestedClasses(recursive: Boolean = true): List> { +fun KClass.getSealedSubclasses(recursive: Boolean = true): List> { return if (recursive) { - nestedClasses + nestedClasses.flatMap { it.getNestedClasses(recursive = true) } + sealedSubclasses + sealedSubclasses.flatMap { it.getSealedSubclasses(recursive = true) } } else { - nestedClasses.toList() + sealedSubclasses.toList() } } - -private fun KClass<*>.getRootKeyTokenSuperclass(): KClass<*> { - return supertypes.firstOrNull() - ?.classifier - ?.asOrNull>() - ?.takeIf { it != Any::class } - ?.getRootKeyTokenSuperclass() - .orElse { this } -} diff --git a/core/src/main/java/com/orange/ouds/core/component/coloredbox/OudsColoredBox.kt b/core/src/main/java/com/orange/ouds/core/component/coloredbox/OudsColoredBox.kt new file mode 100644 index 00000000..08c6dbdb --- /dev/null +++ b/core/src/main/java/com/orange/ouds/core/component/coloredbox/OudsColoredBox.kt @@ -0,0 +1,136 @@ +/* + * Software Name: OUDS Android + * SPDX-FileCopyrightText: Copyright (c) Orange SA + * SPDX-License-Identifier: MIT + * + * This software is distributed under the MIT license, + * the text of which is available at https://opensource.org/license/MIT/ + * or see the "LICENSE" file for more details. + * + * Software description: Android library of reusable graphical components + */ + +package com.orange.ouds.core.component.coloredbox + +import androidx.compose.foundation.background +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.BoxScope +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.LocalContentColor +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.unit.dp +import com.orange.ouds.core.component.button.OudsButton +import com.orange.ouds.core.theme.LocalColoredBox +import com.orange.ouds.core.theme.value +import com.orange.ouds.core.utilities.OudsPreview +import com.orange.ouds.foundation.utilities.BasicPreviewParameterProvider +import com.orange.ouds.foundation.utilities.UiModePreviews +import com.orange.ouds.theme.tokens.OudsColorKeyToken +import com.orange.ouds.theme.tokens.OudsSpaceKeyToken + +/** + * An OUDS colored box is a [Box] where content color is automatically adjusted to maximize the contrast with the chosen background [color]. + * + * Moreover, the colors of several OUDS components (for instance [OudsButton]) are also automatically adjusted. + * Some tokens associated with these colors can be customized and are identified with the `Mono` suffix (for instance `colorBgDefaultEnabledMono` in `OudsButtonTokens`). + * + * @param color The background color. + * @param modifier Modifier to be applied to the layout corresponding to the colored box. + * @param contentAlignment The default alignment inside the colored box. + * @param propagateMinConstraints Whether the incoming min constraints should be passed to content. + * @param content The content of this colored box. + * + * @sample com.orange.ouds.core.component.samples.SimpleOudsColoredBox + */ +@Composable +fun OudsColoredBox( + color: OudsColorKeyToken.Surface, + modifier: Modifier = Modifier, + contentAlignment: Alignment = Alignment.TopStart, + propagateMinConstraints: Boolean = false, + content: @Composable BoxScope.() -> Unit +) { + CompositionLocalProvider( + LocalContentColor provides contentColorFor(color), + LocalColoredBox provides true + ) { + // Filter the background modifiers in order to force the background color + // We could theoretically apply the background color after the modifier but in practise a hairline is still visible + val filteredModifier = modifier.foldIn(Modifier) { result, element -> + if (element::class.simpleName != "BackgroundElement") result.then(element) else result + } + Box( + modifier = Modifier + .background(color.value) // Set the background color first, otherwise padding (if any) is wrongly applied + .then(filteredModifier), + contentAlignment = contentAlignment, + propagateMinConstraints = propagateMinConstraints, + content = content + ) + } +} + +@Composable +private fun contentColorFor(color: OudsColorKeyToken.Surface): Color { + return when (color) { + OudsColorKeyToken.Surface.Brand.Primary -> OudsColorKeyToken.Content.OnBrand.Primary + OudsColorKeyToken.Surface.Status.Accent.Emphasized, + OudsColorKeyToken.Surface.Status.Info.Emphasized, + OudsColorKeyToken.Surface.Status.Negative.Emphasized, + OudsColorKeyToken.Surface.Status.Positive.Emphasized, + OudsColorKeyToken.Surface.Status.Warning.Emphasized -> OudsColorKeyToken.Content.OnStatus.Emphasized + OudsColorKeyToken.Surface.Status.Neutral.Emphasized -> OudsColorKeyToken.Content.OnStatus.EmphasizedNeutral + OudsColorKeyToken.Surface.Status.Accent.Muted, + OudsColorKeyToken.Surface.Status.Info.Muted, + OudsColorKeyToken.Surface.Status.Negative.Muted, + OudsColorKeyToken.Surface.Status.Positive.Muted, + OudsColorKeyToken.Surface.Status.Neutral.Muted, + OudsColorKeyToken.Surface.Status.Warning.Muted -> OudsColorKeyToken.Content.OnStatus.Muted + }.value +} + +@Suppress("PreviewShouldNotBeCalledRecursively") +@UiModePreviews.Default +@Composable +private fun PreviewOudsColoredBox(@PreviewParameter(OudsColoredBoxPreviewParameterProvider::class) parameter: OudsColorKeyToken.Surface) { + PreviewOudsColoredBox(darkThemeEnabled = isSystemInDarkTheme(), parameter = parameter) +} + +@Composable +internal fun PreviewOudsColoredBox( + darkThemeEnabled: Boolean, + parameter: OudsColorKeyToken.Surface +) = OudsPreview(modifier = Modifier.padding(16.dp), darkThemeEnabled = darkThemeEnabled) { + OudsColoredBox(color = parameter) { + Text( + modifier = Modifier.padding(all = OudsSpaceKeyToken.Fixed.Medium.value), + text = parameter.name.removePrefix("OudsColorKeyToken."), + ) + } +} + +internal class OudsColoredBoxPreviewParameterProvider : BasicPreviewParameterProvider(*previewParameterValues.toTypedArray()) + +private val previewParameterValues: List + get() = listOf( + OudsColorKeyToken.Surface.Brand.Primary, + OudsColorKeyToken.Surface.Status.Accent.Emphasized, + OudsColorKeyToken.Surface.Status.Accent.Muted, + OudsColorKeyToken.Surface.Status.Info.Emphasized, + OudsColorKeyToken.Surface.Status.Info.Muted, + OudsColorKeyToken.Surface.Status.Negative.Emphasized, + OudsColorKeyToken.Surface.Status.Negative.Muted, + OudsColorKeyToken.Surface.Status.Neutral.Emphasized, + OudsColorKeyToken.Surface.Status.Neutral.Muted, + OudsColorKeyToken.Surface.Status.Positive.Emphasized, + OudsColorKeyToken.Surface.Status.Positive.Muted, + OudsColorKeyToken.Surface.Status.Warning.Emphasized, + OudsColorKeyToken.Surface.Status.Warning.Muted, + ) diff --git a/core/src/main/java/com/orange/ouds/core/component/samples/OudsColoredBoxSample.kt b/core/src/main/java/com/orange/ouds/core/component/samples/OudsColoredBoxSample.kt new file mode 100644 index 00000000..f1665584 --- /dev/null +++ b/core/src/main/java/com/orange/ouds/core/component/samples/OudsColoredBoxSample.kt @@ -0,0 +1,26 @@ +/* + * Software Name: OUDS Android + * SPDX-FileCopyrightText: Copyright (c) Orange SA + * SPDX-License-Identifier: MIT + * + * This software is distributed under the MIT license, + * the text of which is available at https://opensource.org/license/MIT/ + * or see the "LICENSE" file for more details. + * + * Software description: Android library of reusable graphical components + */ + +package com.orange.ouds.core.component.samples + +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import com.orange.ouds.core.component.coloredbox.OudsColoredBox +import com.orange.ouds.theme.tokens.OudsColorKeyToken + +@Composable +fun SimpleOudsColoredBox() { + OudsColoredBox(color = OudsColorKeyToken.Surface.Status.Info.Emphasized) { + // From this point LocalContentColor is automatically adjusted to maximize the contrast with OudsColorKeyToken.Surface.Status.Info.Emphasized + Text("Text") + } +} diff --git a/core/src/main/java/com/orange/ouds/core/theme/OudsTheme.kt b/core/src/main/java/com/orange/ouds/core/theme/OudsTheme.kt index fea18327..42238243 100644 --- a/core/src/main/java/com/orange/ouds/core/theme/OudsTheme.kt +++ b/core/src/main/java/com/orange/ouds/core/theme/OudsTheme.kt @@ -40,6 +40,7 @@ private val LocalOpacities = staticCompositionLocalOf { missingCo private val LocalSizes = staticCompositionLocalOf { missingCompositionLocalError("LocalSizes") } private val LocalSpaces = staticCompositionLocalOf { missingCompositionLocalError("LocalSpaces") } private val LocalComponentsTokens = staticCompositionLocalOf { missingCompositionLocalError("LocalComponentsTokens") } +internal val LocalColoredBox = staticCompositionLocalOf { false } object OudsTheme { @@ -111,7 +112,6 @@ fun OudsTheme( darkThemeEnabled: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit ) { - val colorScheme = if (darkThemeEnabled) themeContract.colorTokens.darkColorScheme else themeContract.colorTokens.lightColorScheme val materialColorScheme = if (darkThemeEnabled) materialDarkColorScheme else materialLightColorScheme diff --git a/core/src/test/java/com/orange/ouds/core/component/coloredbox/OudsColoredBoxTest.kt b/core/src/test/java/com/orange/ouds/core/component/coloredbox/OudsColoredBoxTest.kt new file mode 100644 index 00000000..53164b6c --- /dev/null +++ b/core/src/test/java/com/orange/ouds/core/component/coloredbox/OudsColoredBoxTest.kt @@ -0,0 +1,54 @@ +/* + * Software Name: OUDS Android + * SPDX-FileCopyrightText: Copyright (c) Orange SA + * SPDX-License-Identifier: MIT + * + * This software is distributed under the MIT license, + * the text of which is available at https://opensource.org/license/MIT/ + * or see the "LICENSE" file for more details. + * + * Software description: Android library of reusable graphical components + */ + +package com.orange.ouds.core.component.coloredbox + +import app.cash.paparazzi.Paparazzi +import com.android.ide.common.rendering.api.SessionParams +import com.orange.ouds.theme.tokens.OudsColorKeyToken +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +@RunWith(Parameterized::class) +internal class OudsColoredBoxTest(private val parameter: OudsColorKeyToken.Surface) { + + companion object { + @JvmStatic + @Parameterized.Parameters + internal fun data() = OudsColoredBoxPreviewParameterProvider().values.toList() + } + + @get:Rule + val paparazzi = Paparazzi(renderingMode = SessionParams.RenderingMode.SHRINK, maxPercentDifference = 0.0) + + @Test + fun takeOudsColoredBoxLightThemeSnapshot() { + paparazzi.snapshot { + PreviewOudsColoredBox( + darkThemeEnabled = false, + parameter = parameter + ) + } + } + + @Test + fun takeOudsColoredBoxDarkThemeSnapshot() { + paparazzi.snapshot { + PreviewOudsColoredBox( + darkThemeEnabled = true, + parameter = parameter + ) + } + } +} diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[0].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[0].png new file mode 100644 index 00000000..f9771ac4 Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[0].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[10].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[10].png new file mode 100644 index 00000000..2322d05e Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[10].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[11].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[11].png new file mode 100644 index 00000000..78d54733 Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[11].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[12].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[12].png new file mode 100644 index 00000000..89e4352d Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[12].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[1].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[1].png new file mode 100644 index 00000000..a3028d42 Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[1].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[2].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[2].png new file mode 100644 index 00000000..7d4527e0 Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[2].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[3].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[3].png new file mode 100644 index 00000000..b4fc7c58 Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[3].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[4].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[4].png new file mode 100644 index 00000000..e400c9aa Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[4].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[5].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[5].png new file mode 100644 index 00000000..9a2dce6e Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[5].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[6].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[6].png new file mode 100644 index 00000000..9be6d0f2 Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[6].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[7].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[7].png new file mode 100644 index 00000000..fd3306c4 Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[7].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[8].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[8].png new file mode 100644 index 00000000..a1a7818e Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[8].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[9].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[9].png new file mode 100644 index 00000000..2f62386a Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxDarkThemeSnapshot[9].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[0].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[0].png new file mode 100644 index 00000000..b0fad56e Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[0].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[10].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[10].png new file mode 100644 index 00000000..bef8736d Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[10].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[11].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[11].png new file mode 100644 index 00000000..9cab968b Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[11].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[12].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[12].png new file mode 100644 index 00000000..7cf84e3b Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[12].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[1].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[1].png new file mode 100644 index 00000000..ad10eb4d Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[1].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[2].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[2].png new file mode 100644 index 00000000..24a1db3e Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[2].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[3].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[3].png new file mode 100644 index 00000000..94f25ab8 Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[3].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[4].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[4].png new file mode 100644 index 00000000..396b7e57 Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[4].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[5].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[5].png new file mode 100644 index 00000000..2eac3382 Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[5].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[6].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[6].png new file mode 100644 index 00000000..9b559603 Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[6].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[7].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[7].png new file mode 100644 index 00000000..74d761dd Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[7].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[8].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[8].png new file mode 100644 index 00000000..c062db0f Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[8].png differ diff --git a/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[9].png b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[9].png new file mode 100644 index 00000000..07e5477a Binary files /dev/null and b/core/src/test/snapshots/images/com.orange.ouds.core.component.coloredbox_OudsColoredBoxTest_takeOudsColoredBoxLightThemeSnapshot[9].png differ diff --git a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsBorderKeyToken.kt b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsBorderKeyToken.kt index 63899b9a..d7cdfa8b 100644 --- a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsBorderKeyToken.kt +++ b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsBorderKeyToken.kt @@ -12,7 +12,7 @@ package com.orange.ouds.theme.tokens -sealed interface OudsBorderKeyToken { +sealed interface OudsBorderKeyToken : OudsKeyToken { sealed interface Radius : OudsBorderKeyToken { data object Default : Radius data object Medium : Radius diff --git a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsColorKeyToken.kt b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsColorKeyToken.kt index 19482147..19acbd95 100644 --- a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsColorKeyToken.kt +++ b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsColorKeyToken.kt @@ -12,7 +12,7 @@ package com.orange.ouds.theme.tokens -sealed interface OudsColorKeyToken { +sealed interface OudsColorKeyToken : OudsKeyToken { sealed interface Opacity : OudsColorKeyToken { data object Lower : Opacity data object Lowest : Opacity diff --git a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsElevationKeyToken.kt b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsElevationKeyToken.kt index 403b8dd4..2ddcb1a6 100644 --- a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsElevationKeyToken.kt +++ b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsElevationKeyToken.kt @@ -12,7 +12,7 @@ package com.orange.ouds.theme.tokens -sealed interface OudsElevationKeyToken { +sealed interface OudsElevationKeyToken : OudsKeyToken { data object None : OudsElevationKeyToken data object Raised : OudsElevationKeyToken diff --git a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsGridKeyToken.kt b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsGridKeyToken.kt index d499d06d..a6e365f7 100644 --- a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsGridKeyToken.kt +++ b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsGridKeyToken.kt @@ -12,7 +12,7 @@ package com.orange.ouds.theme.tokens -sealed interface OudsGridKeyToken { +sealed interface OudsGridKeyToken : OudsKeyToken { data object ColumnGap : OudsGridKeyToken data object Margin : OudsGridKeyToken data object MaxWidth : OudsGridKeyToken diff --git a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsKeyToken.kt b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsKeyToken.kt new file mode 100644 index 00000000..5d7f4efb --- /dev/null +++ b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsKeyToken.kt @@ -0,0 +1,22 @@ +/* + * Software Name: OUDS Android + * SPDX-FileCopyrightText: Copyright (c) Orange SA + * SPDX-License-Identifier: MIT + * + * This software is distributed under the MIT license, + * the text of which is available at https://opensource.org/license/MIT/ + * or see the "LICENSE" file for more details. + * + * Software description: Android library of reusable graphical components + */ + +package com.orange.ouds.theme.tokens + +sealed interface OudsKeyToken { + + val name: String + get() { + val packageName = this::class.java.`package`?.name.orEmpty() + return this::class.qualifiedName.orEmpty().removePrefix("$packageName.") + } +} diff --git a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsOpacityKeyToken.kt b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsOpacityKeyToken.kt index ef158204..b87f162c 100644 --- a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsOpacityKeyToken.kt +++ b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsOpacityKeyToken.kt @@ -12,7 +12,7 @@ package com.orange.ouds.theme.tokens -sealed interface OudsOpacityKeyToken { +sealed interface OudsOpacityKeyToken : OudsKeyToken { data object Invisible : OudsOpacityKeyToken data object Medium : OudsOpacityKeyToken data object Opaque : OudsOpacityKeyToken diff --git a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsSizeKeyToken.kt b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsSizeKeyToken.kt index 33950ef2..cdb2351c 100644 --- a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsSizeKeyToken.kt +++ b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsSizeKeyToken.kt @@ -12,7 +12,7 @@ package com.orange.ouds.theme.tokens -sealed interface OudsSizeKeyToken { +sealed interface OudsSizeKeyToken : OudsKeyToken { sealed interface Icon : OudsSizeKeyToken { sealed interface Decorative : Icon { data object ExtraExtraLarge : Decorative diff --git a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsSpaceKeyToken.kt b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsSpaceKeyToken.kt index 3e956455..4d1f564d 100644 --- a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsSpaceKeyToken.kt +++ b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsSpaceKeyToken.kt @@ -12,7 +12,7 @@ package com.orange.ouds.theme.tokens -sealed interface OudsSpaceKeyToken { +sealed interface OudsSpaceKeyToken : OudsKeyToken { sealed interface ColumnGap : OudsSpaceKeyToken { data object Medium : ColumnGap data object None : ColumnGap diff --git a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsTypographyKeyToken.kt b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsTypographyKeyToken.kt index 1ffbcdf1..b3ebe6e0 100644 --- a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsTypographyKeyToken.kt +++ b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/OudsTypographyKeyToken.kt @@ -12,7 +12,7 @@ package com.orange.ouds.theme.tokens -sealed interface OudsTypographyKeyToken { +sealed interface OudsTypographyKeyToken : OudsKeyToken { sealed interface Display : OudsTypographyKeyToken { data object Large : Display