Skip to content

Commit

Permalink
Merge pull request #544 from kiwicom/coupon-component
Browse files Browse the repository at this point in the history
Add `Coupon` component
  • Loading branch information
Bořek Leikep authored Sep 29, 2023
2 parents feb3588 + 12f437e commit 0b1ecf7
Show file tree
Hide file tree
Showing 14 changed files with 415 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ internal class BaselineProfileGenerator {
profileSubScreen(MainScreenSemantics.CheckboxItemTag)
profileSubScreen(MainScreenSemantics.ChoiceTileItemTag)
profileSubScreen(MainScreenSemantics.CollapseItemTag)
profileSubScreen(MainScreenSemantics.CouponItemTag)
profileSubScreen(MainScreenSemantics.DialogItemTag) {
device.findObject(By.res(DialogScreenSemantics.OrbitDialogButtonTag))
.clickAndWait(Until.newWindow(), TIMEOUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object MainScreenSemantics {
const val CheckboxItemTag = "main_screen_checkbox_item"
const val ChoiceTileItemTag = "main_screen_choice_tile_item"
const val CollapseItemTag = "main_screen_collapse_item"
const val CouponItemTag = "main_screen_coupon_item"
const val DialogItemTag = "main_screen_dialog_item"
const val EmptyStateItemTag = "main_screen_empty_state_item"
const val KeyValueItemTag = "main_screen_key_value_item"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import kiwi.orbit.compose.catalog.screens.CheckboxScreen
import kiwi.orbit.compose.catalog.screens.ChoiceTileScreen
import kiwi.orbit.compose.catalog.screens.CollapseScreen
import kiwi.orbit.compose.catalog.screens.ColorsScreen
import kiwi.orbit.compose.catalog.screens.CouponScreen
import kiwi.orbit.compose.catalog.screens.DialogMaterialDatePicker
import kiwi.orbit.compose.catalog.screens.DialogMaterialTimePicker
import kiwi.orbit.compose.catalog.screens.DialogsMaterialDialog
Expand Down Expand Up @@ -129,6 +130,7 @@ private fun NavGraph(
composable<Destinations.Checkbox> { CheckboxScreen(navController::navigateUp) }
composable<Destinations.ChoiceTile> { ChoiceTileScreen(navController::navigateUp) }
composable<Destinations.Collapse> { CollapseScreen(navController::navigateUp) }
composable<Destinations.Coupon> { CouponScreen(navController::navigateUp) }
composable<Destinations.Dialog> { DialogsScreen(navController) }
dialog<Destinations.DialogMaterialTimePicker> { DialogMaterialTimePicker(navController) }
dialog<Destinations.DialogMaterialDatePicker> { DialogMaterialDatePicker(navController) }
Expand Down
85 changes: 44 additions & 41 deletions catalog/src/main/java/kiwi/orbit/compose/catalog/Destinations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,131 +8,134 @@ import kotlinx.serialization.Serializable

sealed interface Destinations : Destination {
@Serializable
object Main : Destinations
data object Main : Destinations

@Serializable
object Colors : Destinations
data object Colors : Destinations

@Serializable
object Icons : Destinations
data object Icons : Destinations

@Serializable
object Illustrations : Destinations
data object Illustrations : Destinations

@Serializable
object Typography : Destinations
data object Typography : Destinations

@Serializable
object Alert : Destinations
data object Alert : Destinations

@Serializable
object Badge : Destinations
data object Badge : Destinations

@Serializable
object BadgeList : Destinations
data object BadgeList : Destinations

@Serializable
object Button : Destinations
data object Button : Destinations

@Serializable
object Card : Destinations
data object Card : Destinations

@Serializable
object Checkbox : Destinations
data object Checkbox : Destinations

@Serializable
object ChoiceTile : Destinations
data object ChoiceTile : Destinations

@Serializable
object Collapse : Destinations
data object Collapse : Destinations

@Serializable
object Dialog : Destinations
data object Coupon : Destinations

@Serializable
object DialogMaterial : Destinations
data object Dialog : Destinations

@Serializable
object DialogMaterialTimePicker : Destinations, ResultDestination<DialogMaterialTimePicker.Result> {
data object DialogMaterial : Destinations

@Serializable
data object DialogMaterialTimePicker : Destinations, ResultDestination<DialogMaterialTimePicker.Result> {
@Serializable
data class Result(val time: LocalTime)
}

@Serializable
object DialogMaterialDatePicker : Destinations, ResultDestination<DialogMaterialDatePicker.Result> {
data object DialogMaterialDatePicker : Destinations, ResultDestination<DialogMaterialDatePicker.Result> {
@Serializable
data class Result(val date: LocalDate)
}

@Serializable
object DialogOrbit : Destinations
data object DialogOrbit : Destinations

@Serializable
object EmptyState : Destinations
data object EmptyState : Destinations

@Serializable
object KeyValue : Destinations
data object KeyValue : Destinations

@Serializable
object LinearProgressIndicator : Destination
data object LinearProgressIndicator : Destination

@Serializable
object List : Destinations
data object List : Destinations

@Serializable
object ListChoice : Destinations
data object ListChoice : Destinations

@Serializable
object Loading : Destinations
data object Loading : Destinations

@Serializable
object Radio : Destinations
data object Radio : Destinations

@Serializable
object PillButton : Destinations
data object PillButton : Destinations

@Serializable
object Seat : Destinations
data object Seat : Destinations

@Serializable
object SegmentedSwitch : Destinations
data object SegmentedSwitch : Destinations

@Serializable
object SelectField : Destinations
data object SelectField : Destinations

@Serializable
object Slider : Destinations
data object Slider : Destinations

@Serializable
object Stepper : Destinations
data object Stepper : Destinations

@Serializable
object SurfaceCard : Destinations
data object SurfaceCard : Destinations

@Serializable
object Switch : Destinations
data object Switch : Destinations

@Serializable
object Tabs : Destinations
data object Tabs : Destinations

@Serializable
object Tag : Destinations
data object Tag : Destinations

@Serializable
object TextField : Destinations
data object TextField : Destinations

@Serializable
object Tile : Destinations
data object Tile : Destinations

@Serializable
object TileGroup : Destinations
data object TileGroup : Destinations

@Serializable
object Timeline : Destinations
data object Timeline : Destinations

@Serializable
object Toast : Destinations
data object Toast : Destinations

@Serializable
object TopAppBar : Destinations
data object TopAppBar : Destinations
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package kiwi.orbit.compose.catalog.screens

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kiwi.orbit.compose.catalog.AppTheme
import kiwi.orbit.compose.catalog.semantics.SubScreenSemantics
import kiwi.orbit.compose.icons.Icons
import kiwi.orbit.compose.ui.controls.Coupon
import kiwi.orbit.compose.ui.controls.Scaffold
import kiwi.orbit.compose.ui.controls.Text
import kiwi.orbit.compose.ui.controls.ToastHostState
import kiwi.orbit.compose.ui.controls.TopAppBar
import kotlinx.coroutines.launch

@Composable
internal fun CouponScreen(
onNavigateUp: () -> Unit,
) {
val toastHostState = remember { ToastHostState() }
val coroutineScope = rememberCoroutineScope()

Scaffold(
modifier = Modifier.testTag(SubScreenSemantics.Tag),
topBar = {
TopAppBar(
title = { Text("Coupon") },
onNavigateUp = onNavigateUp,
)
},
toastHostState = toastHostState,
) { contentPadding ->
Box(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.padding(contentPadding),
) {
CouponScreenInner(
onCouponCopied = {
coroutineScope.launch {
toastHostState.showToast("Copied to clipboard!") { Icons.Copy }
}
},
)
}
}
}

@Composable
private fun CouponScreenInner(
onCouponCopied: () -> Unit,
) {
Column(
modifier = Modifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
Row(
horizontalArrangement = Arrangement.spacedBy(4.dp),
) {
Text(
text = "Your coupon:",
modifier = Modifier.alignByBaseline(),
)
Coupon(
code = "hxt3b81f",
onCopied = null,
modifier = Modifier.alignByBaseline(),
)
}
Row(
horizontalArrangement = Arrangement.spacedBy(4.dp),
) {
Text(
text = "Copy your coupon:",
modifier = Modifier.alignByBaseline(),
)
Coupon(
code = "hxt3b81f",
onCopied = onCouponCopied,
modifier = Modifier.alignByBaseline(),
)
}
}
}

@Preview
@Composable
private fun CouponScreenPreview() {
AppTheme {
CouponScreen(onNavigateUp = {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ internal fun MainScreen(
MenuItem("Checkbox", MIcons.CheckBox, Semantics.CheckboxItemTag) { Destinations.Checkbox },
MenuItem("Choice Tile", MIcons.Ballot, Semantics.ChoiceTileItemTag) { Destinations.ChoiceTile },
MenuItem("Collapse", Icons.ChevronDown, Semantics.CollapseItemTag) { Destinations.Collapse },
MenuItem("Coupon", Icons.PromoCode, Semantics.CouponItemTag) { Destinations.Coupon },
MenuItem("Dialog", Icons.Chat, Semantics.DialogItemTag) { Destinations.Dialog },
MenuItem("EmptyState", MIcons.SignalWifiOff, Semantics.EmptyStateItemTag) { Destinations.EmptyState },
MenuItem("KeyValue", MIcons.DragHandle, Semantics.KeyValueItemTag) { Destinations.KeyValue },
Expand Down
2 changes: 2 additions & 0 deletions component-status.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
android: Released
- component: CountryFlag
android: Released
- component: Coupon
android: Released
- component: Dialog
android: Released
- component: EmptyState
Expand Down
Loading

0 comments on commit 0b1ecf7

Please sign in to comment.