From 981176758843dacc4c6fa3903236bd47ce43d594 Mon Sep 17 00:00:00 2001 From: Florent Maitre Date: Thu, 21 Nov 2024 17:18:00 +0100 Subject: [PATCH] Use sealed interfaces and objects for all key tokens --- .../java/com/orange/ouds/app/ui/TopBar.kt | 2 +- .../ui/tokens/TokenCategoryDetailScreen.kt | 10 +- .../ouds/app/ui/tokens/TokenProperty.kt | 108 ++++----- .../ouds/app/ui/tokens/TokenPropertyHeader.kt | 2 +- .../ui/tokens/TokenPropertyIllustration.kt | 15 +- .../orange/ouds/app/ui/utilities/KClassExt.kt | 78 ++++++ .../composable/DetailScreenHeader.kt | 2 +- .../app/ui/utilities/composable/LargeCard.kt | 2 +- .../com/orange/ouds/core/theme/OudsBorders.kt | 2 +- .../com/orange/ouds/core/theme/OudsGrids.kt | 10 +- .../com/orange/ouds/core/theme/OudsSizes.kt | 215 ++++++++++------- .../com/orange/ouds/core/theme/OudsSpaces.kt | 153 +----------- .../orange/ouds/core/theme/OudsTypography.kt | 42 ++-- .../ouds/foundation/extensions/StandardExt.kt | 2 + .../ouds/theme/tokens/OudsBorderKeyToken.kt | 44 ++-- .../theme/tokens/OudsElevationKeyToken.kt | 15 +- .../ouds/theme/tokens/OudsGridKeyToken.kt | 11 +- .../ouds/theme/tokens/OudsOpacityKeyToken.kt | 15 +- .../ouds/theme/tokens/OudsSizeKeyToken.kt | 149 +++++++----- .../ouds/theme/tokens/OudsSpaceKeyToken.kt | 227 +++++++++--------- .../theme/tokens/OudsTypographyKeyToken.kt | 66 +++-- .../tokens/components/OudsButtonTokens.kt | 2 +- .../ouds/theme/whitelabel/WhiteLabelTheme.kt | 2 +- 23 files changed, 615 insertions(+), 559 deletions(-) create mode 100644 app/src/main/java/com/orange/ouds/app/ui/utilities/KClassExt.kt diff --git a/app/src/main/java/com/orange/ouds/app/ui/TopBar.kt b/app/src/main/java/com/orange/ouds/app/ui/TopBar.kt index e9f457df..0ae333f2 100644 --- a/app/src/main/java/com/orange/ouds/app/ui/TopBar.kt +++ b/app/src/main/java/com/orange/ouds/app/ui/TopBar.kt @@ -80,7 +80,7 @@ private fun TopBar( text = title, color = OudsColorKeyToken.Content.Default.value, modifier = Modifier.semantics { traversalIndex = -1f }, - style = OudsTypographyKeyToken.HeadingMedium.value + style = OudsTypographyKeyToken.Heading.Medium.value ) }, actions = { diff --git a/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenCategoryDetailScreen.kt b/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenCategoryDetailScreen.kt index fe98a89e..8f0490da 100644 --- a/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenCategoryDetailScreen.kt +++ b/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenCategoryDetailScreen.kt @@ -73,7 +73,7 @@ fun TokenCategoryDetailScreen(tokenCategory: TokenCategory<*>, onSubcategoryClic text = stringResource(id = subcategory.nameRes), maxLines = 1, overflow = TextOverflow.Ellipsis, - style = OudsTypographyKeyToken.HeadingMedium.value + style = OudsTypographyKeyToken.Heading.Medium.value ) } } @@ -89,7 +89,7 @@ fun TokenCategoryDetailScreen(tokenCategory: TokenCategory<*>, onSubcategoryClic text = stringResource(id = tokenProperty.nameRes), maxLines = 1, overflow = TextOverflow.Ellipsis, - style = OudsTypographyKeyToken.HeadingMedium.value + style = OudsTypographyKeyToken.Heading.Medium.value ) } @@ -113,7 +113,7 @@ fun TokenCategoryDetailScreen(tokenCategory: TokenCategory<*>, onSubcategoryClic text = stringResource(id = R.string.app_tokens_dimension_size_iconWithTextTokenName_label, token.name, token.literalValue), maxLines = 1, overflow = TextOverflow.Ellipsis, - style = OudsTypographyKeyToken.BodyDefaultMedium.value, + style = OudsTypographyKeyToken.Body.Default.Medium.value, color = OudsColorKeyToken.Content.Muted.value ) } @@ -135,7 +135,7 @@ fun TokenCategoryDetailScreen(tokenCategory: TokenCategory<*>, onSubcategoryClic style = if (tokenProperty == TokenProperty.Typography) { token.value as TextStyle } else { - OudsTypographyKeyToken.BodyStrongLarge.value + OudsTypographyKeyToken.Body.Strong.Large.value } ) Text( @@ -143,7 +143,7 @@ fun TokenCategoryDetailScreen(tokenCategory: TokenCategory<*>, onSubcategoryClic text = token.literalValue, maxLines = 1, overflow = TextOverflow.Ellipsis, - style = OudsTypographyKeyToken.BodyDefaultMedium.value.copy(color = OudsColorKeyToken.Content.Muted.value) + style = OudsTypographyKeyToken.Body.Default.Medium.value.copy(color = OudsColorKeyToken.Content.Muted.value) ) } } 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 27be4c45..9d820983 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 @@ -15,7 +15,8 @@ package com.orange.ouds.app.ui.tokens import androidx.annotation.StringRes import androidx.compose.runtime.Composable import com.orange.ouds.app.R -import com.orange.ouds.core.theme.value +import com.orange.ouds.app.ui.utilities.getTokenName +import com.orange.ouds.app.ui.utilities.getTokens import com.orange.ouds.theme.tokens.OudsBorderKeyToken import com.orange.ouds.theme.tokens.OudsColorKeyToken import com.orange.ouds.theme.tokens.OudsElevationKeyToken @@ -34,213 +35,204 @@ sealed class TokenProperty( data object BorderRadius : TokenProperty( nameRes = R.string.app_tokens_border_radius_label, - tokens = { OudsBorderKeyToken.Radius.entries.map { Token(it.name, it.value) } }, + tokens = { OudsBorderKeyToken.Radius::class.getTokens() }, categoryClass = TokenCategory.Border::class ) data object BorderStyle : TokenProperty( nameRes = R.string.app_tokens_border_style_label, - tokens = { OudsBorderKeyToken.Style.entries.map { Token(it.name, it.value) } }, + tokens = { OudsBorderKeyToken.Style::class.getTokens() }, categoryClass = TokenCategory.Border::class ) data object BorderWidth : TokenProperty( nameRes = R.string.app_tokens_border_width_label, - tokens = { OudsBorderKeyToken.Width.entries.map { Token(it.name, it.value) } }, + tokens = { OudsBorderKeyToken.Width::class.getTokens() }, categoryClass = TokenCategory.Border::class ) data object ColorAction : TokenProperty( nameRes = R.string.app_tokens_color_action_label, - tokens = { OudsColorKeyToken.Action::class.getTokens() }, + tokens = { OudsColorKeyToken.Action::class.getTokens() }, categoryClass = TokenCategory.Color::class ) data object ColorAlways : TokenProperty( nameRes = R.string.app_tokens_color_always_label, - tokens = { OudsColorKeyToken.Always::class.getTokens() }, + tokens = { OudsColorKeyToken.Always::class.getTokens() }, categoryClass = TokenCategory.Color::class ) data object ColorBackground : TokenProperty( nameRes = R.string.app_tokens_color_background_label, - tokens = { OudsColorKeyToken.Background::class.getTokens() }, + tokens = { OudsColorKeyToken.Background::class.getTokens() }, categoryClass = TokenCategory.Color::class ) data object ColorBorder : TokenProperty( nameRes = R.string.app_tokens_color_border_label, - tokens = { OudsColorKeyToken.Border::class.getTokens() }, + tokens = { OudsColorKeyToken.Border::class.getTokens() }, categoryClass = TokenCategory.Color::class ) data object ColorBrand : TokenProperty( nameRes = R.string.app_tokens_color_brand_label, - tokens = { OudsColorKeyToken.Brand::class.getTokens() }, + tokens = { OudsColorKeyToken.Brand::class.getTokens() }, categoryClass = TokenCategory.Color::class ) data object ColorContent : TokenProperty( nameRes = R.string.app_tokens_color_content_label, - tokens = { OudsColorKeyToken.Content::class.getTokens() }, + tokens = { OudsColorKeyToken.Content::class.getTokens() }, categoryClass = TokenCategory.Color::class ) data object ColorDecorative : TokenProperty( nameRes = R.string.app_tokens_color_decorative_label, - tokens = { OudsColorKeyToken.Decorative::class.getTokens() }, + tokens = { OudsColorKeyToken.Decorative::class.getTokens() }, categoryClass = TokenCategory.Color::class ) data object ColorElevation : TokenProperty( nameRes = R.string.app_tokens_color_elevation_label, - tokens = { OudsColorKeyToken.Elevation::class.getTokens() }, + tokens = { OudsColorKeyToken.Elevation::class.getTokens() }, categoryClass = TokenCategory.Color::class ) data object ColorGradient : TokenProperty( nameRes = R.string.app_tokens_color_gradient_label, - tokens = { OudsColorKeyToken.Gradient::class.getTokens() }, + tokens = { OudsColorKeyToken.Gradient::class.getTokens() }, categoryClass = TokenCategory.Color::class ) data object Elevation : TokenProperty( nameRes = null, - tokens = { OudsElevationKeyToken.entries.map { Token(it.name, it.value) } }, + tokens = { OudsElevationKeyToken::class.getTokens() }, categoryClass = TokenCategory.Elevation::class ) data object Grid : TokenProperty( nameRes = null, - tokens = { OudsGridKeyToken.entries.map { Token(it.name, it.value) } }, + tokens = { OudsGridKeyToken::class.getTokens() }, categoryClass = TokenCategory.Grid::class ) data object Opacity : TokenProperty( nameRes = null, - tokens = { OudsOpacityKeyToken.entries.map { Token(it.name, it.value) } }, + tokens = { OudsOpacityKeyToken::class.getTokens() }, categoryClass = TokenCategory.Opacity::class ) data object SizeIconDecorative : TokenProperty( nameRes = R.string.app_tokens_dimension_size_iconDecorative_label, - tokens = { OudsSizeKeyToken.IconDecorative.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSizeKeyToken.Icon.Decorative::class.getTokens() }, categoryClass = TokenCategory.Dimension.Size::class ) data object SizeIconWithText : TokenProperty( nameRes = R.string.app_tokens_dimension_size_iconWithText_label, - tokens = { OudsSizeKeyToken.IconWithText.entries.map { Token(it.name, it.value) } }, + tokens = { + val keyTokenClasses = listOf( + OudsSizeKeyToken.Icon.WithHeadingExtraLarge::class, + OudsSizeKeyToken.Icon.WithHeadingLarge::class, + OudsSizeKeyToken.Icon.WithHeadingMedium::class, + OudsSizeKeyToken.Icon.WithHeadingSmall::class, + OudsSizeKeyToken.Icon.WithBodyLarge::class, + OudsSizeKeyToken.Icon.WithBodyMedium::class, + OudsSizeKeyToken.Icon.WithBodySmall::class, + OudsSizeKeyToken.Icon.WithLabelExtraLarge::class, + OudsSizeKeyToken.Icon.WithLabelLarge::class, + OudsSizeKeyToken.Icon.WithLabelMedium::class, + OudsSizeKeyToken.Icon.WithLabelSmall::class, + ) + keyTokenClasses.flatMap { keyTokenClass -> + keyTokenClass.getTokens(tokenName = { it.getTokenName(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.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSpaceKeyToken.ColumnGap::class.getTokens(recursive = false) }, categoryClass = TokenCategory.Dimension.Space::class ) data object SpaceColumnGapWithIcon : TokenProperty( nameRes = R.string.app_tokens_dimension_space_columnGapWithIcon_label, - tokens = { OudsSpaceKeyToken.ColumnGap.WithIcon.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSpaceKeyToken.ColumnGap.WithIcon::class.getTokens() }, categoryClass = TokenCategory.Dimension.Space::class ) data object SpaceColumnGapWithArrow : TokenProperty( nameRes = R.string.app_tokens_dimension_space_columnGapWithArrow_label, - tokens = { OudsSpaceKeyToken.ColumnGap.WithArrow.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSpaceKeyToken.ColumnGap.WithArrow::class.getTokens() }, categoryClass = TokenCategory.Dimension.Space::class ) data object SpaceFixed : TokenProperty( nameRes = R.string.app_tokens_dimension_space_fixed_label, - tokens = { OudsSpaceKeyToken.Fixed.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSpaceKeyToken.Fixed::class.getTokens() }, categoryClass = TokenCategory.Dimension.Space::class ) data object SpacePaddingInline : TokenProperty( nameRes = R.string.app_tokens_dimension_space_paddingInline_label, - tokens = { OudsSpaceKeyToken.PaddingInline.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSpaceKeyToken.PaddingInline::class.getTokens(recursive = false) }, categoryClass = TokenCategory.Dimension.Space::class ) data object SpacePaddingInlineWithIcon : TokenProperty( nameRes = R.string.app_tokens_dimension_space_paddingInlineWithIcon_label, - tokens = { OudsSpaceKeyToken.PaddingInline.WithIcon.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSpaceKeyToken.PaddingInline.WithIcon::class.getTokens() }, categoryClass = TokenCategory.Dimension.Space::class ) data object SpacePaddingInlineWithArrow : TokenProperty( nameRes = R.string.app_tokens_dimension_space_paddingInlineWithArrow_label, - tokens = { OudsSpaceKeyToken.PaddingInline.WithArrow.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSpaceKeyToken.PaddingInline.WithArrow::class.getTokens() }, categoryClass = TokenCategory.Dimension.Space::class ) data object SpacePaddingInset : TokenProperty( nameRes = R.string.app_tokens_dimension_space_paddingInset_label, - tokens = { OudsSpaceKeyToken.Inset.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSpaceKeyToken.Inset::class.getTokens() }, categoryClass = TokenCategory.Dimension.Space::class ) data object SpacePaddingStack : TokenProperty( nameRes = R.string.app_tokens_dimension_space_paddingStack_label, - tokens = { OudsSpaceKeyToken.PaddingBlock.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSpaceKeyToken.PaddingBlock::class.getTokens(recursive = false) }, categoryClass = TokenCategory.Dimension.Space::class ) data object SpacePaddingStackWithIcon : TokenProperty( nameRes = R.string.app_tokens_dimension_space_paddingStackWithIcon_label, - tokens = { OudsSpaceKeyToken.PaddingBlock.WithIcon.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSpaceKeyToken.PaddingBlock.WithIcon::class.getTokens() }, categoryClass = TokenCategory.Dimension.Space::class ) data object SpaceRowGap : TokenProperty( nameRes = R.string.app_tokens_dimension_space_rowGap_label, - tokens = { OudsSpaceKeyToken.RowGap.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSpaceKeyToken.RowGap::class.getTokens(recursive = false) }, categoryClass = TokenCategory.Dimension.Space::class ) data object SpaceRowGapWithIcon : TokenProperty( nameRes = R.string.app_tokens_dimension_space_rowGapWithIcon_label, - tokens = { OudsSpaceKeyToken.RowGap.WithIcon.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSpaceKeyToken.RowGap.WithIcon::class.getTokens() }, categoryClass = TokenCategory.Dimension.Space::class ) data object SpaceScaled : TokenProperty( nameRes = R.string.app_tokens_dimension_space_scaled_label, - tokens = { OudsSpaceKeyToken.Scaled.entries.map { Token(it.name, it.value) } }, + tokens = { OudsSpaceKeyToken.Scaled::class.getTokens() }, categoryClass = TokenCategory.Dimension.Space::class ) data object Typography : TokenProperty( nameRes = null, - tokens = { OudsTypographyKeyToken.entries.map { Token(it.name, it.value) } }, + tokens = { OudsTypographyKeyToken::class.getTokens() }, categoryClass = TokenCategory.Typography::class ) } - -@PublishedApi -internal fun KClass<*>.getRelativeName(parent: KClass<*>): String { - return qualifiedName.orEmpty().removePrefix("${parent.qualifiedName.orEmpty()}.") -} - -@PublishedApi -internal inline fun KClass<*>.getNestedObjects(): List { - return getNestedClassesRecursive().mapNotNull { it.objectInstance }.filterIsInstance() -} - -@PublishedApi -internal fun KClass<*>.getNestedClassesRecursive(): List> { - return nestedClasses + nestedClasses.flatMap { it.getNestedClassesRecursive() } -} - -@Composable -inline fun KClass<*>.getTokens(): List> { - return getNestedObjects().mapNotNull { keyToken -> - val value = when (keyToken) { - is OudsColorKeyToken -> keyToken.value - else -> null - } - value?.let { Token(keyToken::class.getRelativeName(this).removeSuffix(".Companion"), it) } - }.sortedBy { it.name } -} diff --git a/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenPropertyHeader.kt b/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenPropertyHeader.kt index 2409b7fd..4038a3cd 100644 --- a/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenPropertyHeader.kt +++ b/app/src/main/java/com/orange/ouds/app/ui/tokens/TokenPropertyHeader.kt @@ -181,7 +181,7 @@ private fun SpaceHeaderText(spaceTokenProperty: TokenProperty>>() + ?.firstOrNull { typographyToken -> + tokenName.split(".").firstOrNull() == typographyToken.name.replace("Strong", "").replace(".", "") + } + ?.value + .orElse { LocalTextStyle.current } Text( modifier = Modifier.weight(1f), - text = label, + text = tokenName, maxLines = 1, overflow = TextOverflow.Ellipsis, - style = OudsTypographyKeyToken.entries.firstOrNull { it.name.replace("Strong", "") == label }?.value.orElse { LocalTextStyle.current } + style = style ) } } 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 new file mode 100644 index 00000000..783a5776 --- /dev/null +++ b/app/src/main/java/com/orange/ouds/app/ui/utilities/KClassExt.kt @@ -0,0 +1,78 @@ +/* + * 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.app.ui.utilities + +import androidx.compose.runtime.Composable +import com.orange.ouds.app.ui.tokens.Token +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 + +@Composable +fun KClass<*>.getTokens( + recursive: Boolean = true, + tokenName: (KClass<*>) -> String = { it.getTokenName(this) } +): List> { + return getNestedObjects(getRootKeyTokenSuperclass(), recursive).mapNotNull { keyToken -> + val value: Any? = 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 + } + value?.let { Token(tokenName(keyToken::class), it) } + } +} + +fun KClass<*>.getTokenName(fromParent: KClass<*>): String { + return qualifiedName.orEmpty() + .removePrefix("${fromParent.qualifiedName.orEmpty()}.") + .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> { + return if (recursive) { + nestedClasses + nestedClasses.flatMap { it.getNestedClasses(recursive = true) } + } else { + nestedClasses.toList() + } +} + +private fun KClass<*>.getRootKeyTokenSuperclass(): KClass<*> { + return supertypes.firstOrNull() + ?.classifier + ?.asOrNull>() + ?.takeIf { it != Any::class } + ?.getRootKeyTokenSuperclass() + .orElse { this } +} diff --git a/app/src/main/java/com/orange/ouds/app/ui/utilities/composable/DetailScreenHeader.kt b/app/src/main/java/com/orange/ouds/app/ui/utilities/composable/DetailScreenHeader.kt index 0091aace..3d63cfae 100644 --- a/app/src/main/java/com/orange/ouds/app/ui/utilities/composable/DetailScreenHeader.kt +++ b/app/src/main/java/com/orange/ouds/app/ui/utilities/composable/DetailScreenHeader.kt @@ -71,7 +71,7 @@ private fun DetailScreenDescription( modifier = modifier, text = stringResource(descriptionRes), color = OudsColorKeyToken.Content.Default.value, - style = OudsTypographyKeyToken.BodyDefaultLarge.value + style = OudsTypographyKeyToken.Body.Default.Large.value ) } diff --git a/app/src/main/java/com/orange/ouds/app/ui/utilities/composable/LargeCard.kt b/app/src/main/java/com/orange/ouds/app/ui/utilities/composable/LargeCard.kt index 65c345e0..8e412717 100644 --- a/app/src/main/java/com/orange/ouds/app/ui/utilities/composable/LargeCard.kt +++ b/app/src/main/java/com/orange/ouds/app/ui/utilities/composable/LargeCard.kt @@ -69,7 +69,7 @@ fun LargeCard( color = OudsColorKeyToken.Content.Default.value, overflow = TextOverflow.Ellipsis, maxLines = 1, - style = OudsTypographyKeyToken.HeadingMedium.value + style = OudsTypographyKeyToken.Heading.Medium.value ) } diff --git a/core/src/main/java/com/orange/ouds/core/theme/OudsBorders.kt b/core/src/main/java/com/orange/ouds/core/theme/OudsBorders.kt index 054f96c5..acfeab61 100644 --- a/core/src/main/java/com/orange/ouds/core/theme/OudsBorders.kt +++ b/core/src/main/java/com/orange/ouds/core/theme/OudsBorders.kt @@ -69,7 +69,7 @@ fun OudsBorders.fromToken(token: OudsBorderKeyToken.Width): Dp { OudsBorderKeyToken.Width.Thick -> widthThick OudsBorderKeyToken.Width.Thicker -> widthThicker OudsBorderKeyToken.Width.Focus -> widthFocus - OudsBorderKeyToken.Width.FocusInset -> widthFocusInset + OudsBorderKeyToken.Width.Focus.Inset -> widthFocusInset } } diff --git a/core/src/main/java/com/orange/ouds/core/theme/OudsGrids.kt b/core/src/main/java/com/orange/ouds/core/theme/OudsGrids.kt index 2db84a06..910337c4 100644 --- a/core/src/main/java/com/orange/ouds/core/theme/OudsGrids.kt +++ b/core/src/main/java/com/orange/ouds/core/theme/OudsGrids.kt @@ -55,18 +55,12 @@ fun OudsGridSemanticTokens.getGrids() = OudsGrids( @Stable fun OudsGrids.fromToken(token: OudsGridKeyToken, adaptiveWindowType: OudsAdaptiveWindowType): Dp { - val gridToken = when (token) { + return when (token) { OudsGridKeyToken.MinWidth -> minWidth OudsGridKeyToken.MaxWidth -> maxWidth OudsGridKeyToken.ColumnGap -> columnGap OudsGridKeyToken.Margin -> margin - } - - return when (adaptiveWindowType) { - OudsAdaptiveWindowType.EXTRA_COMPACT -> gridToken.extraCompact - OudsAdaptiveWindowType.COMPACT -> gridToken.compact - OudsAdaptiveWindowType.MEDIUM -> gridToken.medium - } + }.getValue(adaptiveWindowType) } /** diff --git a/core/src/main/java/com/orange/ouds/core/theme/OudsSizes.kt b/core/src/main/java/com/orange/ouds/core/theme/OudsSizes.kt index 0eafa537..994d693e 100644 --- a/core/src/main/java/com/orange/ouds/core/theme/OudsSizes.kt +++ b/core/src/main/java/com/orange/ouds/core/theme/OudsSizes.kt @@ -13,7 +13,6 @@ package com.orange.ouds.core.theme import androidx.compose.runtime.Composable -import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.runtime.Stable import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp @@ -378,105 +377,149 @@ fun OudsSizeSemanticTokens.getSizes() = OudsSizes( ) @Stable -fun OudsSizes.fromToken(token: OudsSizeKeyToken.IconDecorative): Dp { +fun OudsSizes.fromToken(token: OudsSizeKeyToken.Icon.Decorative): Dp { return when (token) { - OudsSizeKeyToken.IconDecorative.Shortest -> icon.decorative.shortest - OudsSizeKeyToken.IconDecorative.Shorter -> icon.decorative.shorter - OudsSizeKeyToken.IconDecorative.Short -> icon.decorative.short - OudsSizeKeyToken.IconDecorative.Medium -> icon.decorative.medium - OudsSizeKeyToken.IconDecorative.Tall -> icon.decorative.tall - OudsSizeKeyToken.IconDecorative.Taller -> icon.decorative.taller - OudsSizeKeyToken.IconDecorative.Tallest -> icon.decorative.tallest + OudsSizeKeyToken.Icon.Decorative.Shortest -> icon.decorative.shortest + OudsSizeKeyToken.Icon.Decorative.Shorter -> icon.decorative.shorter + OudsSizeKeyToken.Icon.Decorative.Short -> icon.decorative.short + OudsSizeKeyToken.Icon.Decorative.Medium -> icon.decorative.medium + OudsSizeKeyToken.Icon.Decorative.Tall -> icon.decorative.tall + OudsSizeKeyToken.Icon.Decorative.Taller -> icon.decorative.taller + OudsSizeKeyToken.Icon.Decorative.Tallest -> icon.decorative.tallest } } @Stable -fun OudsSizes.fromToken(token: OudsSizeKeyToken.IconWithText, adaptiveWindowType: OudsAdaptiveWindowType): Dp { - val dimensionSizeIconWithTextValue: Any = when (token) { - OudsSizeKeyToken.IconWithText.HeadingSmallSizeShort -> icon.withHeading.small.sizeShort - OudsSizeKeyToken.IconWithText.HeadingSmallSizeMedium -> icon.withHeading.small.sizeMedium - OudsSizeKeyToken.IconWithText.HeadingSmallSizeTall -> icon.withHeading.small.sizeTall - OudsSizeKeyToken.IconWithText.HeadingMediumSizeShort -> icon.withHeading.medium.sizeShort - OudsSizeKeyToken.IconWithText.HeadingMediumSizeMedium -> icon.withHeading.medium.sizeMedium - OudsSizeKeyToken.IconWithText.HeadingMediumSizeTall -> icon.withHeading.medium.sizeTall - OudsSizeKeyToken.IconWithText.HeadingLargeSizeShort -> icon.withHeading.large.sizeShort - OudsSizeKeyToken.IconWithText.HeadingLargeSizeMedium -> icon.withHeading.large.sizeMedium - OudsSizeKeyToken.IconWithText.HeadingLargeSizeTall -> icon.withHeading.large.sizeTall - OudsSizeKeyToken.IconWithText.HeadingExtraLargeSizeShort -> icon.withHeading.extraLarge.sizeShort - OudsSizeKeyToken.IconWithText.HeadingExtraLargeSizeMedium -> icon.withHeading.extraLarge.sizeMedium - OudsSizeKeyToken.IconWithText.HeadingExtraLargeSizeTall -> icon.withHeading.extraLarge.sizeTall - OudsSizeKeyToken.IconWithText.LabelLargeSizeShorter -> icon.withLabel.large.sizeShorter - OudsSizeKeyToken.IconWithText.LabelLargeSizeShort -> icon.withLabel.large.sizeShort - OudsSizeKeyToken.IconWithText.LabelLargeSizeMedium -> icon.withLabel.large.sizeMedium - OudsSizeKeyToken.IconWithText.LabelLargeSizeTall -> icon.withLabel.large.sizeTall - OudsSizeKeyToken.IconWithText.LabelLargeSizeTaller -> icon.withLabel.large.sizeTaller - OudsSizeKeyToken.IconWithText.LabelMediumSizeShort -> icon.withLabel.medium.sizeShort - OudsSizeKeyToken.IconWithText.LabelMediumSizeMedium -> icon.withLabel.medium.sizeMedium - OudsSizeKeyToken.IconWithText.LabelMediumSizeTall -> icon.withLabel.medium.sizeTall - OudsSizeKeyToken.IconWithText.LabelSmallSizeShort -> icon.withLabel.small.sizeShort - OudsSizeKeyToken.IconWithText.LabelSmallSizeMedium -> icon.withLabel.small.sizeMedium - OudsSizeKeyToken.IconWithText.LabelSmallSizeTall -> icon.withLabel.small.sizeTall - OudsSizeKeyToken.IconWithText.LabelExtraLargeSizeShort -> icon.withLabel.extraLarge.sizeShort - OudsSizeKeyToken.IconWithText.LabelExtraLargeSizeMedium -> icon.withLabel.extraLarge.sizeMedium - OudsSizeKeyToken.IconWithText.LabelExtraLargeSizeTall -> icon.withLabel.extraLarge.sizeTall - OudsSizeKeyToken.IconWithText.BodySmallSizeShort -> icon.withBody.small.sizeShort - OudsSizeKeyToken.IconWithText.BodySmallSizeMedium -> icon.withBody.small.sizeMedium - OudsSizeKeyToken.IconWithText.BodySmallSizeTall -> icon.withBody.small.sizeTall - OudsSizeKeyToken.IconWithText.BodyMediumSizeShort -> icon.withBody.medium.sizeShort - OudsSizeKeyToken.IconWithText.BodyMediumSizeMedium -> icon.withBody.medium.sizeMedium - OudsSizeKeyToken.IconWithText.BodyMediumSizeTall -> icon.withBody.medium.sizeTall - OudsSizeKeyToken.IconWithText.BodyLargeSizeShort -> icon.withBody.large.sizeShort - OudsSizeKeyToken.IconWithText.BodyLargeSizeMedium -> icon.withBody.large.sizeMedium - OudsSizeKeyToken.IconWithText.BodyLargeSizeTall -> icon.withBody.large.sizeTall - } +fun OudsSizes.fromToken(token: OudsSizeKeyToken.Icon.WithHeadingExtraLarge, adaptiveWindowType: OudsAdaptiveWindowType): Dp { + return when (token) { + OudsSizeKeyToken.Icon.WithHeadingExtraLarge.SizeShort -> icon.withHeading.extraLarge.sizeShort + OudsSizeKeyToken.Icon.WithHeadingExtraLarge.SizeMedium -> icon.withHeading.extraLarge.sizeMedium + OudsSizeKeyToken.Icon.WithHeadingExtraLarge.SizeTall -> icon.withHeading.extraLarge.sizeTall + }.getValue(adaptiveWindowType) +} + +@Stable +fun OudsSizes.fromToken(token: OudsSizeKeyToken.Icon.WithHeadingLarge, adaptiveWindowType: OudsAdaptiveWindowType): Dp { + return when (token) { + OudsSizeKeyToken.Icon.WithHeadingLarge.SizeShort -> icon.withHeading.large.sizeShort + OudsSizeKeyToken.Icon.WithHeadingLarge.SizeMedium -> icon.withHeading.large.sizeMedium + OudsSizeKeyToken.Icon.WithHeadingLarge.SizeTall -> icon.withHeading.large.sizeTall + }.getValue(adaptiveWindowType) +} + +@Stable +fun OudsSizes.fromToken(token: OudsSizeKeyToken.Icon.WithHeadingMedium, adaptiveWindowType: OudsAdaptiveWindowType): Dp { + return when (token) { + OudsSizeKeyToken.Icon.WithHeadingMedium.SizeShort -> icon.withHeading.medium.sizeShort + OudsSizeKeyToken.Icon.WithHeadingMedium.SizeMedium -> icon.withHeading.medium.sizeMedium + OudsSizeKeyToken.Icon.WithHeadingMedium.SizeTall -> icon.withHeading.medium.sizeTall + }.getValue(adaptiveWindowType) +} + +@Stable +fun OudsSizes.fromToken(token: OudsSizeKeyToken.Icon.WithHeadingSmall, adaptiveWindowType: OudsAdaptiveWindowType): Dp { + return when (token) { + OudsSizeKeyToken.Icon.WithHeadingSmall.SizeShort -> icon.withHeading.small.sizeShort + OudsSizeKeyToken.Icon.WithHeadingSmall.SizeMedium -> icon.withHeading.small.sizeMedium + OudsSizeKeyToken.Icon.WithHeadingSmall.SizeTall -> icon.withHeading.small.sizeTall + }.getValue(adaptiveWindowType) +} + +@Stable +fun OudsSizes.fromToken(token: OudsSizeKeyToken.Icon.WithBodyLarge, adaptiveWindowType: OudsAdaptiveWindowType): Dp { + return when (token) { + OudsSizeKeyToken.Icon.WithBodyLarge.SizeShort -> icon.withBody.large.sizeShort + OudsSizeKeyToken.Icon.WithBodyLarge.SizeMedium -> icon.withBody.large.sizeMedium + OudsSizeKeyToken.Icon.WithBodyLarge.SizeTall -> icon.withBody.large.sizeTall + }.getValue(adaptiveWindowType) +} - return if (dimensionSizeIconWithTextValue is OudsAdaptiveTokenValue<*>) { - dimensionSizeIconWithTextValue.getValue(adaptiveWindowType) - } else { - dimensionSizeIconWithTextValue - } as Dp +@Stable +fun OudsSizes.fromToken(token: OudsSizeKeyToken.Icon.WithBodyMedium, adaptiveWindowType: OudsAdaptiveWindowType): Dp { + return when (token) { + OudsSizeKeyToken.Icon.WithBodyMedium.SizeShort -> icon.withBody.medium.sizeShort + OudsSizeKeyToken.Icon.WithBodyMedium.SizeMedium -> icon.withBody.medium.sizeMedium + OudsSizeKeyToken.Icon.WithBodyMedium.SizeTall -> icon.withBody.medium.sizeTall + }.getValue(adaptiveWindowType) } @Stable -fun OudsSizes.fromToken(token: OudsSizeKeyToken.MaxWidthType, adaptiveWindowType: OudsAdaptiveWindowType): Dp { - val dimensionMaxWidthTypeToken = when (token) { - OudsSizeKeyToken.MaxWidthType.DisplaySmall -> maxWidthType.display.small - OudsSizeKeyToken.MaxWidthType.DisplayMedium -> maxWidthType.display.medium - OudsSizeKeyToken.MaxWidthType.DisplayLarge -> maxWidthType.display.large - OudsSizeKeyToken.MaxWidthType.HeadingSmall -> maxWidthType.heading.small - OudsSizeKeyToken.MaxWidthType.HeadingMedium -> maxWidthType.heading.medium - OudsSizeKeyToken.MaxWidthType.HeadingLarge -> maxWidthType.heading.large - OudsSizeKeyToken.MaxWidthType.HeadingExtraLarge -> maxWidthType.heading.extraLarge - OudsSizeKeyToken.MaxWidthType.BodySmall -> maxWidthType.body.small - OudsSizeKeyToken.MaxWidthType.BodyMedium -> maxWidthType.body.medium - OudsSizeKeyToken.MaxWidthType.BodyLarge -> maxWidthType.body.large +fun OudsSizes.fromToken(token: OudsSizeKeyToken.Icon.WithBodySmall, adaptiveWindowType: OudsAdaptiveWindowType): Dp { + return when (token) { + OudsSizeKeyToken.Icon.WithBodySmall.SizeShort -> icon.withBody.small.sizeShort + OudsSizeKeyToken.Icon.WithBodySmall.SizeMedium -> icon.withBody.small.sizeMedium + OudsSizeKeyToken.Icon.WithBodySmall.SizeTall -> icon.withBody.small.sizeTall + }.getValue(adaptiveWindowType) +} + +@Stable +fun OudsSizes.fromToken(token: OudsSizeKeyToken.Icon.WithLabelExtraLarge): Dp { + return when (token) { + OudsSizeKeyToken.Icon.WithLabelExtraLarge.SizeShort -> icon.withLabel.extraLarge.sizeShort + OudsSizeKeyToken.Icon.WithLabelExtraLarge.SizeMedium -> icon.withLabel.extraLarge.sizeMedium + OudsSizeKeyToken.Icon.WithLabelExtraLarge.SizeTall -> icon.withLabel.extraLarge.sizeTall } +} - return when (adaptiveWindowType) { - OudsAdaptiveWindowType.EXTRA_COMPACT -> dimensionMaxWidthTypeToken.extraCompact - OudsAdaptiveWindowType.COMPACT -> dimensionMaxWidthTypeToken.compact - OudsAdaptiveWindowType.MEDIUM -> dimensionMaxWidthTypeToken.medium +@Stable +fun OudsSizes.fromToken(token: OudsSizeKeyToken.Icon.WithLabelLarge): Dp { + return when (token) { + OudsSizeKeyToken.Icon.WithLabelLarge.SizeShorter -> icon.withLabel.large.sizeShorter + OudsSizeKeyToken.Icon.WithLabelLarge.SizeShort -> icon.withLabel.large.sizeShort + OudsSizeKeyToken.Icon.WithLabelLarge.SizeMedium -> icon.withLabel.large.sizeMedium + OudsSizeKeyToken.Icon.WithLabelLarge.SizeTall -> icon.withLabel.large.sizeTall + OudsSizeKeyToken.Icon.WithLabelLarge.SizeTaller -> icon.withLabel.large.sizeTaller } } -/** - * Converts an OUDS decorative icon size token to the local decorative icon size value provided by the theme. - */ -val OudsSizeKeyToken.IconDecorative.value: Dp - @ReadOnlyComposable - @Composable - get() = OudsTheme.sizes.fromToken(this) +@Stable +fun OudsSizes.fromToken(token: OudsSizeKeyToken.Icon.WithLabelMedium): Dp { + return when (token) { + OudsSizeKeyToken.Icon.WithLabelMedium.SizeShort -> icon.withLabel.medium.sizeShort + OudsSizeKeyToken.Icon.WithLabelMedium.SizeMedium -> icon.withLabel.medium.sizeMedium + OudsSizeKeyToken.Icon.WithLabelMedium.SizeTall -> icon.withLabel.medium.sizeTall + } +} -/** - * Converts an OUDS icon size with typography token to the local icon size with typography value provided by the theme depending on the window size. - */ -val OudsSizeKeyToken.IconWithText.value: Dp - @Composable - get() = OudsTheme.sizes.fromToken(this, OudsAdaptiveWindowType.fromWindowWidth(currentWindowWidth())) +@Stable +fun OudsSizes.fromToken(token: OudsSizeKeyToken.Icon.WithLabelSmall): Dp { + return when (token) { + OudsSizeKeyToken.Icon.WithLabelSmall.SizeShort -> icon.withLabel.small.sizeShort + OudsSizeKeyToken.Icon.WithLabelSmall.SizeMedium -> icon.withLabel.small.sizeMedium + OudsSizeKeyToken.Icon.WithLabelSmall.SizeTall -> icon.withLabel.small.sizeTall + } +} -/** - * Converts an OUDS max width with typography token to the local max width with typography value provided by the theme depending on the window size. - */ -val OudsSizeKeyToken.MaxWidthType.value: Dp +@Stable +fun OudsSizes.fromToken(token: OudsSizeKeyToken.MaxWidth, adaptiveWindowType: OudsAdaptiveWindowType): Dp { + return when (token) { + OudsSizeKeyToken.MaxWidth.Type.DisplaySmall -> maxWidthType.display.small + OudsSizeKeyToken.MaxWidth.Type.DisplayMedium -> maxWidthType.display.medium + OudsSizeKeyToken.MaxWidth.Type.DisplayLarge -> maxWidthType.display.large + OudsSizeKeyToken.MaxWidth.Type.HeadingSmall -> maxWidthType.heading.small + OudsSizeKeyToken.MaxWidth.Type.HeadingMedium -> maxWidthType.heading.medium + OudsSizeKeyToken.MaxWidth.Type.HeadingLarge -> maxWidthType.heading.large + OudsSizeKeyToken.MaxWidth.Type.HeadingExtraLarge -> maxWidthType.heading.extraLarge + OudsSizeKeyToken.MaxWidth.Type.BodySmall -> maxWidthType.body.small + OudsSizeKeyToken.MaxWidth.Type.BodyMedium -> maxWidthType.body.medium + OudsSizeKeyToken.MaxWidth.Type.BodyLarge -> maxWidthType.body.large + }.getValue(adaptiveWindowType) +} + +val OudsSizeKeyToken.value: Dp @Composable - get() = OudsTheme.sizes.fromToken(this, OudsAdaptiveWindowType.fromWindowWidth(currentWindowWidth())) \ No newline at end of file + get() = when (this) { + is OudsSizeKeyToken.Icon.Decorative -> OudsTheme.sizes.fromToken(this) + is OudsSizeKeyToken.Icon.WithHeadingExtraLarge -> OudsTheme.sizes.fromToken(this, OudsAdaptiveWindowType.fromWindowWidth(currentWindowWidth())) + is OudsSizeKeyToken.Icon.WithHeadingLarge -> OudsTheme.sizes.fromToken(this, OudsAdaptiveWindowType.fromWindowWidth(currentWindowWidth())) + is OudsSizeKeyToken.Icon.WithHeadingMedium -> OudsTheme.sizes.fromToken(this, OudsAdaptiveWindowType.fromWindowWidth(currentWindowWidth())) + is OudsSizeKeyToken.Icon.WithHeadingSmall -> OudsTheme.sizes.fromToken(this, OudsAdaptiveWindowType.fromWindowWidth(currentWindowWidth())) + is OudsSizeKeyToken.Icon.WithBodyLarge -> OudsTheme.sizes.fromToken(this, OudsAdaptiveWindowType.fromWindowWidth(currentWindowWidth())) + is OudsSizeKeyToken.Icon.WithBodyMedium -> OudsTheme.sizes.fromToken(this, OudsAdaptiveWindowType.fromWindowWidth(currentWindowWidth())) + is OudsSizeKeyToken.Icon.WithBodySmall -> OudsTheme.sizes.fromToken(this, OudsAdaptiveWindowType.fromWindowWidth(currentWindowWidth())) + is OudsSizeKeyToken.Icon.WithLabelExtraLarge -> OudsTheme.sizes.fromToken(this) + is OudsSizeKeyToken.Icon.WithLabelLarge -> OudsTheme.sizes.fromToken(this) + is OudsSizeKeyToken.Icon.WithLabelMedium -> OudsTheme.sizes.fromToken(this) + is OudsSizeKeyToken.Icon.WithLabelSmall -> OudsTheme.sizes.fromToken(this) + is OudsSizeKeyToken.MaxWidth -> OudsTheme.sizes.fromToken(this, OudsAdaptiveWindowType.fromWindowWidth(currentWindowWidth())) + } diff --git a/core/src/main/java/com/orange/ouds/core/theme/OudsSpaces.kt b/core/src/main/java/com/orange/ouds/core/theme/OudsSpaces.kt index 1ab85055..b2d91dfc 100644 --- a/core/src/main/java/com/orange/ouds/core/theme/OudsSpaces.kt +++ b/core/src/main/java/com/orange/ouds/core/theme/OudsSpaces.kt @@ -13,7 +13,6 @@ package com.orange.ouds.core.theme import androidx.compose.runtime.Composable -import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.runtime.Stable import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp @@ -366,7 +365,7 @@ fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.Fixed): Dp { @Stable fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.Scaled, adaptiveWindowType: OudsAdaptiveWindowType): Dp { - val dimensionAdaptableSpaceToken = when (token) { + return when (token) { OudsSpaceKeyToken.Scaled.None -> scaled.none OudsSpaceKeyToken.Scaled.Smash -> scaled.smash OudsSpaceKeyToken.Scaled.Shortest -> scaled.shortest @@ -377,13 +376,7 @@ fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.Scaled, adaptiveWindowType: Ou OudsSpaceKeyToken.Scaled.Taller -> scaled.taller OudsSpaceKeyToken.Scaled.Tallest -> scaled.tallest OudsSpaceKeyToken.Scaled.Spacious -> scaled.spacious - } - - return when (adaptiveWindowType) { - OudsAdaptiveWindowType.EXTRA_COMPACT -> dimensionAdaptableSpaceToken.extraCompact - OudsAdaptiveWindowType.COMPACT -> dimensionAdaptableSpaceToken.compact - OudsAdaptiveWindowType.MEDIUM -> dimensionAdaptableSpaceToken.medium - } + }.getValue(adaptiveWindowType) } @Stable @@ -396,12 +389,7 @@ fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.PaddingInline): Dp { OudsSpaceKeyToken.PaddingInline.Tall -> paddingInline.tall OudsSpaceKeyToken.PaddingInline.Taller -> paddingInline.taller OudsSpaceKeyToken.PaddingInline.Tallest -> paddingInline.tallest - } -} -@Stable -fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.PaddingInline.WithIcon): Dp { - return when (token) { OudsSpaceKeyToken.PaddingInline.WithIcon.None -> paddingInline.withIcon.none OudsSpaceKeyToken.PaddingInline.WithIcon.Shortest -> paddingInline.withIcon.shortest OudsSpaceKeyToken.PaddingInline.WithIcon.Shorter -> paddingInline.withIcon.shorter @@ -410,12 +398,7 @@ fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.PaddingInline.WithIcon): Dp { OudsSpaceKeyToken.PaddingInline.WithIcon.Tall -> paddingInline.withIcon.tall OudsSpaceKeyToken.PaddingInline.WithIcon.Taller -> paddingInline.withIcon.taller OudsSpaceKeyToken.PaddingInline.WithIcon.Tallest -> paddingInline.withIcon.tallest - } -} -@Stable -fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.PaddingInline.WithArrow): Dp { - return when (token) { OudsSpaceKeyToken.PaddingInline.WithArrow.None -> paddingInline.withArrow.none OudsSpaceKeyToken.PaddingInline.WithArrow.Shortest -> paddingInline.withArrow.shortest OudsSpaceKeyToken.PaddingInline.WithArrow.Shorter -> paddingInline.withArrow.shorter @@ -437,12 +420,7 @@ fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.PaddingBlock): Dp { OudsSpaceKeyToken.PaddingBlock.Tall -> paddingBlock.tall OudsSpaceKeyToken.PaddingBlock.Taller -> paddingBlock.taller OudsSpaceKeyToken.PaddingBlock.Tallest -> paddingBlock.tallest - } -} -@Stable -fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.PaddingBlock.WithIcon): Dp { - return when (token) { OudsSpaceKeyToken.PaddingBlock.WithIcon.None -> paddingBlock.withIcon.none OudsSpaceKeyToken.PaddingBlock.WithIcon.Shortest -> paddingBlock.withIcon.shortest OudsSpaceKeyToken.PaddingBlock.WithIcon.Shorter -> paddingBlock.withIcon.shorter @@ -478,24 +456,14 @@ fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.ColumnGap): Dp { OudsSpaceKeyToken.ColumnGap.Medium -> columnGap.medium OudsSpaceKeyToken.ColumnGap.Tall -> columnGap.tall OudsSpaceKeyToken.ColumnGap.Taller -> columnGap.taller - } -} -@Stable -fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.ColumnGap.WithIcon): Dp { - return when (token) { OudsSpaceKeyToken.ColumnGap.WithIcon.None -> columnGap.withIcon.none OudsSpaceKeyToken.ColumnGap.WithIcon.Shortest -> columnGap.withIcon.shortest OudsSpaceKeyToken.ColumnGap.WithIcon.Shorter -> columnGap.withIcon.shorter OudsSpaceKeyToken.ColumnGap.WithIcon.Short -> columnGap.withIcon.short OudsSpaceKeyToken.ColumnGap.WithIcon.Medium -> columnGap.withIcon.medium OudsSpaceKeyToken.ColumnGap.WithIcon.Tall -> columnGap.withIcon.tall - } -} -@Stable -fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.ColumnGap.WithArrow): Dp { - return when (token) { OudsSpaceKeyToken.ColumnGap.WithArrow.None -> columnGap.withArrow.none OudsSpaceKeyToken.ColumnGap.WithArrow.Shortest -> columnGap.withArrow.shortest OudsSpaceKeyToken.ColumnGap.WithArrow.Shorter -> columnGap.withArrow.shorter @@ -514,12 +482,7 @@ fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.RowGap): Dp { OudsSpaceKeyToken.RowGap.Short -> rowGap.short OudsSpaceKeyToken.RowGap.Medium -> rowGap.medium OudsSpaceKeyToken.RowGap.Tall -> rowGap.tall - } -} -@Stable -fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.RowGap.WithIcon): Dp { - return when (token) { OudsSpaceKeyToken.RowGap.WithIcon.None -> rowGap.withIcon.none OudsSpaceKeyToken.RowGap.WithIcon.Shortest -> rowGap.withIcon.shortest OudsSpaceKeyToken.RowGap.WithIcon.Shorter -> rowGap.withIcon.shorter @@ -530,106 +493,16 @@ fun OudsSpaces.fromToken(token: OudsSpaceKeyToken.RowGap.WithIcon): Dp { } /** - * Converts an OUDS column gap space token to the local column gap space value provided by the theme. - */ -val OudsSpaceKeyToken.ColumnGap.value: Dp - @ReadOnlyComposable - @Composable - get() = OudsTheme.spaces.fromToken(this) - -/** - * Converts an OUDS column gap with icon space token to the local column gap with icon space value provided by the theme. - */ -val OudsSpaceKeyToken.ColumnGap.WithIcon.value: Dp - @ReadOnlyComposable - @Composable - get() = OudsTheme.spaces.fromToken(this) - -/** - * Converts an OUDS column gap with arrow space token to the local column gap with arrow space value provided by the theme. + * Converts an OUDS space token to the local space value provided by the theme. */ -val OudsSpaceKeyToken.ColumnGap.WithArrow.value: Dp - @ReadOnlyComposable +val OudsSpaceKeyToken.value: Dp @Composable - get() = OudsTheme.spaces.fromToken(this) - - -/** - * Converts an OUDS fixed space token to the local space value provided by the theme. - */ -val OudsSpaceKeyToken.Fixed.value: Dp - @ReadOnlyComposable - @Composable - get() = OudsTheme.spaces.fromToken(this) - -/** - * Converts an OUDS block padding token to the local block padding value provided by the theme. - */ -val OudsSpaceKeyToken.PaddingBlock.value: Dp - @ReadOnlyComposable - @Composable - get() = OudsTheme.spaces.fromToken(this) - -/** - * Converts an OUDS block with icon padding token to the local block with icon padding value provided by the theme. - */ -val OudsSpaceKeyToken.PaddingBlock.WithIcon.value: Dp - @ReadOnlyComposable - @Composable - get() = OudsTheme.spaces.fromToken(this) - - -/** - * Converts an OUDS inline padding token to the local inline padding value provided by the theme. - */ -val OudsSpaceKeyToken.PaddingInline.value: Dp - @ReadOnlyComposable - @Composable - get() = OudsTheme.spaces.fromToken(this) - -/** - * Converts an OUDS inline padding with icon token to the local inline padding with icon value provided by the theme. - */ -val OudsSpaceKeyToken.PaddingInline.WithIcon.value: Dp - @ReadOnlyComposable - @Composable - get() = OudsTheme.spaces.fromToken(this) - -/** - * Converts an OUDS inline padding with arrow token to the local inline padding with arrow value provided by the theme. - */ -val OudsSpaceKeyToken.PaddingInline.WithArrow.value: Dp - @ReadOnlyComposable - @Composable - get() = OudsTheme.spaces.fromToken(this) - -/** - * Converts an OUDS inset token to the local inset value provided by the theme. - */ -val OudsSpaceKeyToken.Inset.value: Dp - @ReadOnlyComposable - @Composable - get() = OudsTheme.spaces.fromToken(this) - -/** - * Converts an OUDS row gap space token to the local row gap space value provided by the theme. - */ -val OudsSpaceKeyToken.RowGap.value: Dp - @ReadOnlyComposable - @Composable - get() = OudsTheme.spaces.fromToken(this) - -/** - * Converts an OUDS row gap with icon space token to the local row gap with icon space value provided by the theme. - */ -val OudsSpaceKeyToken.RowGap.WithIcon.value: Dp - @ReadOnlyComposable - @Composable - get() = OudsTheme.spaces.fromToken(this) - -/** - * Converts an OUDS scaled space token to the local space value provided by the theme depending on the window size. - */ -val OudsSpaceKeyToken.Scaled.value: Dp - @Composable - get() = OudsTheme.spaces.fromToken(this, OudsAdaptiveWindowType.fromWindowWidth(currentWindowWidth())) + get() = when (this) { + is OudsSpaceKeyToken.ColumnGap -> OudsTheme.spaces.fromToken(this) + is OudsSpaceKeyToken.Fixed -> OudsTheme.spaces.fromToken(this) + is OudsSpaceKeyToken.Inset -> OudsTheme.spaces.fromToken(this) + is OudsSpaceKeyToken.PaddingBlock -> OudsTheme.spaces.fromToken(this) + is OudsSpaceKeyToken.PaddingInline -> OudsTheme.spaces.fromToken(this) + is OudsSpaceKeyToken.RowGap -> OudsTheme.spaces.fromToken(this) + is OudsSpaceKeyToken.Scaled -> OudsTheme.spaces.fromToken(this, OudsAdaptiveWindowType.fromWindowWidth(currentWindowWidth())) + } diff --git a/core/src/main/java/com/orange/ouds/core/theme/OudsTypography.kt b/core/src/main/java/com/orange/ouds/core/theme/OudsTypography.kt index c5af363a..1fdd58c2 100644 --- a/core/src/main/java/com/orange/ouds/core/theme/OudsTypography.kt +++ b/core/src/main/java/com/orange/ouds/core/theme/OudsTypography.kt @@ -411,27 +411,27 @@ fun OudsFontSemanticTokens.getTypography(fontFamily: FontFamily) = OudsTypograph @Stable fun OudsTypography.fromToken(token: OudsTypographyKeyToken, adaptiveWindowType: OudsAdaptiveWindowType): TextStyle { val typography: Any = when (token) { - OudsTypographyKeyToken.DisplayLarge -> displayLarge - OudsTypographyKeyToken.DisplayMedium -> displayMedium - OudsTypographyKeyToken.DisplaySmall -> displaySmall - OudsTypographyKeyToken.HeadingExtraLarge -> headingExtraLarge - OudsTypographyKeyToken.HeadingLarge -> headingLarge - OudsTypographyKeyToken.HeadingMedium -> headingMedium - OudsTypographyKeyToken.HeadingSmall -> headingSmall - OudsTypographyKeyToken.BodyDefaultLarge -> bodyDefaultLarge - OudsTypographyKeyToken.BodyDefaultMedium -> bodyDefaultMedium - OudsTypographyKeyToken.BodyDefaultSmall -> bodyDefaultSmall - OudsTypographyKeyToken.BodyStrongLarge -> bodyStrongLarge - OudsTypographyKeyToken.BodyStrongMedium -> bodyStrongMedium - OudsTypographyKeyToken.BodyStrongSmall -> bodyStrongSmall - OudsTypographyKeyToken.LabelDefaultExtraLarge -> labelDefaultExtraLarge - OudsTypographyKeyToken.LabelDefaultLarge -> labelDefaultLarge - OudsTypographyKeyToken.LabelDefaultMedium -> labelDefaultMedium - OudsTypographyKeyToken.LabelDefaultSmall -> labelDefaultSmall - OudsTypographyKeyToken.LabelStrongExtraLarge -> labelStrongExtraLarge - OudsTypographyKeyToken.LabelStrongLarge -> labelStrongLarge - OudsTypographyKeyToken.LabelStrongMedium -> labelStrongMedium - OudsTypographyKeyToken.LabelStrongSmall -> labelStrongSmall + OudsTypographyKeyToken.Display.Large -> displayLarge + OudsTypographyKeyToken.Display.Medium -> displayMedium + OudsTypographyKeyToken.Display.Small -> displaySmall + OudsTypographyKeyToken.Heading.ExtraLarge -> headingExtraLarge + OudsTypographyKeyToken.Heading.Large -> headingLarge + OudsTypographyKeyToken.Heading.Medium -> headingMedium + OudsTypographyKeyToken.Heading.Small -> headingSmall + OudsTypographyKeyToken.Body.Default.Large -> bodyDefaultLarge + OudsTypographyKeyToken.Body.Default.Medium -> bodyDefaultMedium + OudsTypographyKeyToken.Body.Default.Small -> bodyDefaultSmall + OudsTypographyKeyToken.Body.Strong.Large -> bodyStrongLarge + OudsTypographyKeyToken.Body.Strong.Medium -> bodyStrongMedium + OudsTypographyKeyToken.Body.Strong.Small -> bodyStrongSmall + OudsTypographyKeyToken.Label.Default.ExtraLarge -> labelDefaultExtraLarge + OudsTypographyKeyToken.Label.Default.Large -> labelDefaultLarge + OudsTypographyKeyToken.Label.Default.Medium -> labelDefaultMedium + OudsTypographyKeyToken.Label.Default.Small -> labelDefaultSmall + OudsTypographyKeyToken.Label.Strong.ExtraLarge -> labelStrongExtraLarge + OudsTypographyKeyToken.Label.Strong.Large -> labelStrongLarge + OudsTypographyKeyToken.Label.Strong.Medium -> labelStrongMedium + OudsTypographyKeyToken.Label.Strong.Small -> labelStrongSmall } return if (typography is OudsAdaptiveTokenValue<*>) { diff --git a/foundation/src/main/java/com/orange/ouds/foundation/extensions/StandardExt.kt b/foundation/src/main/java/com/orange/ouds/foundation/extensions/StandardExt.kt index 349c5d1e..ddd02eca 100644 --- a/foundation/src/main/java/com/orange/ouds/foundation/extensions/StandardExt.kt +++ b/foundation/src/main/java/com/orange/ouds/foundation/extensions/StandardExt.kt @@ -35,3 +35,5 @@ inline fun tryOrNull(block: () -> R): R? { null } } + +inline fun Any.asOrNull(): V? = this as? V 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 5105dac4..46108e2c 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,29 +12,33 @@ package com.orange.ouds.theme.tokens -object OudsBorderKeyToken { - enum class Width { - None, - Default, - Thin, - Medium, - Thick, - Thicker, - Focus, - FocusInset +sealed interface OudsBorderKeyToken { + + sealed interface Width : OudsBorderKeyToken { + data object None : Width + data object Default : Width + data object Thin : Width + data object Medium : Width + data object Thick : Width + data object Thicker : Width + + sealed interface Focus : Width { + companion object : Focus + data object Inset : Focus + } } - enum class Radius { - None, - Default, - Short, - Medium, - Tall, - Pill + sealed interface Radius : OudsBorderKeyToken { + data object None : Radius + data object Default : Radius + data object Short : Radius + data object Medium : Radius + data object Tall : Radius + data object Pill : Radius } - enum class Style { - Default, - Drag + sealed interface Style : OudsBorderKeyToken { + data object Default : Style + data object Drag : Style } } \ No newline at end of file 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 9e21edb2..0e534f37 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,11 +12,12 @@ package com.orange.ouds.theme.tokens -enum class OudsElevationKeyToken { - None, - Raised, - OverlayDefault, - AllSticky, - Drag, - OverlayEmphasized +sealed interface OudsElevationKeyToken { + + data object None : OudsElevationKeyToken + data object Raised : OudsElevationKeyToken + data object OverlayDefault : OudsElevationKeyToken + data object AllSticky : OudsElevationKeyToken + data object Drag : OudsElevationKeyToken + data object OverlayEmphasized : OudsElevationKeyToken } \ No newline at end of file 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 e66d641c..4e9f0a90 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,9 +12,10 @@ package com.orange.ouds.theme.tokens -enum class OudsGridKeyToken { - MinWidth, - MaxWidth, - ColumnGap, - Margin, +sealed interface OudsGridKeyToken { + + data object MinWidth : OudsGridKeyToken + data object MaxWidth : OudsGridKeyToken + data object ColumnGap : OudsGridKeyToken + data object Margin : OudsGridKeyToken } \ No newline at end of file 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 492fe399..1012b4a8 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,11 +12,12 @@ package com.orange.ouds.theme.tokens -enum class OudsOpacityKeyToken { - Transparent, - Weaker, - Weak, - Medium, - Strong, - Opaque +sealed interface OudsOpacityKeyToken { + + data object Transparent : OudsOpacityKeyToken + data object Weaker : OudsOpacityKeyToken + data object Weak : OudsOpacityKeyToken + data object Medium : OudsOpacityKeyToken + data object Strong : OudsOpacityKeyToken + data object Opaque : OudsOpacityKeyToken } \ No newline at end of file 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 3623189a..fe730ce2 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,65 +12,100 @@ package com.orange.ouds.theme.tokens -object OudsSizeKeyToken { - enum class IconDecorative { - Shortest, - Shorter, - Short, - Medium, - Tall, - Taller, - Tallest, - } +sealed interface OudsSizeKeyToken { + + sealed interface Icon : OudsSizeKeyToken { + sealed interface Decorative : Icon { + data object Shortest : Decorative + data object Shorter : Decorative + data object Short : Decorative + data object Medium : Decorative + data object Tall : Decorative + data object Taller : Decorative + data object Tallest : Decorative + } + + sealed interface WithHeadingExtraLarge : Icon { + data object SizeShort : WithHeadingExtraLarge + data object SizeMedium : WithHeadingExtraLarge + data object SizeTall : WithHeadingExtraLarge + } + + sealed interface WithHeadingLarge : Icon { + data object SizeShort : WithHeadingLarge + data object SizeMedium : WithHeadingLarge + data object SizeTall : WithHeadingLarge + } + + sealed interface WithHeadingMedium : Icon { + data object SizeShort : WithHeadingMedium + data object SizeMedium : WithHeadingMedium + data object SizeTall : WithHeadingMedium + } + + sealed interface WithHeadingSmall : Icon { + data object SizeShort : WithHeadingSmall + data object SizeMedium : WithHeadingSmall + data object SizeTall : WithHeadingSmall + } + + sealed interface WithBodyLarge : Icon { + data object SizeShort : WithBodyLarge + data object SizeMedium : WithBodyLarge + data object SizeTall : WithBodyLarge + } + + sealed interface WithBodyMedium : Icon { + data object SizeShort : WithBodyMedium + data object SizeMedium : WithBodyMedium + data object SizeTall : WithBodyMedium + } + + sealed interface WithBodySmall : Icon { + data object SizeShort : WithBodySmall + data object SizeMedium : WithBodySmall + data object SizeTall : WithBodySmall + } + + sealed interface WithLabelExtraLarge : Icon { + data object SizeShort : WithLabelExtraLarge + data object SizeMedium : WithLabelExtraLarge + data object SizeTall : WithLabelExtraLarge + } + + sealed interface WithLabelLarge : Icon { + data object SizeShorter : WithLabelLarge + data object SizeShort : WithLabelLarge + data object SizeMedium : WithLabelLarge + data object SizeTall : WithLabelLarge + data object SizeTaller : WithLabelLarge + } + + sealed interface WithLabelMedium : Icon { + data object SizeShort : WithLabelMedium + data object SizeMedium : WithLabelMedium + data object SizeTall : WithLabelMedium + } - enum class IconWithText { - HeadingExtraLargeSizeShort, - HeadingExtraLargeSizeMedium, - HeadingExtraLargeSizeTall, - HeadingLargeSizeShort, - HeadingLargeSizeMedium, - HeadingLargeSizeTall, - HeadingMediumSizeShort, - HeadingMediumSizeMedium, - HeadingMediumSizeTall, - HeadingSmallSizeShort, - HeadingSmallSizeMedium, - HeadingSmallSizeTall, - BodyLargeSizeShort, - BodyLargeSizeMedium, - BodyLargeSizeTall, - BodyMediumSizeShort, - BodyMediumSizeMedium, - BodyMediumSizeTall, - BodySmallSizeShort, - BodySmallSizeMedium, - BodySmallSizeTall, - LabelExtraLargeSizeShort, - LabelExtraLargeSizeMedium, - LabelExtraLargeSizeTall, - LabelLargeSizeShorter, - LabelLargeSizeShort, - LabelLargeSizeMedium, - LabelLargeSizeTall, - LabelLargeSizeTaller, - LabelMediumSizeShort, - LabelMediumSizeMedium, - LabelMediumSizeTall, - LabelSmallSizeShort, - LabelSmallSizeMedium, - LabelSmallSizeTall, + sealed interface WithLabelSmall : Icon { + data object SizeShort : WithLabelSmall + data object SizeMedium : WithLabelSmall + data object SizeTall : WithLabelSmall + } } - enum class MaxWidthType { - DisplaySmall, - DisplayMedium, - DisplayLarge, - HeadingSmall, - HeadingMedium, - HeadingLarge, - HeadingExtraLarge, - BodySmall, - BodyMedium, - BodyLarge + sealed interface MaxWidth : OudsSizeKeyToken { + sealed interface Type : MaxWidth { + data object DisplaySmall : Type + data object DisplayMedium : Type + data object DisplayLarge : Type + data object HeadingSmall : Type + data object HeadingMedium : Type + data object HeadingLarge : Type + data object HeadingExtraLarge : Type + data object BodySmall : Type + data object BodyMedium : Type + data object BodyLarge : Type + } } } \ No newline at end of file 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 5ec00f4a..ed9c966c 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,142 +12,143 @@ package com.orange.ouds.theme.tokens -object OudsSpaceKeyToken { - enum class Fixed { - None, - Smash, - Shortest, - Shorter, - Short, - Medium, - Tall, - Taller, - Tallest, - Spacious, - Huge, - Jumbo +sealed interface OudsSpaceKeyToken { + + sealed interface Fixed : OudsSpaceKeyToken { + data object None : Fixed + data object Smash : Fixed + data object Shortest : Fixed + data object Shorter : Fixed + data object Short : Fixed + data object Medium : Fixed + data object Tall : Fixed + data object Taller : Fixed + data object Tallest : Fixed + data object Spacious : Fixed + data object Huge : Fixed + data object Jumbo : Fixed } - enum class Scaled { - None, - Smash, - Shortest, - Shorter, - Short, - Medium, - Tall, - Taller, - Tallest, - Spacious + sealed interface Scaled : OudsSpaceKeyToken { + data object None : Scaled + data object Smash : Scaled + data object Shortest : Scaled + data object Shorter : Scaled + data object Short : Scaled + data object Medium : Scaled + data object Tall : Scaled + data object Taller : Scaled + data object Tallest : Scaled + data object Spacious : Scaled } - enum class PaddingInline { - None, - Shorter, - Short, - Medium, - Tall, - Taller, - Tallest; + sealed interface PaddingInline : OudsSpaceKeyToken { + data object None : PaddingInline + data object Shorter : PaddingInline + data object Short : PaddingInline + data object Medium : PaddingInline + data object Tall : PaddingInline + data object Taller : PaddingInline + data object Tallest : PaddingInline - enum class WithIcon { - None, - Shortest, - Shorter, - Short, - Medium, - Tall, - Taller, - Tallest, + sealed interface WithIcon : PaddingInline { + data object None : WithIcon + data object Shortest : WithIcon + data object Shorter : WithIcon + data object Short : WithIcon + data object Medium : WithIcon + data object Tall : WithIcon + data object Taller : WithIcon + data object Tallest : WithIcon } - enum class WithArrow { - None, - Shortest, - Shorter, - Short, - Medium, - Tall, - Taller, - Tallest, + sealed interface WithArrow : PaddingInline { + data object None : WithArrow + data object Shortest : WithArrow + data object Shorter : WithArrow + data object Short : WithArrow + data object Medium : WithArrow + data object Tall : WithArrow + data object Taller : WithArrow + data object Tallest : WithArrow } } - enum class PaddingBlock { - None, - Shorter, - Short, - Medium, - Tall, - Taller, - Tallest; + sealed interface PaddingBlock : OudsSpaceKeyToken { + data object None : PaddingBlock + data object Shorter : PaddingBlock + data object Short : PaddingBlock + data object Medium : PaddingBlock + data object Tall : PaddingBlock + data object Taller : PaddingBlock + data object Tallest : PaddingBlock - enum class WithIcon { - None, - Shortest, - Shorter, - Short, - Medium, - Tall, - Taller, + sealed interface WithIcon : PaddingBlock { + data object None : WithIcon + data object Shortest : WithIcon + data object Shorter : WithIcon + data object Short : WithIcon + data object Medium : WithIcon + data object Tall : WithIcon + data object Taller : WithIcon } } - enum class Inset { - None, - Smash, - Shortest, - Shorter, - Short, - Medium, - Tall, - Taller, - Tallest, - Spacious, + sealed interface Inset : OudsSpaceKeyToken { + data object None : Inset + data object Smash : Inset + data object Shortest : Inset + data object Shorter : Inset + data object Short : Inset + data object Medium : Inset + data object Tall : Inset + data object Taller : Inset + data object Tallest : Inset + data object Spacious : Inset } - enum class ColumnGap { - None, - Shorter, - Short, - Medium, - Tall, - Taller; + sealed interface ColumnGap : OudsSpaceKeyToken { + data object None : ColumnGap + data object Shorter : ColumnGap + data object Short : ColumnGap + data object Medium : ColumnGap + data object Tall : ColumnGap + data object Taller : ColumnGap - enum class WithIcon { - None, - Shortest, - Shorter, - Short, - Medium, - Tall, + sealed interface WithIcon : ColumnGap { + data object None : WithIcon + data object Shortest : WithIcon + data object Shorter : WithIcon + data object Short : WithIcon + data object Medium : WithIcon + data object Tall : WithIcon } - enum class WithArrow { - None, - Shortest, - Shorter, - Short, - Medium, - Tall, + sealed interface WithArrow : ColumnGap { + data object None : WithArrow + data object Shortest : WithArrow + data object Shorter : WithArrow + data object Short : WithArrow + data object Medium : WithArrow + data object Tall : WithArrow } } - enum class RowGap { - None, - Shortest, - Shorter, - Short, - Medium, - Tall; + sealed interface RowGap : OudsSpaceKeyToken { + data object None : RowGap + data object Shortest : RowGap + data object Shorter : RowGap + data object Short : RowGap + data object Medium : RowGap + data object Tall : RowGap - enum class WithIcon { - None, - Shortest, - Shorter, - Short, - Medium, - Tall, + sealed interface WithIcon : RowGap { + data object None : WithIcon + data object Shortest : WithIcon + data object Shorter : WithIcon + data object Short : WithIcon + data object Medium : WithIcon + data object Tall : WithIcon } } } \ No newline at end of file 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 e9462e68..1ffbcdf1 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,26 +12,48 @@ package com.orange.ouds.theme.tokens -enum class OudsTypographyKeyToken { - DisplayLarge, - DisplayMedium, - DisplaySmall, - HeadingExtraLarge, - HeadingLarge, - HeadingMedium, - HeadingSmall, - BodyDefaultLarge, - BodyDefaultMedium, - BodyDefaultSmall, - BodyStrongLarge, - BodyStrongMedium, - BodyStrongSmall, - LabelDefaultExtraLarge, - LabelDefaultLarge, - LabelDefaultMedium, - LabelDefaultSmall, - LabelStrongExtraLarge, - LabelStrongLarge, - LabelStrongMedium, - LabelStrongSmall +sealed interface OudsTypographyKeyToken { + + sealed interface Display : OudsTypographyKeyToken { + data object Large : Display + data object Medium : Display + data object Small : Display + } + + sealed interface Heading : OudsTypographyKeyToken { + data object ExtraLarge : Heading + data object Large : Heading + data object Medium : Heading + data object Small : Heading + } + + sealed interface Body : OudsTypographyKeyToken { + sealed interface Default : Body { + data object Large : Default + data object Medium : Default + data object Small : Default + } + + sealed interface Strong : Body { + data object Large : Strong + data object Medium : Strong + data object Small : Strong + } + } + + sealed interface Label : OudsTypographyKeyToken { + sealed interface Default : Label { + data object ExtraLarge : Default + data object Large : Default + data object Medium : Default + data object Small : Default + } + + sealed interface Strong : Label { + data object ExtraLarge : Strong + data object Large : Strong + data object Medium : Strong + data object Small : Strong + } + } } \ No newline at end of file diff --git a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/components/OudsButtonTokens.kt b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/components/OudsButtonTokens.kt index 6039f3f0..32ec9cf1 100644 --- a/theme-contract/src/main/java/com/orange/ouds/theme/tokens/components/OudsButtonTokens.kt +++ b/theme-contract/src/main/java/com/orange/ouds/theme/tokens/components/OudsButtonTokens.kt @@ -29,7 +29,7 @@ open class OudsButtonTokens( val focusedElevation: OudsElevationKeyToken = OudsElevationKeyToken.None, val hoveredElevation: OudsElevationKeyToken = OudsElevationKeyToken.None, val disabledElevation: OudsElevationKeyToken = OudsElevationKeyToken.None, - val labelStyle: OudsTypographyKeyToken = OudsTypographyKeyToken.BodyStrongLarge, + val labelStyle: OudsTypographyKeyToken = OudsTypographyKeyToken.Body.Strong.Large, val verticalContentPadding: OudsSpaceKeyToken.Fixed = OudsSpaceKeyToken.Fixed.Smash, val horizontalContentPadding: OudsSpaceKeyToken.Fixed = OudsSpaceKeyToken.Fixed.Tall ) \ No newline at end of file diff --git a/theme-white-label/src/main/java/com/orange/ouds/theme/whitelabel/WhiteLabelTheme.kt b/theme-white-label/src/main/java/com/orange/ouds/theme/whitelabel/WhiteLabelTheme.kt index 6c02c36e..d53f0b38 100644 --- a/theme-white-label/src/main/java/com/orange/ouds/theme/whitelabel/WhiteLabelTheme.kt +++ b/theme-white-label/src/main/java/com/orange/ouds/theme/whitelabel/WhiteLabelTheme.kt @@ -44,7 +44,7 @@ open class WhiteLabelTheme : OudsThemeContract { defaultElevation = OudsElevationKeyToken.OverlayDefault, focusedElevation = OudsElevationKeyToken.OverlayDefault, hoveredElevation = OudsElevationKeyToken.OverlayDefault, - labelStyle = OudsTypographyKeyToken.BodyDefaultLarge, + labelStyle = OudsTypographyKeyToken.Body.Default.Large, verticalContentPadding = OudsSpaceKeyToken.Fixed.Shortest, horizontalContentPadding = OudsSpaceKeyToken.Fixed.Short )