Skip to content

Commit

Permalink
chore: update tokens (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
boosted-bot authored Dec 18, 2024
1 parent 8d9ccc0 commit eccb9d1
Show file tree
Hide file tree
Showing 29 changed files with 1,291 additions and 508 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fun ComponentsScreen() {
.padding(top = OudsSpaceKeyToken.Fixed.Medium.value)
.width(OudsGridKeyToken.Margin.value)
.height(OudsGridKeyToken.ColumnGap.value)
.background(OudsColorKeyToken.Content.Brand.Primary.value)
.background(OudsColorKeyToken.Content.BrandPrimary.value)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private fun CodeColumn(codeExample: String, modifier: Modifier = Modifier) {
Icon(
modifier = Modifier.rotate(linkArrowRotation),
painter = painterResource(R.drawable.ic_chevron_down),
tint = OudsColorKeyToken.Content.Brand.Primary.value,
tint = OudsColorKeyToken.Content.BrandPrimary.value,
contentDescription = null
)
}
Expand Down
212 changes: 201 additions & 11 deletions app/src/main/java/com/orange/ouds/app/ui/tokens/TokenProperty.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ sealed class TokenProperty<T>(
data object SizeIconWithText : TokenProperty<TokenCategory.Dimension.Size>(
nameRes = R.string.app_tokens_dimension_size_iconWithText_label,
tokens = 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,
OudsSizeKeyToken.Icon.WithHeading.ExtraLarge::class,
OudsSizeKeyToken.Icon.WithHeading.Large::class,
OudsSizeKeyToken.Icon.WithHeading.Medium::class,
OudsSizeKeyToken.Icon.WithHeading.Small::class,
OudsSizeKeyToken.Icon.WithBody.Large::class,
OudsSizeKeyToken.Icon.WithBody.Medium::class,
OudsSizeKeyToken.Icon.WithBody.Small::class,
OudsSizeKeyToken.Icon.WithLabel.ExtraLarge::class,
OudsSizeKeyToken.Icon.WithLabel.Large::class,
OudsSizeKeyToken.Icon.WithLabel.Medium::class,
OudsSizeKeyToken.Icon.WithLabel.Small::class,
).flatMap { keyTokenClass ->
keyTokenClass.getTokens(tokenName = { it.getTokenName(OudsSizeKeyToken.Icon::class).removePrefix("With") })
},
Expand Down Expand Up @@ -190,3 +190,193 @@ sealed class TokenProperty<T>(
categoryClass = TokenCategory.Typography::class
)
}

val OudsBorderKeyToken.Radius.order: Int
get() = when (this) {
OudsBorderKeyToken.Radius.None -> 0
OudsBorderKeyToken.Radius.Default -> 1
OudsBorderKeyToken.Radius.Short -> 2
OudsBorderKeyToken.Radius.Medium -> 3
OudsBorderKeyToken.Radius.Tall -> 4
OudsBorderKeyToken.Radius.Pill -> 5
}

val OudsBorderKeyToken.Width.order: Int
get() = when (this) {
OudsBorderKeyToken.Width.None -> 0
OudsBorderKeyToken.Width.Default -> 1
OudsBorderKeyToken.Width.Thin -> 2
OudsBorderKeyToken.Width.Medium -> 3
OudsBorderKeyToken.Width.Thick -> 4
OudsBorderKeyToken.Width.Thicker -> 5
OudsBorderKeyToken.Width.Focus -> 6
OudsBorderKeyToken.Width.FocusInset -> 7
}

val OudsElevationKeyToken.order: Int
get() = when (this) {
OudsElevationKeyToken.None -> 0
OudsElevationKeyToken.Raised -> 1
OudsElevationKeyToken.OverlayDefault -> 2
OudsElevationKeyToken.StickyDefault -> 3
OudsElevationKeyToken.StickyEmphasized -> 4
OudsElevationKeyToken.StickyNavigationScrolled -> 5
OudsElevationKeyToken.Drag -> 6
OudsElevationKeyToken.OverlayEmphasized -> 7
}

val OudsOpacityKeyToken.order: Int
get() = when (this) {
OudsOpacityKeyToken.Invisible -> 0
OudsOpacityKeyToken.Weaker -> 1
OudsOpacityKeyToken.Weak -> 2
OudsOpacityKeyToken.Medium -> 3
OudsOpacityKeyToken.Strong -> 4
OudsOpacityKeyToken.Opaque -> 5
}

val OudsSizeKeyToken.Icon.order: Int
get() = when (this) {
OudsSizeKeyToken.Icon.Decorative.ExtraExtraSmall -> 0
OudsSizeKeyToken.Icon.Decorative.ExtraSmall -> 1
OudsSizeKeyToken.Icon.Decorative.Small -> 2
OudsSizeKeyToken.Icon.Decorative.Medium -> 3
OudsSizeKeyToken.Icon.Decorative.Large -> 4
OudsSizeKeyToken.Icon.Decorative.ExtraLarge -> 5
OudsSizeKeyToken.Icon.Decorative.ExtraExtraLarge -> 6
OudsSizeKeyToken.Icon.WithHeading.Small.SizeSmall -> 10
OudsSizeKeyToken.Icon.WithHeading.Small.SizeMedium -> 11
OudsSizeKeyToken.Icon.WithHeading.Small.SizeLarge -> 12
OudsSizeKeyToken.Icon.WithHeading.Medium.SizeSmall -> 20
OudsSizeKeyToken.Icon.WithHeading.Medium.SizeMedium -> 21
OudsSizeKeyToken.Icon.WithHeading.Medium.SizeLarge -> 22
OudsSizeKeyToken.Icon.WithHeading.Large.SizeSmall -> 30
OudsSizeKeyToken.Icon.WithHeading.Large.SizeMedium -> 31
OudsSizeKeyToken.Icon.WithHeading.Large.SizeLarge -> 32
OudsSizeKeyToken.Icon.WithHeading.ExtraLarge.SizeSmall -> 40
OudsSizeKeyToken.Icon.WithHeading.ExtraLarge.SizeMedium -> 41
OudsSizeKeyToken.Icon.WithHeading.ExtraLarge.SizeLarge -> 42
OudsSizeKeyToken.Icon.WithBody.Small.SizeSmall -> 50
OudsSizeKeyToken.Icon.WithBody.Small.SizeMedium -> 51
OudsSizeKeyToken.Icon.WithBody.Small.SizeLarge -> 52
OudsSizeKeyToken.Icon.WithBody.Medium.SizeSmall -> 60
OudsSizeKeyToken.Icon.WithBody.Medium.SizeMedium -> 61
OudsSizeKeyToken.Icon.WithBody.Medium.SizeLarge -> 62
OudsSizeKeyToken.Icon.WithBody.Large.SizeSmall -> 70
OudsSizeKeyToken.Icon.WithBody.Large.SizeMedium -> 71
OudsSizeKeyToken.Icon.WithBody.Large.SizeLarge -> 72
OudsSizeKeyToken.Icon.WithLabel.Small.SizeExtraSmall -> 80
OudsSizeKeyToken.Icon.WithLabel.Small.SizeSmall -> 81
OudsSizeKeyToken.Icon.WithLabel.Small.SizeMedium -> 82
OudsSizeKeyToken.Icon.WithLabel.Small.SizeLarge -> 83
OudsSizeKeyToken.Icon.WithLabel.Medium.SizeExtraSmall -> 90
OudsSizeKeyToken.Icon.WithLabel.Medium.SizeSmall -> 91
OudsSizeKeyToken.Icon.WithLabel.Medium.SizeMedium -> 92
OudsSizeKeyToken.Icon.WithLabel.Medium.SizeLarge -> 93
OudsSizeKeyToken.Icon.WithLabel.Large.SizeExtraSmall -> 100
OudsSizeKeyToken.Icon.WithLabel.Large.SizeSmall -> 101
OudsSizeKeyToken.Icon.WithLabel.Large.SizeMedium -> 102
OudsSizeKeyToken.Icon.WithLabel.Large.SizeLarge -> 103
OudsSizeKeyToken.Icon.WithLabel.Large.SizeExtraLarge -> 104
OudsSizeKeyToken.Icon.WithLabel.ExtraLarge.SizeSmall -> 110
OudsSizeKeyToken.Icon.WithLabel.ExtraLarge.SizeMedium -> 111
OudsSizeKeyToken.Icon.WithLabel.ExtraLarge.SizeLarge -> 112
}

val OudsSpaceKeyToken.ColumnGap.order: Int
get() = when (this) {
OudsSpaceKeyToken.ColumnGap.None -> 0
OudsSpaceKeyToken.ColumnGap.Smash -> 1
OudsSpaceKeyToken.ColumnGap.Shortest -> 2
OudsSpaceKeyToken.ColumnGap.Shorter -> 3
OudsSpaceKeyToken.ColumnGap.Short -> 4
OudsSpaceKeyToken.ColumnGap.Medium -> 5
OudsSpaceKeyToken.ColumnGap.Tall -> 6
OudsSpaceKeyToken.ColumnGap.Taller -> 7
OudsSpaceKeyToken.ColumnGap.Tallest -> 8
}

val OudsSpaceKeyToken.Fixed.order: Int
get() = when (this) {
OudsSpaceKeyToken.Fixed.None -> 0
OudsSpaceKeyToken.Fixed.Smash -> 1
OudsSpaceKeyToken.Fixed.Shortest -> 2
OudsSpaceKeyToken.Fixed.Shorter -> 3
OudsSpaceKeyToken.Fixed.Short -> 4
OudsSpaceKeyToken.Fixed.Medium -> 5
OudsSpaceKeyToken.Fixed.Tall -> 6
OudsSpaceKeyToken.Fixed.Taller -> 7
OudsSpaceKeyToken.Fixed.Tallest -> 8
OudsSpaceKeyToken.Fixed.Spacious -> 9
OudsSpaceKeyToken.Fixed.Huge -> 10
OudsSpaceKeyToken.Fixed.Jumbo -> 11
}

val OudsSpaceKeyToken.Inset.order: Int
get() = when (this) {
OudsSpaceKeyToken.Inset.None -> 0
OudsSpaceKeyToken.Inset.Smash -> 1
OudsSpaceKeyToken.Inset.Shortest -> 2
OudsSpaceKeyToken.Inset.Shorter -> 3
OudsSpaceKeyToken.Inset.Short -> 4
OudsSpaceKeyToken.Inset.Medium -> 5
OudsSpaceKeyToken.Inset.Tall -> 6
OudsSpaceKeyToken.Inset.Taller -> 7
OudsSpaceKeyToken.Inset.Tallest -> 8
OudsSpaceKeyToken.Inset.Spacious -> 9
}

val OudsSpaceKeyToken.PaddingBlock.order: Int
get() = when (this) {
OudsSpaceKeyToken.PaddingBlock.None -> 0
OudsSpaceKeyToken.PaddingBlock.Smash -> 1
OudsSpaceKeyToken.PaddingBlock.Shortest -> 2
OudsSpaceKeyToken.PaddingBlock.Shorter -> 3
OudsSpaceKeyToken.PaddingBlock.Short -> 4
OudsSpaceKeyToken.PaddingBlock.Medium -> 5
OudsSpaceKeyToken.PaddingBlock.Tall -> 6
OudsSpaceKeyToken.PaddingBlock.Taller -> 7
OudsSpaceKeyToken.PaddingBlock.Tallest -> 8
OudsSpaceKeyToken.PaddingBlock.Spacious -> 9
OudsSpaceKeyToken.PaddingBlock.Huge -> 10
}

val OudsSpaceKeyToken.PaddingInline.order: Int
get() = when (this) {
OudsSpaceKeyToken.PaddingInline.None -> 0
OudsSpaceKeyToken.PaddingInline.Smash -> 1
OudsSpaceKeyToken.PaddingInline.Shortest -> 2
OudsSpaceKeyToken.PaddingInline.Shorter -> 3
OudsSpaceKeyToken.PaddingInline.Short -> 4
OudsSpaceKeyToken.PaddingInline.Medium -> 5
OudsSpaceKeyToken.PaddingInline.Tall -> 6
OudsSpaceKeyToken.PaddingInline.Taller -> 7
OudsSpaceKeyToken.PaddingInline.Tallest -> 8
OudsSpaceKeyToken.PaddingInline.Spacious -> 9
OudsSpaceKeyToken.PaddingInline.Huge -> 10
}

val OudsSpaceKeyToken.RowGap.order: Int
get() = when (this) {
OudsSpaceKeyToken.RowGap.None -> 0
OudsSpaceKeyToken.RowGap.Smash -> 1
OudsSpaceKeyToken.RowGap.Shortest -> 2
OudsSpaceKeyToken.RowGap.Shorter -> 3
OudsSpaceKeyToken.RowGap.Short -> 4
OudsSpaceKeyToken.RowGap.Medium -> 5
OudsSpaceKeyToken.RowGap.Tall -> 6
}

val OudsSpaceKeyToken.Scaled.order: Int
get() = when (this) {
OudsSpaceKeyToken.Scaled.None -> 0
OudsSpaceKeyToken.Scaled.Smash -> 1
OudsSpaceKeyToken.Scaled.Shortest -> 2
OudsSpaceKeyToken.Scaled.Shorter -> 3
OudsSpaceKeyToken.Scaled.Short -> 4
OudsSpaceKeyToken.Scaled.Medium -> 5
OudsSpaceKeyToken.Scaled.Tall -> 6
OudsSpaceKeyToken.Scaled.Taller -> 7
OudsSpaceKeyToken.Scaled.Tallest -> 8
OudsSpaceKeyToken.Scaled.Spacious -> 9
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -38,8 +37,6 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -139,10 +136,11 @@ fun SizeIconWithTextIllustrationRow(size: Dp, tokenName: String) {
tint = Color(0xFF26B2FF), //TODO use AlwaysInfo token when available
contentDescription = null
)
val tokenTypography = tokenName.split('.').take(2).joinToString(".")
val style = OudsTypographyKeyToken::class.getTokens()
.asOrNull<List<Token<TextStyle>>>()
?.firstOrNull { typographyToken ->
tokenName.split(".").firstOrNull() == typographyToken.name.replace("Strong", "").replace(".", "")
typographyToken.name.replace(".Strong", "") == tokenTypography
}
?.value?.invoke()
.orElse { LocalTextStyle.current }
Expand Down
21 changes: 19 additions & 2 deletions app/src/main/java/com/orange/ouds/app/ui/utilities/KClassExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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
Expand All @@ -30,7 +31,23 @@ fun KClass<*>.getTokens(
recursive: Boolean = true,
tokenName: (KClass<*>) -> String = { it.getTokenName(this) }
): List<Token<*>> {
return getNestedObjects(getRootKeyTokenSuperclass(), recursive).map { keyToken ->
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 = {
Expand All @@ -54,7 +71,7 @@ fun KClass<*>.getTokens(

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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,23 @@ fun OudsButton(
Button(
onClick = onClick,
enabled = enabled,
shape = RoundedCornerShape(cornerRadius.value),
shape = RoundedCornerShape(borderRadius.value),
modifier = modifier,
contentPadding = PaddingValues(
vertical = verticalContentPadding.value,
horizontal = horizontalContentPadding.value
vertical = spacePaddingBlock.value,
horizontal = spacePaddingBlock.value
),
interactionSource = remember { MutableInteractionSource() },
elevation = ButtonDefaults.buttonElevation(
defaultElevation = defaultElevation.value,
pressedElevation = pressedElevation.value,
focusedElevation = focusedElevation.value,
hoveredElevation = hoveredElevation.value,
disabledElevation = disabledElevation.value,
),
colors = ButtonDefaults.buttonColors(
containerColor = containerColor.value,
contentColor = contentColor.value,
disabledContainerColor = disabledContainerColor.value,
disabledContentColor = disabledContentColor.value,
containerColor = colorBgDefaultEnabled.value,
contentColor = colorContentDefaultEnabled.value,
disabledContainerColor = colorBgDefaultDisabled.value,
disabledContentColor = colorContentDefaultDisabled.value,
)
) {
Text(
modifier = modifier,
text = text,
style = labelStyle.value,
text = text
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.Focus.Inset -> widthFocusInset
OudsBorderKeyToken.Width.FocusInset -> widthFocusInset
}
}

Expand Down
Loading

0 comments on commit eccb9d1

Please sign in to comment.