Skip to content

Commit

Permalink
Add code snippet for OudsButton and OudsLink
Browse files Browse the repository at this point in the history
  • Loading branch information
florentmaitre committed Feb 12, 2025
1 parent 4af6366 commit ed5e392
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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

import com.orange.ouds.app.ui.utilities.Code
import com.orange.ouds.core.component.OudsColoredBox

fun Code.Builder.coloredBoxCall(onColoredBox: Boolean, content: Code.Builder.() -> Unit) {
if (onColoredBox) {
functionCall("OudsColoredBox") {
trailingLambda = true
typedArgument("color", OudsColoredBox.Color.BrandPrimary)
lambdaArgument("content", content)
}
} else {
content()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.rememberBottomSheetScaffoldState
import androidx.compose.runtime.Composable
Expand All @@ -28,6 +30,8 @@ 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.components.coloredBoxCall
import com.orange.ouds.app.ui.utilities.composable.CodeSnippet
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
Expand Down Expand Up @@ -87,7 +91,11 @@ fun ButtonDemoScreen() = DemoScreen(rememberButtonDemoState()) {
)
}
) {
Column(modifier = Modifier.fillMaxWidth()) {
Column(
modifier = Modifier
.fillMaxWidth()
.verticalScroll(rememberScrollState())
) {
DetailScreenDescription(
modifier = Modifier.padding(all = OudsTheme.spaces.fixed.medium),
descriptionRes = Component.Button.descriptionRes
Expand All @@ -98,6 +106,12 @@ fun ButtonDemoScreen() = DemoScreen(rememberButtonDemoState()) {
ButtonDemo(state = this@DemoScreen)
}
}
ButtonDemoCodeSnippet(
state = this@DemoScreen,
modifier = Modifier
.padding(all = OudsTheme.spaces.fixed.medium)
.padding(top = OudsTheme.spaces.fixed.medium)
)
}
}
}
Expand All @@ -111,7 +125,10 @@ private fun ButtonDemo(state: ButtonDemoState) {
.fillMaxWidth()
) {
val text = stringResource(id = R.string.app_components_button_label)
val icon = OudsButton.Icon(painterResource(id = R.drawable.ic_heart), stringResource(id = R.string.app_components_button_icon_a11y))
val icon = OudsButton.Icon(
painter = painterResource(id = R.drawable.ic_heart),
contentDescription = stringResource(id = R.string.app_components_button_icon_a11y)
)
with(state) {
when (layout) {
ButtonDemoState.Layout.TextOnly -> {
Expand Down Expand Up @@ -168,6 +185,34 @@ private fun ButtonDemoBox(colored: Boolean, modifier: Modifier = Modifier, conte
}
}

@Composable
private fun ButtonDemoCodeSnippet(state: ButtonDemoState, modifier: Modifier = Modifier) {
val text = stringResource(id = R.string.app_components_button_label)
CodeSnippet(modifier = modifier) {
coloredBoxCall(state.onColoredBox) {
functionCall("OudsButton") {
if (state.layout in listOf(ButtonDemoState.Layout.IconOnly, ButtonDemoState.Layout.IconAndText)) {
constructorCallArgument<OudsButton.Icon>("icon") {
functionCallArgument("painter", "painterResource") {
typedArgument("id", R.drawable.ic_heart)
}
functionCallArgument("contentDescription", "stringResource") {
typedArgument("id", R.string.app_components_button_icon_a11y)
}
}
}
if (state.layout in listOf(ButtonDemoState.Layout.TextOnly, ButtonDemoState.Layout.IconAndText)) {
typedArgument("text", text)
}
lambdaArgument("onClick")
typedArgument("enabled", state.enabled)
typedArgument("style", state.style)
typedArgument("hierarchy", state.hierarchy)
}
}
}
}

@UiModePreviews.Default
@Composable
private fun PreviewButtonDemoScreen() = OudsPreview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.rememberBottomSheetScaffoldState
import androidx.compose.runtime.Composable
Expand All @@ -27,6 +29,8 @@ 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.components.coloredBoxCall
import com.orange.ouds.app.ui.utilities.composable.CodeSnippet
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
Expand Down Expand Up @@ -72,7 +76,11 @@ fun LinkDemoScreen() = DemoScreen(rememberLinkDemoState()) {
)
}
) {
Column(modifier = Modifier.fillMaxWidth()) {
Column(
modifier = Modifier
.fillMaxWidth()
.verticalScroll(rememberScrollState())
) {
DetailScreenDescription(
modifier = Modifier.padding(all = OudsTheme.spaces.fixed.medium),
descriptionRes = Component.Link.descriptionRes
Expand All @@ -83,6 +91,12 @@ fun LinkDemoScreen() = DemoScreen(rememberLinkDemoState()) {
LinkDemo(state = this@DemoScreen)
}
}
LinkDemoCodeSnippet(
state = this@DemoScreen,
modifier = Modifier
.padding(all = OudsTheme.spaces.fixed.medium)
.padding(top = OudsTheme.spaces.fixed.medium)
)
}
}
}
Expand Down Expand Up @@ -159,6 +173,33 @@ private fun LinkDemoBox(colored: Boolean, modifier: Modifier = Modifier, content
}
}

@Composable
private fun LinkDemoCodeSnippet(state: LinkDemoState, modifier: Modifier = Modifier) {
val text = stringResource(id = R.string.app_components_link_label)
CodeSnippet(modifier = modifier) {
coloredBoxCall(state.onColoredBox) {
functionCall("OudsLink") {
typedArgument("text", text)
when (state.layout) {
LinkDemoState.Layout.TextOnly -> {}
LinkDemoState.Layout.IconAndText -> {
constructorCallArgument<OudsLink.Icon>("icon") {
functionCallArgument("painter", "painterResource") {
typedArgument("id", R.drawable.ic_heart)
}
}
}
LinkDemoState.Layout.ArrowBack -> typedArgument("arrow", OudsLink.Arrow.Back)
LinkDemoState.Layout.ArrowNext -> typedArgument("arrow", OudsLink.Arrow.Next)
}
lambdaArgument("onClick")
typedArgument("enabled", state.enabled)
typedArgument("size", state.size)
}
}
}
}

@UiModePreviews.Default
@Composable
private fun PreviewLinkDemoScreen() = OudsPreview {
Expand Down

0 comments on commit ed5e392

Please sign in to comment.