Skip to content

Commit

Permalink
[#701] Replace OdsHorizontalCardImagePosition by OdsHorizontalCard.Im…
Browse files Browse the repository at this point in the history
…age.Position
  • Loading branch information
paulinea committed Nov 10, 2023
1 parent ee9d777 commit a67f630
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import com.orange.ods.compose.component.card.OdsHorizontalCardImagePosition
import com.orange.ods.compose.component.card.OdsHorizontalCard

@Composable
fun rememberCardCustomizationState(
Expand All @@ -25,7 +25,7 @@ fun rememberCardCustomizationState(
subtitleChecked: MutableState<Boolean> = rememberSaveable { mutableStateOf(true) },
buttonCount: MutableState<Int> = rememberSaveable { mutableStateOf(CardCustomizationState.MinButtonCount) },
dividerChecked: MutableState<Boolean> = rememberSaveable { mutableStateOf(true) },
imagePosition: MutableState<OdsHorizontalCardImagePosition> = rememberSaveable { mutableStateOf(OdsHorizontalCardImagePosition.Start) }
imagePosition: MutableState<OdsHorizontalCard.Image.Position> = rememberSaveable { mutableStateOf(OdsHorizontalCard.Image.Position.Start) }
) =
remember(clickable, thumbnailChecked, textChecked, subtitleChecked, buttonCount, dividerChecked, imagePosition) {
CardCustomizationState(clickable, thumbnailChecked, textChecked, subtitleChecked, buttonCount, dividerChecked, imagePosition)
Expand All @@ -38,7 +38,7 @@ class CardCustomizationState(
val subtitleChecked: MutableState<Boolean>,
val buttonCount: MutableState<Int>,
val dividerChecked: MutableState<Boolean>,
val imagePosition: MutableState<OdsHorizontalCardImagePosition>
val imagePosition: MutableState<OdsHorizontalCard.Image.Position>
) {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.orange.ods.app.ui.components.Variant
import com.orange.ods.app.ui.components.utilities.ComponentCountRow
import com.orange.ods.app.ui.components.utilities.ComponentCustomizationBottomSheetScaffold
import com.orange.ods.app.ui.utilities.composable.Subtitle
import com.orange.ods.compose.component.card.OdsHorizontalCardImagePosition
import com.orange.ods.compose.component.card.OdsHorizontalCard
import com.orange.ods.compose.component.chip.OdsChoiceChip
import com.orange.ods.compose.component.chip.OdsChoiceChipsFlowRow
import com.orange.ods.compose.component.list.OdsListItem
Expand Down Expand Up @@ -54,11 +54,11 @@ fun ComponentCard(variant: Variant) {
chips = listOf(
OdsChoiceChip(
text = stringResource(id = R.string.component_card_horizontal_image_position_start),
value = OdsHorizontalCardImagePosition.Start
value = OdsHorizontalCard.Image.Position.Start
),
OdsChoiceChip(
text = stringResource(id = R.string.component_card_horizontal_image_position_end),
value = OdsHorizontalCardImagePosition.End
value = OdsHorizontalCard.Image.Position.End
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions docs/components/Cards.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ OdsHorizontalCard(
text = "Text",
firstButton = OdsCard.Button("First button") { doSomething() },
secondButton = OdsCard.Button("Second button") { doSomething() },
imagePosition = OdsHorizontalCardImagePosition.Start,
imagePosition = OdsHorizontalCard.Image.Position.Start,
divider = false,
onClick = { doSomething() }
)
Expand All @@ -216,7 +216,7 @@ Parameter | Default&nbsp;value | Description
`text: String?` | `null` | Text displayed into the card
`firstButton: OdsCard.Button?` | `null` | First button displayed into the card
`secondButton: OdsCard.Button?` | `null` | Second button displayed into the card
`imagePosition: OdsHorizontalCardImagePosition` | `OdsHorizontalCardImagePosition.Start` | Position of the image within the card, it can be set to `OdsHorizontalCardImagePosition.Start` or `OdsHorizontalCardImagePosition.End`
`imagePosition: OdsHorizontalCard.Image.Position` | `OdsHorizontalCard.Image.Position.Start` | Position of the image within the card, it can be set to `OdsHorizontalCard.Image.Position.Start` or `OdsHorizontalCard.Image.Position.End`
`divider: Boolean` | `true` | Controls the divider display. If `true`, it will be displayed between the card content and the action buttons.
`onClick: (() -> Unit)?` | `null` | Callback invoked on card click
{:.table}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import com.orange.ods.compose.theme.OdsTheme
* @param text Text displayed into the card.
* @param firstButton First [OdsCard.Button] displayed into the card.
* @param secondButton Second [OdsCard.Button] displayed into the card.
* @param imagePosition Position of the image within the card, it can be set to [OdsHorizontalCardImagePosition.Start] or [OdsHorizontalCardImagePosition.End]. [OdsHorizontalCardImagePosition.Start] by default.
* @param imagePosition Position of the image within the card, it can be set to [OdsHorizontalCard.Image.Position.Start] or [OdsHorizontalCard.Image.Position.End]. [OdsHorizontalCard.Image.Position.Start] by default.
* @param divider Controls the divider display. If `true`, it will be displayed between the card content and the action buttons.
* @param onClick Callback invoked on card click.
*/
Expand All @@ -62,7 +62,7 @@ fun OdsHorizontalCard(
text: String? = null,
firstButton: OdsCard.Button? = null,
secondButton: OdsCard.Button? = null,
imagePosition: OdsHorizontalCardImagePosition = OdsHorizontalCardImagePosition.Start,
imagePosition: OdsHorizontalCard.Image.Position = OdsHorizontalCard.Image.Position.Start,
divider: Boolean = true,
onClick: (() -> Unit)? = null,
) {
Expand Down Expand Up @@ -92,8 +92,8 @@ fun OdsHorizontalCard(
top.linkTo(parent.top)
bottom.linkTo(dividerRef.top)
when (imagePosition) {
OdsHorizontalCardImagePosition.Start -> start.linkTo(parent.start)
OdsHorizontalCardImagePosition.End -> end.linkTo(parent.end)
OdsHorizontalCard.Image.Position.Start -> start.linkTo(parent.start)
OdsHorizontalCard.Image.Position.End -> end.linkTo(parent.end)
}
width = Dimension.value(imageSize)
height = Dimension.fillToConstraints.atLeast(imageSize)
Expand All @@ -110,11 +110,11 @@ fun OdsHorizontalCard(
text = title,
modifier = Modifier.constrainAs(titleRef) {
when (imagePosition) {
OdsHorizontalCardImagePosition.Start -> {
OdsHorizontalCard.Image.Position.Start -> {
start.linkTo(imageRef.end, margin = mediumSpacing)
end.linkTo(parent.end, margin = mediumSpacing)
}
OdsHorizontalCardImagePosition.End -> {
OdsHorizontalCard.Image.Position.End -> {
start.linkTo(parent.start, margin = mediumSpacing)
end.linkTo(imageRef.start, margin = mediumSpacing)
}
Expand Down Expand Up @@ -180,8 +180,12 @@ fun OdsHorizontalCard(
}
}

enum class OdsHorizontalCardImagePosition {
Start, End
class OdsHorizontalCard {
class Image {
enum class Position {
Start, End
}
}
}

@UiModePreviews.Default
Expand All @@ -202,7 +206,7 @@ private fun PreviewOdsHorizontalCard(@PreviewParameter(OdsHorizontalCardPreviewP

internal data class OdsHorizontalCardPreviewParameter(
val subtitle: String?,
val imagePosition: OdsHorizontalCardImagePosition,
val imagePosition: OdsHorizontalCard.Image.Position,
val dividerEnabled: Boolean,
val firstButtonText: String?,
val secondButtonText: String?
Expand All @@ -218,9 +222,9 @@ private val previewParameterValues: List<OdsHorizontalCardPreviewParameter>
val secondButtonText = "Second button"

return listOf(
OdsHorizontalCardPreviewParameter(subtitle, OdsHorizontalCardImagePosition.Start, true, firstButtonText, secondButtonText),
OdsHorizontalCardPreviewParameter(subtitle, OdsHorizontalCardImagePosition.End, false, firstButtonText, null),
OdsHorizontalCardPreviewParameter(subtitle, OdsHorizontalCardImagePosition.Start, true, null, null),
OdsHorizontalCardPreviewParameter(null, OdsHorizontalCardImagePosition.Start, false, null, secondButtonText)
OdsHorizontalCardPreviewParameter(subtitle, OdsHorizontalCard.Image.Position.Start, true, firstButtonText, secondButtonText),
OdsHorizontalCardPreviewParameter(subtitle, OdsHorizontalCard.Image.Position.End, false, firstButtonText, null),
OdsHorizontalCardPreviewParameter(subtitle, OdsHorizontalCard.Image.Position.Start, true, null, null),
OdsHorizontalCardPreviewParameter(null, OdsHorizontalCard.Image.Position.Start, false, null, secondButtonText)
)
}

0 comments on commit a67f630

Please sign in to comment.