Skip to content

Commit

Permalink
[#415] Display only one style of text fields in the demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
paulinea authored and florentmaitre committed Jan 31, 2023
1 parent f2931a1 commit 7f0acbc
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 157 deletions.
17 changes: 4 additions & 13 deletions demo/src/main/java/com/orange/ods/demo/ui/components/Component.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ sealed class Component(
R.drawable.il_text_fields,
R.drawable.il_text_fields_small,
R.string.component_text_fields_description,
listOf(Variant.TextFieldFilledText, Variant.TextFieldFilledPassword, Variant.TextFieldOutlinedText, Variant.TextFieldOutlinedPassword)
listOf(Variant.TextField, Variant.TextFieldPassword)
)

object Tabs : Component(
Expand All @@ -181,15 +181,9 @@ val components = Component::class.sealedSubclasses.mapNotNull { it.objectInstanc

sealed class Variant(
@StringRes val titleRes: Int,
val composableName: String,
val section: Section? = null
val composableName: String
) {

enum class Section(@StringRes val titleRes: Int) {
TextFieldOutlined(R.string.component_text_field_outlined),
TextFieldFilled(R.string.component_text_field_filled)
}

val id: Long = Variant::class.sealedSubclasses.indexOf(this::class).toLong()

object AppBarsTopRegular : Variant(R.string.component_app_bars_top_regular, OdsComponent.OdsTopAppBar.name)
Expand All @@ -212,11 +206,8 @@ sealed class Variant(
object ProgressBar : Variant(R.string.component_progress_bar, OdsComponent.OdsLinearProgressIndicator.name)
object ProgressActivityIndicator : Variant(R.string.component_progress_activity_indicator, OdsComponent.OdsCircularProgressIndicator.name)

object TextFieldFilledText : Variant(R.string.component_text_field_text, OdsComponent.OdsTextField.name, Section.TextFieldFilled)
object TextFieldFilledPassword : Variant(R.string.component_text_field_password, OdsComponent.OdsPasswordTextField.name, Section.TextFieldFilled)
object TextFieldOutlinedText : Variant(R.string.component_text_field_text, OdsComponent.OdsOutlinedTextField.name, Section.TextFieldOutlined)
object TextFieldOutlinedPassword :
Variant(R.string.component_text_field_password, OdsComponent.OdsPasswordOutlinedTextField.name, Section.TextFieldOutlined)
object TextField : Variant(R.string.component_text_field_text, OdsComponent.OdsTextField.name)
object TextFieldPassword : Variant(R.string.component_text_field_password, OdsComponent.OdsPasswordTextField.name)

object TabsFixed : Variant(R.string.component_tabs_fixed, OdsComponent.OdsTabRow.name)
object TabsScrollable : Variant(R.string.component_tabs_scrollable, OdsComponent.OdsScrollableTabRow.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,21 @@
package com.orange.ods.demo.ui.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import com.orange.ods.compose.component.divider.OdsDivider
import com.orange.ods.compose.component.list.OdsListItem
import com.orange.ods.compose.component.list.OdsListItemIcon
import com.orange.ods.compose.component.list.OdsListItemIconType
import com.orange.ods.compose.component.list.iconType
import com.orange.ods.compose.text.OdsTextSubtitle2
import com.orange.ods.demo.R
import com.orange.ods.demo.ui.LocalMainTopAppBarManager
import com.orange.ods.demo.ui.utilities.DrawableManager
Expand Down Expand Up @@ -67,29 +62,13 @@ fun ComponentDetailScreen(
composableName = component.composableName
) { onDemoClick() }
} else {
component.variants.groupBy { it.section }.onEachIndexed { index, (section, variants) ->
section?.let {
if (index > 0) {
OdsDivider(modifier = Modifier.padding(top = dimensionResource(id = R.dimen.spacing_s)))
}
Box(modifier = Modifier.height(dimensionResource(id = R.dimen.list_single_line_item_height)), contentAlignment = Alignment.Center) {
OdsTextSubtitle2(
modifier = Modifier
.padding(horizontal = dimensionResource(id = R.dimen.screen_horizontal_margin)),
text = stringResource(id = section.titleRes)
)
}

}
variants.forEach { variant ->
ComponentDetailLinkItem(label = stringResource(id = variant.titleRes), composableName = variant.composableName) {
onVariantClick(
variant.id
)
}
component.variants.forEach { variant ->
ComponentDetailLinkItem(label = stringResource(id = variant.titleRes), composableName = variant.composableName) {
onVariantClick(variant.id)
}
}
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.orange.ods.demo.ui.components.chips.ChipCustomizationState.LeadingEle
import com.orange.ods.demo.ui.components.utilities.ComponentCustomizationBottomSheetScaffold
import com.orange.ods.demo.ui.components.utilities.clickOnElement
import com.orange.ods.demo.ui.utilities.composable.Subtitle
import com.orange.ods.theme.OdsComponentCustomizations.Companion.ChipStyle
import com.orange.ods.theme.OdsComponentsConfiguration.Companion.ComponentStyle

@OptIn(ExperimentalMaterialApi::class)
@Composable
Expand Down Expand Up @@ -106,7 +106,7 @@ fun ChipTypeDemo(chipType: ChipType, content: @Composable () -> Unit) {
@Composable
private fun Chip(chipCustomizationState: ChipCustomizationState) {
val context = LocalContext.current
val outlinedChips = LocalMainThemeManager.current.currentThemeConfiguration.components.chipStyle == ChipStyle.Outlined
val outlinedChips = LocalMainThemeManager.current.currentThemeConfiguration.components.chipStyle == ComponentStyle.Outlined
val cancelCrossLabel = stringResource(id = R.string.component_element_cancel_cross)
val recipes = LocalRecipes.current.take(4)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import com.orange.ods.demo.domain.recipes.LocalRecipes
import com.orange.ods.demo.ui.LocalMainThemeManager
import com.orange.ods.demo.ui.components.utilities.ComponentCustomizationBottomSheetScaffold
import com.orange.ods.demo.ui.utilities.composable.Subtitle
import com.orange.ods.theme.OdsComponentCustomizations.Companion.ChipStyle
import com.orange.ods.theme.OdsComponentsConfiguration.Companion.ComponentStyle

@OptIn(ExperimentalMaterialApi::class)
@Composable
Expand Down Expand Up @@ -78,7 +78,7 @@ fun ChipFilter() {

@Composable
private fun FilterChip(ingredient: Ingredient, customizationState: ChipCustomizationState) {
val outlinedChips = LocalMainThemeManager.current.currentThemeConfiguration.components.chipStyle == ChipStyle.Outlined
val outlinedChips = LocalMainThemeManager.current.currentThemeConfiguration.components.chipStyle == ComponentStyle.Outlined
val selected = rememberSaveable { mutableStateOf(false) }
OdsFilterChip(
text = ingredient.food.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ fun ComponentTextField(variant: Variant) {
bottomSheetScaffoldState = rememberBottomSheetScaffoldState(),
bottomSheetContent = {
when (variant) {
Variant.TextFieldFilledText, Variant.TextFieldOutlinedText -> TextFieldTextCustomization(textFieldCustomizationState)
Variant.TextFieldFilledPassword, Variant.TextFieldOutlinedPassword -> TextFieldPasswordCustomization(textFieldCustomizationState)
Variant.TextField -> TextFieldTextCustomization(textFieldCustomizationState)
Variant.TextFieldPassword -> TextFieldPasswordCustomization(textFieldCustomizationState)
else -> {}
}
}) {
Expand All @@ -65,10 +65,8 @@ fun ComponentTextField(variant: Variant) {
)
) {
when (variant) {
Variant.TextFieldFilledText -> TextFieldFilled(customizationState = textFieldCustomizationState)
Variant.TextFieldFilledPassword -> TextFieldFilledPassword(customizationState = textFieldCustomizationState)
Variant.TextFieldOutlinedText -> TextFieldOutlined(customizationState = textFieldCustomizationState)
Variant.TextFieldOutlinedPassword -> TextFieldOutlinedPassword(customizationState = textFieldCustomizationState)
Variant.TextField -> TextField(customizationState = textFieldCustomizationState)
Variant.TextFieldPassword -> TextFieldPassword(customizationState = textFieldCustomizationState)
else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.orange.ods.demo.ui.components.textfields.TextFieldCustomizationState.
import com.orange.ods.demo.ui.components.utilities.clickOnElement

@Composable
fun TextFieldFilled(customizationState: TextFieldCustomizationState) {
fun TextField(customizationState: TextFieldCustomizationState) {
val context = LocalContext.current
val trailingIconName = stringResource(id = R.string.component_element_trailing)

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.orange.ods.compose.component.textfield.password.OdsPasswordTextField
import com.orange.ods.demo.R

@Composable
fun TextFieldFilledPassword(customizationState: TextFieldCustomizationState) {
fun TextFieldPassword(customizationState: TextFieldCustomizationState) {

Column {
OdsPasswordTextField(
Expand Down
2 changes: 0 additions & 2 deletions demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@
<string name="component_text_field">Text field</string>
<string name="component_text_field_keyboard">Keyboard</string>
<string name="component_text_fields_description">Text fields enable the user to type text into the app. They also provide ways to select text and the opportunity to save time by suggesting options for auto-completion.</string>
<string name="component_text_field_filled">Filled</string>
<string name="component_text_field_outlined">Outlined</string>
<string name="component_text_field_text">Text field</string>
<string name="component_text_field_password">Password field</string>
<string name="component_text_field_input_type">Input type</string>
Expand Down

0 comments on commit 7f0acbc

Please sign in to comment.