-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
264 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
app/src/main/java/com/orange/ouds/app/ui/components/link/LinkDemoScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* 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.link | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.rememberBottomSheetScaffoldState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import com.orange.ouds.app.R | ||
import com.orange.ouds.app.ui.components.Component | ||
import com.orange.ouds.app.ui.utilities.composable.CustomizationBottomSheetScaffold | ||
import com.orange.ouds.app.ui.utilities.composable.CustomizationChoiceChipsColumn | ||
import com.orange.ouds.app.ui.utilities.composable.CustomizationSwitchListItem | ||
import com.orange.ouds.app.ui.utilities.composable.DemoScreen | ||
import com.orange.ouds.app.ui.utilities.composable.DetailScreenDescription | ||
import com.orange.ouds.core.component.link.OudsLink | ||
import com.orange.ouds.core.theme.OudsTheme | ||
import com.orange.ouds.core.theme.OudsThemeTweak | ||
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.OudsSpaceKeyToken | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun LinkDemoScreen() = DemoScreen(rememberLinkDemoState()) { | ||
CustomizationBottomSheetScaffold( | ||
bottomSheetScaffoldState = rememberBottomSheetScaffoldState(), | ||
bottomSheetContent = { | ||
CustomizationSwitchListItem( | ||
label = stringResource(R.string.app_common_enabled_label), | ||
checked = enabled, | ||
onCheckedChange = { enabled = it }, | ||
enabled = style == OudsLink.Style.Default | ||
) | ||
val styles = remember { listOf(OudsLink.Style.Default, OudsLink.Style.Skeleton) } | ||
CustomizationChoiceChipsColumn( | ||
modifier = Modifier.padding(top = OudsSpaceKeyToken.Fixed.Medium.value), | ||
label = stringResource(R.string.app_components_common_style_label), | ||
chipsLabels = styles.map { it::class.simpleName.orEmpty() }, | ||
selectedChipIndex = styles.indexOf(style), | ||
onSelectionChange = { id -> style = styles[id] } | ||
) | ||
val sizes = remember { listOf(OudsLink.Size.Small, OudsLink.Size.Medium) } | ||
CustomizationChoiceChipsColumn( | ||
modifier = Modifier.padding(top = OudsSpaceKeyToken.Fixed.Medium.value), | ||
label = stringResource(R.string.app_components_link_size_label), | ||
chipsLabels = sizes.map { it.name }, | ||
selectedChipIndex = sizes.indexOf(size), | ||
onSelectionChange = { id -> size = sizes[id] } | ||
) | ||
CustomizationChoiceChipsColumn( | ||
modifier = Modifier.padding(top = OudsSpaceKeyToken.Fixed.Medium.value), | ||
label = stringResource(R.string.app_components_common_layout_label), | ||
chipsLabels = LinkDemoState.Layout.entries.map { stringResource(it.labelRes) }, | ||
selectedChipIndex = LinkDemoState.Layout.entries.indexOf(layout), | ||
onSelectionChange = { id -> layout = LinkDemoState.Layout.entries[id] } | ||
) | ||
} | ||
) { | ||
Column(modifier = Modifier.fillMaxWidth()) { | ||
DetailScreenDescription( | ||
modifier = Modifier.padding(all = OudsSpaceKeyToken.Fixed.Medium.value), | ||
descriptionRes = Component.Link.descriptionRes | ||
) | ||
LinkDemo(state = this@DemoScreen) | ||
OudsThemeTweak(OudsTheme.Tweak.Invert) { | ||
LinkDemo(state = this@DemoScreen) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun LinkDemo(state: LinkDemoState) { | ||
Box( | ||
modifier = Modifier | ||
.background(OudsTheme.colorScheme.backgroundColors.primary) | ||
.padding(all = OudsSpaceKeyToken.Fixed.Medium.value) | ||
.fillMaxWidth(), | ||
contentAlignment = Alignment.Center | ||
) { | ||
val text = stringResource(id = R.string.app_components_link_label) | ||
with(state) { | ||
when (layout) { | ||
LinkDemoState.Layout.TextOnly -> { | ||
OudsLink( | ||
text = text, | ||
icon = null, | ||
onClick = {}, | ||
enabled = enabled, | ||
style = style, | ||
size = size | ||
) | ||
} | ||
LinkDemoState.Layout.IconAndText -> { | ||
OudsLink( | ||
text = text, | ||
icon = OudsLink.Icon(painterResource(id = R.drawable.ic_heart)), | ||
onClick = {}, | ||
enabled = enabled, | ||
style = style, | ||
size = size | ||
) | ||
} | ||
LinkDemoState.Layout.ArrowBack -> { | ||
OudsLink( | ||
text = text, | ||
arrow = OudsLink.Arrow.Back, | ||
onClick = {}, | ||
enabled = enabled, | ||
style = style, | ||
size = size | ||
) | ||
} | ||
LinkDemoState.Layout.ArrowNext -> { | ||
OudsLink( | ||
text = text, | ||
arrow = OudsLink.Arrow.Next, | ||
onClick = {}, | ||
enabled = enabled, | ||
style = style, | ||
size = size | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@UiModePreviews.Default | ||
@Composable | ||
private fun PreviewLinkDemoScreen() = OudsPreview { | ||
LinkDemoScreen() | ||
} |
85 changes: 85 additions & 0 deletions
85
app/src/main/java/com/orange/ouds/app/ui/components/link/LinkDemoState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* 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.link | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.mapSaver | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import com.orange.ouds.app.R | ||
import com.orange.ouds.core.component.link.OudsLink | ||
import com.orange.ouds.core.component.link.OudsLinkDefaults | ||
|
||
@Composable | ||
fun rememberLinkDemoState( | ||
enabled: Boolean = true, | ||
style: OudsLink.Style = OudsLinkDefaults.Style, | ||
size: OudsLink.Size = OudsLinkDefaults.Size, | ||
layout: LinkDemoState.Layout = LinkDemoState.Layout.TextOnly | ||
) = rememberSaveable(enabled, style, size, layout, saver = LinkDemoState.Saver) { | ||
LinkDemoState(enabled, style, size, layout) | ||
} | ||
|
||
class LinkDemoState( | ||
enabled: Boolean, | ||
style: OudsLink.Style, | ||
size: OudsLink.Size, | ||
layout: Layout | ||
) { | ||
|
||
companion object { | ||
|
||
val Saver = run { | ||
val enabledKey = "enabled" | ||
val styleKey = "style" | ||
val sizeKey = "size" | ||
val layoutKey = "layout" | ||
mapSaver( | ||
save = { state -> | ||
mapOf( | ||
enabledKey to state.enabled, | ||
styleKey to state.style, | ||
sizeKey to state.size, | ||
layoutKey to state.layout | ||
) | ||
}, | ||
restore = { map -> | ||
LinkDemoState( | ||
map[enabledKey] as Boolean, | ||
map[styleKey] as OudsLink.Style, | ||
map[sizeKey] as OudsLink.Size, | ||
map[layoutKey] as Layout | ||
) | ||
} | ||
) | ||
} | ||
} | ||
|
||
var enabled: Boolean by mutableStateOf(enabled) | ||
|
||
var style: OudsLink.Style by mutableStateOf(style) | ||
|
||
var size: OudsLink.Size by mutableStateOf(size) | ||
|
||
var layout: Layout by mutableStateOf(layout) | ||
|
||
enum class Layout(@StringRes val labelRes: Int) { | ||
TextOnly(R.string.app_components_common_textOnlyLayout_label), | ||
IconAndText(R.string.app_components_common_iconAndTextLayout_label), | ||
ArrowBack(R.string.app_components_link_arrowBack_label), | ||
ArrowNext(R.string.app_components_link_arrowNext_label) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters