Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ theme-orange/src/main/res/drawable/ic_orange_component_bullet_list_level1.xml
theme-orange/src/main/res/drawable/ic_orange_component_bullet_list_level2.xml
theme-orange/src/main/res/drawable/ic_orange_component_bullet_list_tick.xml
theme-orange/src/main/res/drawable/ic_orange_component_button_expurge.xml
theme-orange/src/main/res/drawable/ic_orange_component_button_next.xml
theme-orange/src/main/res/drawable/ic_orange_component_button_previous.xml
theme-orange/src/main/res/drawable/ic_orange_component_checkbox_selected.xml
theme-orange/src/main/res/drawable/ic_orange_component_checkbox_undetermined.xml
theme-orange/src/main/res/drawable/ic_orange_component_chip_tick.xml
Expand Down Expand Up @@ -140,6 +142,8 @@ theme-sosh/src/main/res/drawable/ic_sosh_component_bullet_list_level1.xml
theme-sosh/src/main/res/drawable/ic_sosh_component_bullet_list_level2.xml
theme-sosh/src/main/res/drawable/ic_sosh_component_bullet_list_tick.xml
theme-sosh/src/main/res/drawable/ic_sosh_component_button_expurge.xml
theme-sosh/src/main/res/drawable/ic_sosh_component_button_next.xml
theme-sosh/src/main/res/drawable/ic_sosh_component_button_previous.xml
theme-sosh/src/main/res/drawable/ic_sosh_component_checkbox_selected.xml
theme-sosh/src/main/res/drawable/ic_sosh_component_checkbox_undetermined.xml
theme-sosh/src/main/res/drawable/ic_sosh_component_chip_tick.xml
Expand Down Expand Up @@ -171,6 +175,8 @@ theme-wireframe/src/main/res/drawable/ic_wireframe_component_bullet_list_level1.
theme-wireframe/src/main/res/drawable/ic_wireframe_component_bullet_list_level2.xml
theme-wireframe/src/main/res/drawable/ic_wireframe_component_bullet_list_tick.xml
theme-wireframe/src/main/res/drawable/ic_wireframe_component_button_expurge.xml
theme-wireframe/src/main/res/drawable/ic_wireframe_component_button_next.xml
theme-wireframe/src/main/res/drawable/ic_wireframe_component_button_previous.xml
theme-wireframe/src/main/res/drawable/ic_wireframe_component_checkbox_selected.xml
theme-wireframe/src/main/res/drawable/ic_wireframe_component_checkbox_undetermined.xml
theme-wireframe/src/main/res/drawable/ic_wireframe_component_chip_tick.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.orange.ouds.app.ui.components.bottomsheet.StandardBottomSheetDemoScre
import com.orange.ouds.app.ui.components.bottomsheet.ModalBottomSheetDemoScreen
import com.orange.ouds.app.ui.components.bulletlist.BulletListDemoScreen
import com.orange.ouds.app.ui.components.button.ButtonDemoScreen
import com.orange.ouds.app.ui.components.button.NavigationButtonDemoScreen
import com.orange.ouds.app.ui.components.checkbox.CheckboxDemoScreen
import com.orange.ouds.app.ui.components.checkbox.CheckboxItemDemoScreen
import com.orange.ouds.app.ui.components.chip.FilterChipDemoScreen
Expand Down Expand Up @@ -94,7 +95,7 @@ sealed class Component(
R.string.app_components_button_tech,
R.string.app_components_button_description_text,
{ ButtonIllustration() },
demoScreen = { ButtonDemoScreen() }
listOf(Variant.Button, Variant.NavigationButton)
)

data object Checkbox : Component(
Expand Down Expand Up @@ -222,6 +223,10 @@ sealed class Variant(
data object StandardBottomSheet : Variant(R.string.app_components_bottomSheet_standardBottomSheet_tech, { StandardBottomSheetDemoScreen() })
data object ModalBottomSheet : Variant(R.string.app_components_bottomSheet_modalBottomSheet_tech, { ModalBottomSheetDemoScreen() })

// Button
data object Button : Variant(R.string.app_components_button_button_tech, { ButtonDemoScreen() })
data object NavigationButton : Variant(R.string.app_components_button_navigationButton_tech, { NavigationButtonDemoScreen() })

// Checkbox
data object Checkbox : Variant(R.string.app_components_checkbox_checkbox_tech, { CheckboxDemoScreen() })
data object CheckboxItem : Variant(R.string.app_components_checkbox_checkboxItem_tech, { CheckboxItemDemoScreen() })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.components.button

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.listSaver
import androidx.compose.runtime.setValue

open class BaseButtonDemoState(
label: String,
enabled: Boolean,
onColoredBox: Boolean,
hasLoader: Boolean
) {
companion object {
val Saver = listSaver(
save = { state ->
with(state) {
listOf(
label,
enabled,
onColoredBox,
hasLoader
)
}
},
restore = { list: List<Any?> ->
BaseButtonDemoState(
list[0] as String,
list[1] as Boolean,
list[2] as Boolean,
list[3] as Boolean
)
}
)
}

var label: String by mutableStateOf(label)

var enabled: Boolean by mutableStateOf(enabled)

var onColoredBox: Boolean by mutableStateOf(onColoredBox)

var hasLoader: Boolean by mutableStateOf(hasLoader)

val enabledSwitchEnabled: Boolean
get() = !hasLoader

val loaderSwitchEnabled: Boolean
get() = enabled
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,44 +43,40 @@ class ButtonDemoState(
hasLoader: Boolean,
appearance: OudsButtonAppearance,
layout: Layout
) {
) : BaseButtonDemoState(label, enabled, onColoredBox, hasLoader) {

companion object {

private val ForbiddenAppearancesOnColoredBox = listOf(OudsButtonAppearance.Brand, OudsButtonAppearance.Negative)

@Suppress("UNCHECKED_CAST")
val Saver = listSaver(
save = { state ->
with(state) {
listOf(
appearance,
layout,
with(BaseButtonDemoState.Saver) { save(state) }
)
}
},
restore = { list: List<Any?> ->
val baseButtonDemoState = list[1]?.let { BaseButtonDemoState.Saver.restore(it) }
baseButtonDemoState?.run {
ButtonDemoState(
label,
enabled,
onColoredBox,
hasLoader,
appearance,
layout
list[0] as OudsButtonAppearance,
list[1] as Layout
)
}
},
restore = { list: List<Any?> ->
ButtonDemoState(
list[0] as String,
list[1] as Boolean,
list[2] as Boolean,
list[3] as Boolean,
list[4] as OudsButtonAppearance,
list[5] as Layout,
)
}
)
}

var label: String by mutableStateOf(label)

var enabled: Boolean by mutableStateOf(enabled)

var onColoredBox: Boolean by mutableStateOf(onColoredBox)

var hasLoader: Boolean by mutableStateOf(hasLoader)
var layout: Layout by mutableStateOf(layout)

private var _appearance: OudsButtonAppearance by mutableStateOf(appearance)
var appearance: OudsButtonAppearance
Expand All @@ -92,17 +88,9 @@ class ButtonDemoState(
}
}

var layout: Layout by mutableStateOf(layout)

val enabledSwitchEnabled: Boolean
get() = !hasLoader

val onColoredBoxSwitchEnabled: Boolean
get() = appearance !in ForbiddenAppearancesOnColoredBox

val loaderSwitchEnabled: Boolean
get() = enabled

val labelTextInputEnabled: Boolean
get() = layout != Layout.IconOnly

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* 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.components.button

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.PreviewLightDark
import com.orange.ouds.app.R
import com.orange.ouds.app.ui.components.Component
import com.orange.ouds.app.ui.components.coloredBoxCall
import com.orange.ouds.app.ui.components.enabledArgument
import com.orange.ouds.app.ui.components.labelArgument
import com.orange.ouds.app.ui.components.onClickArgument
import com.orange.ouds.app.ui.utilities.Code
import com.orange.ouds.app.ui.utilities.composable.AppPreview
import com.orange.ouds.app.ui.utilities.composable.CustomizationFilterChips
import com.orange.ouds.app.ui.utilities.composable.CustomizationSwitchItem
import com.orange.ouds.app.ui.utilities.composable.CustomizationTextInput
import com.orange.ouds.app.ui.utilities.composable.DemoScreen
import com.orange.ouds.core.component.OudsButtonLoader
import com.orange.ouds.core.component.OudsNavigationButton
import com.orange.ouds.core.component.OudsNavigationButtonAppearance
import com.orange.ouds.core.component.OudsNavigationButtonDefaults
import com.orange.ouds.core.component.OudsNavigationButtonLayout
import com.orange.ouds.theme.OudsVersion

@Composable
fun NavigationButtonDemoScreen() {
val state = rememberNavigationButtonDemoState()
DemoScreen(
description = stringResource(id = Component.Button.descriptionRes),
bottomSheetContent = { NavigationButtonDemoBottomSheetContent(state = state) },
codeSnippet = { navigationButtonDemoCodeSnippet(state = state) },
demoContent = { NavigationButtonDemoContent(state = state) },
demoContentOnColoredBox = state.onColoredBox,
version = OudsVersion.Component.NavigationButton
)
}

@Composable
private fun NavigationButtonDemoBottomSheetContent(state: NavigationButtonDemoState) {
with(state) {
CustomizationSwitchItem(
label = stringResource(R.string.app_common_enabled_tech),
checked = enabled,
onCheckedChange = { enabled = it },
enabled = enabledSwitchEnabled
)
CustomizationSwitchItem(
label = stringResource(R.string.app_components_common_onColoredBackground_tech),
checked = onColoredBox,
onCheckedChange = { onColoredBox = it },
enabled = onColoredBoxSwitchEnabled
)
CustomizationFilterChips(
applyTopPadding = true,
label = stringResource(R.string.app_components_common_layout_tech),
chipLabels = OudsNavigationButtonLayout.entries.map { it.name },
selectedChipIndex = OudsNavigationButtonLayout.entries.indexOf(layout),
onSelectionChange = { index -> layout = OudsNavigationButtonLayout.entries[index] }
)
CustomizationFilterChips(
applyTopPadding = true,
label = stringResource(R.string.app_components_common_appearance_tech),
chipLabels = OudsNavigationButtonAppearance.entries.map { it.name },
selectedChipIndex = OudsNavigationButtonAppearance.entries.indexOf(appearance),
onSelectionChange = { index -> appearance = OudsNavigationButtonAppearance.entries[index] }
)
CustomizationSwitchItem(
label = stringResource(R.string.app_components_common_loader_tech),
checked = hasLoader,
onCheckedChange = { hasLoader = it },
enabled = loaderSwitchEnabled
)
CustomizationSwitchItem(
label = stringResource(R.string.app_components_common_iconOnlyLayout_tech),
checked = iconOnly,
onCheckedChange = { iconOnly = it }
)
CustomizationTextInput(
applyTopPadding = true,
label = stringResource(R.string.app_components_common_label_tech),
value = label,
onValueChange = { value -> label = value },
enabled = labelTextInputEnabled
)
}
}

@Composable
private fun NavigationButtonDemoContent(state: NavigationButtonDemoState) {
with(state) {
val loader = if (hasLoader) OudsButtonLoader(null) else null
if (iconOnly) {
OudsNavigationButton(
layout = layout,
onClick = {},
enabled = enabled,
loader = loader,
appearance = appearance
)
} else {
OudsNavigationButton(
label = label,
layout = layout,
onClick = {},
enabled = enabled,
loader = loader,
appearance = appearance
)
}
}
}

private fun Code.Builder.navigationButtonDemoCodeSnippet(state: NavigationButtonDemoState) {
with(state) {
coloredBoxCall(onColoredBox) {
functionCall("OudsNavigationButton") {
if (!iconOnly) {
labelArgument(label)
}
typedArgument("layout", layout)
onClickArgument()
if (!enabled) enabledArgument(enabled)
if (hasLoader) {
constructorCallArgument<OudsButtonLoader>("loader") {
typedArgument("progress", null)
}
}
if (appearance != OudsNavigationButtonDefaults.Appearance) typedArgument("appearance", appearance)
}
}
}
}

@PreviewLightDark
@Composable
private fun PreviewNavigationButtonDemoScreen() = AppPreview {
NavigationButtonDemoScreen()
}
Loading
Loading