Skip to content

Commit

Permalink
UI: Divider
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz committed Oct 6, 2024
1 parent 898a09e commit 1746850
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package xyz.ksharma.krail.design.system.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.unit.dp
import xyz.ksharma.krail.design.system.LocalContentColor
import xyz.ksharma.krail.design.system.theme.KrailTheme

@Composable
fun Divider(
modifier: Modifier = Modifier,
type: DividerType = DividerType.HORIZONTAL,
color: Color? = null,
) {
CompositionLocalProvider(LocalContentColor provides KrailTheme.colors.onBackground.copy(alpha = 0.2f)) {
Box(
modifier = modifier
.then(
when (type) {
DividerType.HORIZONTAL -> Modifier
.fillMaxWidth()
.height(1.dp)

DividerType.VERTICAL -> Modifier
.fillMaxHeight()
.width(1.dp)
}
)
.background(color = color ?: LocalContentColor.current)
)
}
}

enum class DividerType {
HORIZONTAL,
VERTICAL
}

@PreviewLightDark
@Composable
private fun DividerPreview() {
KrailTheme {
Box(
modifier = Modifier
.fillMaxWidth()
.height(30.dp)
.background(KrailTheme.colors.background),
contentAlignment = Alignment.Center,
) {
Divider()
}
}
}

@PreviewLightDark
@Composable
private fun DividerVerticalPreview() {
KrailTheme {
Box(
modifier = Modifier
.size(30.dp)
.background(KrailTheme.colors.background),
contentAlignment = Alignment.Center,
) {
Divider(type = DividerType.VERTICAL)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package xyz.ksharma.krail.trip_planner.ui.state.searchstop

import xyz.ksharma.krail.trip_planner.domain.model.TransportMode

sealed interface SearchStopUiEvent {

data class SearchTextChanged(val query: String) : SearchStopUiEvent

data class StopSelected(
val stopId: String,
val stopName: String,
val mode: List<TransportMode.TransportModeType>,
) : SearchStopUiEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ package xyz.ksharma.krail.trip_planner.ui.searchstop
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.lazy.LazyColumn
Expand All @@ -32,6 +29,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.mapLatest
import timber.log.Timber
import xyz.ksharma.krail.design.system.components.Divider
import xyz.ksharma.krail.design.system.components.Text
import xyz.ksharma.krail.design.system.components.TextField
import xyz.ksharma.krail.design.system.components.TransportModeIcon
Expand All @@ -41,6 +39,9 @@ import xyz.ksharma.krail.trip_planner.domain.model.TransportMode
import xyz.ksharma.krail.trip_planner.ui.state.searchstop.SearchStopState
import xyz.ksharma.krail.trip_planner.ui.state.searchstop.SearchStopUiEvent

/**
* TODO - implement scroll to top, when too many search results are displayed.
*/
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun SearchStopScreen(
Expand Down Expand Up @@ -111,13 +112,7 @@ fun SearchStopScreen(
}
}

// Divider Component
Box(
modifier = Modifier
.fillMaxWidth()
.height(1.dp)
.background(color = KrailTheme.colors.onBackground.copy(alpha = 0.2f))
)
Divider()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SearchStopViewModel @Inject constructor(
fun onEvent(event: SearchStopUiEvent) {
when (event) {
is SearchStopUiEvent.SearchTextChanged -> onSearchTextChanged(event.query)
is SearchStopUiEvent.StopSelected -> {}
}
}

Expand Down

0 comments on commit 1746850

Please sign in to comment.