Skip to content

Commit

Permalink
Merge pull request #626 from Orange-OpenSource/624-technical-enhance-…
Browse files Browse the repository at this point in the history
…code-implementation-syntax

624 - Enhance code implementation syntax
  • Loading branch information
paulinea authored Sep 21, 2023
2 parents 0e8cb9d + 2ef4256 commit e2b5fd4
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ fun ComponentTopAppBar(variant: Variant) {
title(context.getString(R.string.component_app_bars_top_regular))

if (isNavigationIconEnabled) {
classInstance("navigationIcon", OdsTopAppBarNavigationIcon::class.java) {
simple("imageVector", "<image vector>")
classInstance<OdsTopAppBarNavigationIcon>("navigationIcon") {
imageVector()
contentDescription(context.getString(R.string.top_app_bar_back_icon_desc))
}
}

list("actions") {
repeat(actionCount.value) {
classInstance(OdsTopAppBarActionButton::class.java) {
classInstance<OdsTopAppBarActionButton> {
onClick()
painter()
contentDescription("icon description")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@ fun ComponentBanners() {
exhaustiveParameters = false,
parameters = {
string("message", if (hasTwoTextLines) recipe.description else recipe.title)
classInstance("firstButton", OdsBannerButton::class.java) {
classInstance<OdsBannerButton>("firstButton") {
text(context.getString(R.string.component_banner_dismiss))
onClick()
}
if (hasImage) {
classInstance("image", OdsBannerImage::class.java) {
classInstance<OdsBannerImage>("image") {
painter()
contentDescription("")
}
}
if (hasSecondButton) {
classInstance("secondButton", OdsBannerButton::class.java) {
classInstance<OdsBannerButton>("secondButton") {
text(context.getString(R.string.component_banner_detail))
onClick()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ fun ComponentBottomNavigation() {
parameters = {
list("items") {
navigationItems.take(selectedNavigationItemCount.value).forEach { item ->
classInstance(OdsBottomNavigationItem::class.java) {
classInstance("icon", OdsBottomNavigationItemIcon::class.java) {
classInstance<OdsBottomNavigationItem> {
classInstance<OdsBottomNavigationItemIcon>("icon") {
painter()
contentDescription("")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import com.orange.ods.compose.component.button.OdsButton
import com.orange.ods.compose.component.button.OdsButtonIcon
import com.orange.ods.compose.component.button.OdsButtonStyle
import com.orange.ods.compose.theme.OdsDisplaySurface
import com.orange.ods.extension.fullName

@Composable
fun ButtonsContained(customizationState: ButtonCustomizationState) {
Expand Down Expand Up @@ -84,10 +83,10 @@ fun ButtonsContained(customizationState: ButtonCustomizationState) {
name = OdsComposable.OdsButton.name,
exhaustiveParameters = false,
parameters = {
simple("style", buttonStyle.value.fullName)
enum("style", buttonStyle.value)
if (hasFullScreenWidth) fillMaxWidth()
if (hasLeadingIcon) {
classInstance("icon", OdsButtonIcon::class.java) {
classInstance<OdsButtonIcon>("icon") {
painter()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fun ButtonsOutlined(customizationState: ButtonCustomizationState) {
parameters = {
if (hasFullScreenWidth) fillMaxWidth()
if (hasLeadingIcon) {
classInstance("icon", OdsButtonIcon::class.java) {
classInstance<OdsButtonIcon>("icon") {
painter()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import com.orange.ods.compose.component.button.OdsButtonIcon
import com.orange.ods.compose.component.button.OdsTextButton
import com.orange.ods.compose.component.button.OdsTextButtonStyle
import com.orange.ods.compose.theme.OdsDisplaySurface
import com.orange.ods.extension.fullName

@Composable
fun ButtonsText(customizationState: ButtonCustomizationState) {
Expand Down Expand Up @@ -79,10 +78,10 @@ fun ButtonsText(customizationState: ButtonCustomizationState) {
name = OdsComposable.OdsTextButton.name,
exhaustiveParameters = false,
parameters = {
simple("style", textButtonStyle.value.fullName)
enum("style", textButtonStyle.value)
if (hasFullScreenWidth) fillMaxWidth()
if (hasLeadingIcon) {
classInstance("icon", OdsButtonIcon::class.java) {
classInstance<OdsButtonIcon>("icon") {
painter()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun ButtonsTextToggleButtonsRow(customizationState: ButtonCustomizationState) {
parameters = {
list("textToggleButtons") {
textToggleButtons.take(toggleCount.value).forEach { item ->
classInstance(OdsTextToggleButtonsRowItem::class.java) {
classInstance<OdsTextToggleButtonsRowItem> {
text(item.text)
enabled(customizationState.isEnabled)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fun ButtonsIcon(customizationState: ButtonIconCustomizationState) {
name = OdsComposable.OdsIconButton.name,
exhaustiveParameters = false,
parameters = {
classInstance("icon", OdsIconButtonIcon::class.java) {
classInstance<OdsIconButtonIcon>("icon") {
painter()
contentDescription("")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ fun ButtonsIconToggle(customizationState: ButtonIconCustomizationState) {
name = OdsComposable.OdsIconToggleButton.name,
exhaustiveParameters = false,
parameters = {
classInstance("uncheckedIcon", OdsIconButtonIcon::class.java) {
classInstance<OdsIconButtonIcon>("uncheckedIcon") {
painter()
contentDescription("")
}
classInstance("checkedIcon", OdsIconButtonIcon::class.java) {
classInstance<OdsIconButtonIcon>("checkedIcon") {
painter()
contentDescription("")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fun ButtonsIconToggleGroup(customizationState: ButtonIconCustomizationState) {
parameters = {
list("icons") {
repeat(toggleCount.value) {
classInstance(OdsIconToggleButtonsRowIcon::class.java) {
classInstance<OdsIconToggleButtonsRowIcon> {
painter()
contentDescription("")
if (!isEnabled) enabled(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fun CardHorizontal(customizationState: CardCustomizationState) {
name = OdsComposable.OdsHorizontalCard.name,
exhaustiveParameters = false,
parameters = {
enum("imagePosition", imagePosition.value)
title(recipe.title)
classInstance("image", OdsCardImage::class.java) {
painter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private fun Chip(chipCustomizationState: ChipCustomizationState) {
lambda("onValueChange")
list("chips") {
recipes.forEachIndexed { index, recipe ->
classInstance(OdsChoiceChip::class.java) {
classInstance<OdsChoiceChip<*>> {
text(recipe.title)
stringRepresentation("value", index)
if (!isEnabled) enabled(false)
Expand Down Expand Up @@ -175,13 +175,13 @@ private fun Chip(chipCustomizationState: ChipCustomizationState) {
parameters = {
text(recipe?.title.orEmpty())
if (isActionChip || hasLeadingIcon) {
classInstance("leadingIcon", OdsChipLeadingIcon::class.java) {
classInstance<OdsChipLeadingIcon>("leadingIcon") {
painter()
contentDescription("")
}
}
if (hasLeadingAvatar) {
classInstance("leadingAvatar", OdsChipLeadingAvatar::class.java) {
classInstance<OdsChipLeadingAvatar>("leadingAvatar") {
image()
contentDescription("")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fun ChipFilter() {
parameters = {
text(ingredient.food.name)
if (hasLeadingAvatar) {
classInstance("leadingAvatar", OdsChipLeadingAvatar::class.java) {
classInstance<OdsChipLeadingAvatar>("leadingAvatar") {
image()
contentDescription("")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ fun ComponentDialog() {
exhaustiveParameters = false,
parameters = {
simple("text", "<dialog text>")
classInstance("confirmButton", OdsAlertDialogButton::class.java) {
classInstance<OdsAlertDialogButton>("confirmButton") {
text(confirmButtonText)
onClick()
}
if (customizationState.isTitleChecked) string("title", recipe.title)
if (customizationState.isDismissButtonChecked) {
classInstance("dismissButton", OdsAlertDialogButton::class.java) {
classInstance<OdsAlertDialogButton>("dismissButton") {
text(dismissButtonText)
onClick()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fun ComponentFloatingActionButton() {
name = usedComponentName,
exhaustiveParameters = false,
parameters = {
classInstance("icon", OdsFloatingActionButtonIcon::class.java) {
classInstance<OdsFloatingActionButtonIcon>("icon") {
painter()
contentDescription("")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,21 @@ fun ComponentImageTile() {
name = OdsComposable.OdsImageTile.name,
exhaustiveParameters = false,
parameters = {
stringRepresentation("legendAreaDisplayType", type.value)
enum("legendAreaDisplayType", type.value)
if (hasText) title(recipe.title)
classInstance("image", OdsImageTileImage::class.java) {
classInstance<OdsImageTileImage>("image") {
painter()
contentDescription("")
}
if (hasIcon) {
classInstance("icon", OdsImageTileIconToggleButton::class.java) {
classInstance<OdsImageTileIconToggleButton>("icon") {
checked(iconChecked)
lambda("onCheckedChange")
classInstance("uncheckedIcon", OdsIconButtonIcon::class.java) {
classInstance<OdsIconButtonIcon>("uncheckedIcon") {
painter()
contentDescription("")
}
classInstance("checkedIcon", OdsIconButtonIcon::class.java) {
classInstance<OdsIconButtonIcon>("checkedIcon") {
painter()
contentDescription("")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fun MenuDropdown() {
lambda("onDismissRequest")
list("items") {
recipes.take(2).forEachIndexed { index, recipe ->
classInstance(OdsDropdownMenuItem::class.java) {
classInstance<OdsDropdownMenuItem> {
string("text", recipe.title)
if (hasIcons && recipe.iconResId != null) icon()
if (hasDividerExample && index == dividerIndex) stringRepresentation("divider", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fun MenuExposedDropdown() {
string("label", label)
list("items") {
items.forEach { item ->
classInstance(OdsExposedDropdownMenuItem::class.java) {
classInstance<OdsExposedDropdownMenuItem> {
string("label", item.label)
if (hasIcons) simple("iconResId", "<drawable id>")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,24 @@ fun ComponentModalDrawers() {
name = OdsComposable.OdsModalDrawer.name,
exhaustiveParameters = false,
parameters = {
classInstance("drawerHeader", OdsModalDrawerHeader::class.java) {
classInstance<OdsModalDrawerHeader>("drawerHeader") {
title(title)
image()
stringRepresentation("imageDisplayType", imageDisplayType)
enum("imageDisplayType", imageDisplayType)
subtitle?.let { subtitle(it) }
}
list("drawerContentList") {
if (isContentExampleChecked) {
if (hasLabel) {
classInstance(OdsModalDrawerSectionLabel::class.java) {
classInstance<OdsModalDrawerSectionLabel> {
label("Section")
}
}
classInstance(OdsModalDrawerListItem::class.java) {
classInstance<OdsModalDrawerListItem> {
icon()
simple("text", "<item label>")
}
if (hasDivider) classInstance(OdsModalDrawerDivider::class.java)
if (hasDivider) classInstance<OdsModalDrawerDivider>()
}
}
simple("selectedItem", "<OdsModalDrawerItem>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fun ProgressLinear() {
if (type.value == ProgressCustomizationState.Type.Determinate) stringRepresentation("progress", determinateProgressValue)
if (hasLabel) string("label", text)
if (hasIcon) {
classInstance("icon", OdsLinearProgressIndicatorIcon::class.java) {
classInstance<OdsLinearProgressIndicatorIcon>("icon") {
painter()
contentDescription("")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fun TextFieldCodeImplementationColumn(
lambda("onValueChange")
label(label)
placeholder(placeholder)
classInstance("keyboardOptions", KeyboardOptions::class.java) {
classInstance<KeyboardOptions>("keyboardOptions") {
simple("capitalization", capitalizationValue)
stringRepresentation("keyboardType", softKeyboardType.value.keyboardType)
stringRepresentation("imeAction", softKeyboardAction.value.imeAction)
Expand Down
Loading

0 comments on commit e2b5fd4

Please sign in to comment.