Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add grid tokens in the demo app #149

Draft
wants to merge 26 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4384ce7
Add border tokens in the demo app
paulinea Oct 16, 2024
6a862e3
Review: Change dashedBorder modifier signature
paulinea Oct 17, 2024
5d0f34a
Review: Move defaultIllustrationSize variable in the companion object…
paulinea Oct 17, 2024
c81a14b
Add ic_spacing icon
paulinea Oct 17, 2024
858ae97
Start adding dimension tokens in demo app
paulinea Oct 18, 2024
8254ed5
Fix subcategories detail display
paulinea Oct 18, 2024
457a2b6
Reorder OudsSizeIconWithTextKeyToken
paulinea Oct 21, 2024
378812b
Display dimension size tokens
paulinea Oct 21, 2024
1d6cbcd
Display all spacing tokens in the demo app
paulinea Oct 21, 2024
3da3c0d
Apply filter before calling private composable
paulinea Oct 22, 2024
057b1c7
Reorder properties
paulinea Oct 22, 2024
a04f3d3
Update illustrations for spacing inline with icon
paulinea Oct 22, 2024
0b22f2b
Rename spacing into space
paulinea Oct 23, 2024
7f91d84
Rename strings
paulinea Oct 23, 2024
9b76204
Add WithArrow tokens illustrations
paulinea Oct 23, 2024
b696f73
Replace hardcoded spaces by tokens
paulinea Oct 24, 2024
79ca7ab
Factorize some code
paulinea Oct 24, 2024
3776da3
Improve size and space key tokens organization
paulinea Oct 25, 2024
d42faf4
Start adding dimension tokens in demo app
paulinea Oct 18, 2024
2629b8e
Add grid icon
paulinea Oct 22, 2024
116c516
Display grid tokens in demo app
paulinea Oct 22, 2024
cb5932d
Add grid illustrations
paulinea Oct 22, 2024
45db7e5
Replace Spacing by Space
paulinea Oct 23, 2024
f02c08f
Add header
paulinea Oct 24, 2024
d846e48
Move grid illustrations in TokenPropertyIllustration file
paulinea Oct 24, 2024
7fabe55
Fix broken build during rebase
paulinea Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,47 @@ Any use or displaying shall constitute an infringement under intellectual proper
app/src/main/res/drawable/ic_border.xml
app/src/main/res/drawable/ic_component_atom.xml
app/src/main/res/drawable/ic_design_token_figma.xml
app/src/main/res/drawable/ic_design_token_figma_no_padding.xml
app/src/main/res/drawable/ic_dimension.xml
app/src/main/res/drawable/ic_filter_effects.xml
app/src/main/res/drawable/ic_info.xml
app/src/main/res/drawable/ic_layers.xml
app/src/main/res/drawable/ic_menu_grid.xml
app/src/main/res/drawable/ic_solar_palette.xml
app/src/main/res/drawable/ic_typography.xml
app/src/main/res/drawable/ic_ui_dark_mode.xml
app/src/main/res/drawable/ic_ui_light_mode.xml
app/src/main/res/drawable/il_opacity_union.xml
app/src/main/res/drawable-hdpi/il_tokens_grid_column_margin.png
app/src/main/res/drawable-hdpi/il_tokens_grid_max_width.png
app/src/main/res/drawable-hdpi/il_tokens_grid_min_width.png
app/src/main/res/drawable-mdpi/il_tokens_grid_column_margin.png
app/src/main/res/drawable-mdpi/il_tokens_grid_max_width.png
app/src/main/res/drawable-mdpi/il_tokens_grid_min_width.png
app/src/main/res/drawable-xhdpi/il_tokens_grid_column_margin.png
app/src/main/res/drawable-xhdpi/il_tokens_grid_max_width.png
app/src/main/res/drawable-xhdpi/il_tokens_grid_min_width.png
app/src/main/res/drawable-xxhdpi/il_tokens_grid_column_margin.png
app/src/main/res/drawable-xxhdpi/il_tokens_grid_max_width.png
app/src/main/res/drawable-xxhdpi/il_tokens_grid_min_width.png
app/src/main/res/drawable-xxxhdpi/il_tokens_grid_column_margin.png
app/src/main/res/drawable-xxxhdpi/il_tokens_grid_max_width.png
app/src/main/res/drawable-xxxhdpi/il_tokens_grid_min_width.png
app/src/main/res/drawable-night-hdpi/il_tokens_grid_column_margin.png
app/src/main/res/drawable-night-hdpi/il_tokens_grid_max_width.png
app/src/main/res/drawable-night-hdpi/il_tokens_grid_min_width.png
app/src/main/res/drawable-night-mdpi/il_tokens_grid_column_margin.png
app/src/main/res/drawable-night-mdpi/il_tokens_grid_max_width.png
app/src/main/res/drawable-night-mdpi/il_tokens_grid_min_width.png
app/src/main/res/drawable-night-xhdpi/il_tokens_grid_column_margin.png
app/src/main/res/drawable-night-xhdpi/il_tokens_grid_max_width.png
app/src/main/res/drawable-night-xhdpi/il_tokens_grid_min_width.png
app/src/main/res/drawable-night-xxhdpi/il_tokens_grid_column_margin.png
app/src/main/res/drawable-night-xxhdpi/il_tokens_grid_max_width.png
app/src/main/res/drawable-night-xxhdpi/il_tokens_grid_min_width.png
app/src/main/res/drawable-night-xxxhdpi/il_tokens_grid_column_margin.png
app/src/main/res/drawable-night-xxxhdpi/il_tokens_grid_max_width.png
app/src/main/res/drawable-night-xxxhdpi/il_tokens_grid_min_width.png

docs/images/favicon-16x16.png
docs/images/orange-logo.svg
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/com/orange/ouds/app/ui/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ import com.orange.ouds.app.R
import com.orange.ouds.app.ui.navigation.appNavGraph
import com.orange.ouds.app.ui.utilities.isDarkModeEnabled
import com.orange.ouds.core.theme.OudsTheme
import com.orange.ouds.core.theme.value
import com.orange.ouds.core.utilities.OudsPreview
import com.orange.ouds.foundation.extensions.orElse
import com.orange.ouds.foundation.utilities.UiModePreviews
import com.orange.ouds.theme.OudsThemeContract
import com.orange.ouds.theme.orange.ORANGE_THEME_NAME
import com.orange.ouds.theme.orange.OrangeTheme
import com.orange.ouds.theme.orangecountry.OrangeCountryTheme
import com.orange.ouds.theme.tokens.OudsSpaceKeyToken
import com.orange.ouds.theme.whitelabel.WhiteLabelTheme

@Composable
Expand Down Expand Up @@ -155,12 +157,11 @@ private fun ChangeThemeDialog(themeManager: ThemeManager, dismissDialog: () -> U
.background(OudsTheme.colorScheme.surfaceVariant)
.selectableGroup()
) {
//TODO Replace hard coded values by tokens when available and use OUDS typography
Text(
text = stringResource(R.string.app_themeDialog_label),
modifier = Modifier
.padding(top = 16.dp, bottom = 8.dp)
.padding(horizontal = 16.dp),
.padding(top = OudsSpaceKeyToken.Fixed.Medium.value, bottom = OudsSpaceKeyToken.Fixed.Short.value)
.padding(horizontal = OudsSpaceKeyToken.Fixed.Medium.value),
style = MaterialTheme.typography.titleLarge
)
themeManager.availableThemes.forEach { theme ->
Expand All @@ -180,7 +181,7 @@ private fun ChangeThemeDialog(themeManager: ThemeManager, dismissDialog: () -> U
},
role = Role.RadioButton
)
.padding(horizontal = 16.dp),
.padding(horizontal = OudsSpaceKeyToken.Fixed.Medium.value),
verticalAlignment = Alignment.CenterVertically
) {
RadioButton(
Expand All @@ -190,7 +191,7 @@ private fun ChangeThemeDialog(themeManager: ThemeManager, dismissDialog: () -> U
Text(
text = theme.name,
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(start = 16.dp)
modifier = Modifier.padding(start = OudsSpaceKeyToken.Fixed.Medium.value)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import com.orange.ouds.core.theme.value
import com.orange.ouds.core.utilities.OudsPreview
import com.orange.ouds.foundation.utilities.UiModePreviews
import com.orange.ouds.theme.tokens.OudsGridKeyToken
import com.orange.ouds.theme.tokens.OudsSpacingFixedKeyToken
import com.orange.ouds.theme.tokens.OudsSpaceKeyToken

@Composable
fun ComponentsScreen() {
Expand All @@ -49,7 +49,7 @@ fun ComponentsScreen() {

Box(
modifier = Modifier
.padding(top = OudsSpacingFixedKeyToken.Medium.value)
.padding(top = OudsSpaceKeyToken.Fixed.Medium.value)
.width(OudsGridKeyToken.Margin.value)
.height(OudsGridKeyToken.ColumnGap.value)
.background(OudsTheme.colorScheme.primary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import com.orange.ouds.app.ui.tokens.addTokensNavGraph
* Root navigation graph of the application
*/
fun NavGraphBuilder.appNavGraph(navController: NavController) {
addTokensNavGraph()
addTokensNavGraph(navController)
addAboutNavGraph()
addBottomBarNavGraph(navController)
}
Expand All @@ -38,7 +38,7 @@ fun NavGraphBuilder.appNavGraph(navController: NavController) {
*/
private fun NavGraphBuilder.addBottomBarNavGraph(navController: NavController) {
composable(BottomBarItem.Tokens.route) { from ->
TokensScreen(onTokenClick = { id -> navController.navigateToElement(TokensNavigation.TokenCategoryDetailRoute, id, from) })
TokensScreen(onTokenCategoryClick = { id -> navController.navigateToElement(TokensNavigation.TokenCategoryDetailRoute, id, from) })
}
composable(BottomBarItem.Components.route) { _ ->
ComponentsScreen()
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/java/com/orange/ouds/app/ui/tokens/Token.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.tokens

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import com.orange.ouds.app.R

data class Token<T>(val name: String, val value: T) {
val literalValue: String
@Composable
get() = when (value) {
is Float -> stringResource(id = R.string.app_tokens_floatFormat_label, value)
is Dp -> stringResource(id = R.string.app_tokens_dpFormat_label, value.toString().replace(".0.dp", "").substringBeforeLast(".dp"))
is TextStyle -> stringResource(id = R.string.app_tokens_spFormat_label, value.fontSize.toString().replace(".0.sp", "").substringBeforeLast(".sp"))
else -> value.toString()
}
}
182 changes: 36 additions & 146 deletions app/src/main/java/com/orange/ouds/app/ui/tokens/TokenCategory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,8 @@ package com.orange.ouds.app.ui.tokens

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.orange.ouds.app.R
import com.orange.ouds.core.theme.value
import com.orange.ouds.theme.OudsBorderStyle
import com.orange.ouds.theme.dashedBorder
import com.orange.ouds.theme.dottedBorder
import com.orange.ouds.theme.tokens.OudsBorderRadiusKeyToken
import com.orange.ouds.theme.tokens.OudsBorderStyleKeyToken
import com.orange.ouds.theme.tokens.OudsBorderWidthKeyToken
import com.orange.ouds.theme.tokens.OudsElevationKeyToken
import com.orange.ouds.theme.tokens.OudsOpacityKeyToken
import com.orange.ouds.theme.tokens.OudsSpacingFixedKeyToken
import com.orange.ouds.theme.tokens.OudsTypographyKeyToken
import com.orange.ouds.theme.tokens.semantic.OudsColorKeyToken

val tokenCategories = TokenCategory::class.sealedSubclasses.mapNotNull { it.objectInstance }

Expand All @@ -53,7 +24,9 @@ sealed class TokenCategory(
@StringRes val nameRes: Int,
@DrawableRes val imageRes: Int,
@StringRes val descriptionRes: Int,
val properties: List<TokenProperty>
val properties: List<TokenProperty> = emptyList(),
val subcategories: List<TokenCategory> = emptyList(),
val subcategory: Boolean = false
) {

companion object {
Expand All @@ -69,13 +42,46 @@ sealed class TokenCategory(
listOf(TokenProperty.BorderWidth, TokenProperty.BorderRadius, TokenProperty.BorderStyle)
)

data object Dimension : TokenCategory(
R.string.app_tokens_dimension_label,
R.drawable.ic_dimension,
R.string.app_tokens_dimension_description_text,
subcategories = listOf(Space, Size)
) {
data object Space : TokenCategory(
R.string.app_tokens_dimension_space_label,
R.drawable.ic_dimension,
R.string.app_tokens_dimension_space_description_text,
listOf(
TokenProperty.SpaceScaled, TokenProperty.SpaceFixed, TokenProperty.SpacePaddingInline, TokenProperty.SpacePaddingStack,
TokenProperty.SpacePaddingInset, TokenProperty.SpaceColumnGap, TokenProperty.SpaceRowGap
),
subcategory = true
)

data object Size : TokenCategory(
R.string.app_tokens_dimension_size_label,
R.drawable.ic_dimension,
R.string.app_tokens_dimension_size_description_text,
listOf(TokenProperty.SizeIconDecorative, TokenProperty.SizeIconWithLabel),
subcategory = true
)
}

data object Elevation : TokenCategory(
R.string.app_tokens_elevation_label,
R.drawable.ic_layers,
R.string.app_tokens_elevation_description_text,
listOf(TokenProperty.Elevation)
)

data object Grid : TokenCategory(
R.string.app_tokens_grid_label,
R.drawable.ic_menu_grid,
R.string.app_tokens_grid_description_text,
listOf(TokenProperty.Grid)
)

data object Opacity : TokenCategory(
R.string.app_tokens_opacity_label,
R.drawable.ic_filter_effects,
Expand All @@ -89,120 +95,4 @@ sealed class TokenCategory(
R.string.app_tokens_typography_description_text,
listOf(TokenProperty.Typography)
)

}

sealed class TokenProperty(
@StringRes val nameRes: Int?,
val tokens: @Composable () -> List<Token<Any>>
) {
protected companion object {
val defaultIllustrationSize = 64.dp
}

data object BorderRadius : TokenProperty(
nameRes = R.string.app_tokens_border_radius_label,
tokens = { OudsBorderRadiusKeyToken.entries.map { Token(it.name, it.value) } }
) {
@Composable
fun Illustration(radius: Dp) {
Box(
modifier = Modifier
.size(defaultIllustrationSize)
.border(
width = 1.dp,
color = OudsColorKeyToken.OnSurface.value,
shape = RoundedCornerShape(radius)
) //TODO use ContentDefault token when available
.background(color = OudsColorKeyToken.Surface.value), //TODO use BgDefaultSecondary token when available
)
}
}

data object BorderStyle : TokenProperty(
nameRes = R.string.app_tokens_border_style_label,
tokens = { OudsBorderStyleKeyToken.entries.map { Token(it.name, it.value) } }
) {
@Composable
fun Illustration(style: OudsBorderStyle) {
val borderColor = OudsColorKeyToken.OnSurface.value //TODO use ContentDefault token when available
val borderWidth = 1.dp
val modifier = when (style) {
OudsBorderStyle.None -> Modifier
OudsBorderStyle.Solid -> Modifier.border(width = borderWidth, color = borderColor)
OudsBorderStyle.Dashed -> Modifier.dashedBorder(width = borderWidth, color = borderColor)
OudsBorderStyle.Dotted -> Modifier.dottedBorder(width = borderWidth, color = borderColor)
}
Box(
modifier = modifier
.size(defaultIllustrationSize)
.background(color = OudsColorKeyToken.Surface.value), //TODO use BgDefaultSecondary token when available
)
}
}

data object BorderWidth : TokenProperty(
nameRes = R.string.app_tokens_border_width_label,
tokens = { OudsBorderWidthKeyToken.entries.map { Token(it.name, it.value) } }
) {
@Composable
fun Illustration(width: Dp) {
val borderColor = OudsColorKeyToken.OnSurface.value //TODO use ContentDefault token when available
Box(
modifier = Modifier
.size(defaultIllustrationSize)
.border(width = width, color = borderColor)
.background(color = OudsColorKeyToken.Surface.value), //TODO use BgDefaultSecondary token when available
)
}
}

data object Elevation : TokenProperty(
nameRes = null,
tokens = { OudsElevationKeyToken.entries.map { Token(it.name, it.value) } }
) {
@Composable
fun Illustration(elevation: Dp) {
Surface(shadowElevation = elevation) {
Box(
modifier = Modifier
.size(defaultIllustrationSize)
.background(color = OudsColorKeyToken.Surface.value), //TODO use BgDefaultSecondary token when available
)
}
}
}

data object Opacity : TokenProperty(
nameRes = null,
tokens = { OudsOpacityKeyToken.entries.map { Token(it.name, it.value) } }
) {
@Composable
fun Illustration(opacity: Float) {
val squareColor = if (isSystemInDarkTheme()) Color.White else Color.Black
Box {
Image(painter = painterResource(id = R.drawable.il_opacity_union), contentDescription = null)
Box(
modifier = Modifier
.padding(top = OudsSpacingFixedKeyToken.Medium.value, start = OudsSpacingFixedKeyToken.Medium.value)
.size(48.dp)
.background(color = squareColor.copy(alpha = opacity))
.border(width = 1.dp, color = squareColor)
)
}
}
}

data object Typography : TokenProperty(nameRes = null, tokens = { OudsTypographyKeyToken.entries.map { Token(it.name, it.value) } })
}

data class Token<T>(val name: String, val value: T) {
val literalValue: String
@Composable
get() = when (value) {
is Dp -> stringResource(id = R.string.app_tokens_dpFormat_label, value.toString().replace(".0.dp", "").substringBeforeLast(".dp"))
is Float -> stringResource(id = R.string.app_tokens_floatFormat_label, value)
is TextStyle -> stringResource(id = R.string.app_tokens_spFormat_label, value.fontSize.toString().replace(".0.sp", "").substringBeforeLast(".sp"))
else -> value.toString()
}
}
Loading