Skip to content

Commit

Permalink
Review: Add helpers for function arguments in code snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
florentmaitre committed Feb 14, 2025
1 parent b504bfe commit dfcb99b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

package com.orange.ouds.app.ui.components

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import com.orange.ouds.app.ui.utilities.Code
import com.orange.ouds.app.ui.utilities.FunctionCall
import com.orange.ouds.core.component.OudsColoredBox

fun Code.Builder.coloredBoxCall(onColoredBox: Boolean, content: Code.Builder.() -> Unit) {
Expand All @@ -26,3 +29,21 @@ fun Code.Builder.coloredBoxCall(onColoredBox: Boolean, content: Code.Builder.()
content()
}
}

fun FunctionCall.Builder.painterArgument(@DrawableRes id: Int) {
functionCallArgument("painter", "painterResource") {
typedArgument("id", id)
}
}

fun FunctionCall.Builder.contentDescriptionArgument(@StringRes id: Int) {
functionCallArgument("contentDescription", "stringResource") {
typedArgument("id", id)
}
}

fun FunctionCall.Builder.onClickArgument(init: Code.Builder.() -> Unit = {}) = lambdaArgument("onClick", init)

fun FunctionCall.Builder.textArgument(text: String?) = typedArgument("text", text)

fun FunctionCall.Builder.enabledArgument(boolean: Boolean) = typedArgument("enabled", boolean)
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ 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.components.contentDescriptionArgument
import com.orange.ouds.app.ui.components.enabledArgument
import com.orange.ouds.app.ui.components.onClickArgument
import com.orange.ouds.app.ui.components.painterArgument
import com.orange.ouds.app.ui.components.textArgument
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.CustomizationChoiceChips
Expand Down Expand Up @@ -197,19 +202,15 @@ private fun ButtonDemoCodeSnippet(state: ButtonDemoState, modifier: Modifier = M
functionCall(OudsButton::class.simpleName.orEmpty()) {
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)
}
painterArgument(R.drawable.ic_heart)
contentDescriptionArgument(R.string.app_components_button_icon_a11y)
}
}
if (state.layout in listOf(ButtonDemoState.Layout.TextOnly, ButtonDemoState.Layout.IconAndText)) {
typedArgument("text", text)
textArgument(text)
}
lambdaArgument("onClick")
typedArgument("enabled", state.enabled)
onClickArgument()
enabledArgument(state.enabled)
typedArgument("style", state.style)
typedArgument("hierarchy", state.hierarchy)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ 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.components.enabledArgument
import com.orange.ouds.app.ui.components.onClickArgument
import com.orange.ouds.app.ui.components.painterArgument
import com.orange.ouds.app.ui.components.textArgument
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.CustomizationChoiceChips
Expand Down Expand Up @@ -184,21 +188,19 @@ private fun LinkDemoCodeSnippet(state: LinkDemoState, modifier: Modifier = Modif
CodeSnippet(modifier = modifier) {
coloredBoxCall(state.onColoredBox) {
functionCall(OudsLink::class.simpleName.orEmpty()) {
typedArgument("text", text)
textArgument(text)
when (state.layout) {
LinkDemoState.Layout.TextOnly -> {}
LinkDemoState.Layout.IconAndText -> {
constructorCallArgument<OudsLink.Icon>("icon") {
functionCallArgument("painter", "painterResource") {
typedArgument("id", R.drawable.ic_heart)
}
painterArgument(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)
onClickArgument()
enabledArgument(state.enabled)
typedArgument("size", state.size)
}
}
Expand Down

0 comments on commit dfcb99b

Please sign in to comment.