Skip to content

Commit b20519b

Browse files
committed
Fix DateCell elevation
1 parent 3d17260 commit b20519b

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

rowKalendar/src/commonMain/kotlin/io/github/chouaibmo/rowkalendar/RowKalendar.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fun RowKalendar(
2525
maxDays: Int = 365,
2626
content: @Composable (date: LocalDate, isSelected: Boolean, onClick: (LocalDate) -> Unit) -> Unit
2727
) {
28-
val viewModel: RowKalendarViewModel = viewModel()
28+
val viewModel: RowKalendarViewModel = viewModel { RowKalendarViewModel() }
2929
val uiState = viewModel.uiState.value
3030
val scrollState = rememberLazyListState(
3131
initialFirstVisibleItemIndex = (uiState.dates.size / 2) - 1,
@@ -38,7 +38,7 @@ fun RowKalendar(
3838
LazyRow(
3939
state = scrollState,
4040
modifier = modifier,
41-
horizontalArrangement = Arrangement.spacedBy(8.dp),
41+
horizontalArrangement = Arrangement.spacedBy(6.dp),
4242
) {
4343
itemsIndexed(uiState.dates) { index, date ->
4444

rowKalendar/src/commonMain/kotlin/io/github/chouaibmo/rowkalendar/components/DateCell.kt

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ import androidx.compose.foundation.clickable
55
import androidx.compose.foundation.layout.Arrangement
66
import androidx.compose.foundation.layout.Column
77
import androidx.compose.foundation.layout.Spacer
8-
import androidx.compose.foundation.layout.fillMaxSize
98
import androidx.compose.foundation.layout.height
9+
import androidx.compose.foundation.layout.padding
1010
import androidx.compose.material3.Card
1111
import androidx.compose.material3.CardDefaults
1212
import androidx.compose.material3.Text
1313
import androidx.compose.runtime.Composable
1414
import androidx.compose.ui.Alignment
1515
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.draw.clip
17+
import androidx.compose.ui.draw.shadow
1618
import androidx.compose.ui.graphics.Shape
1719
import androidx.compose.ui.text.font.FontWeight
1820
import androidx.compose.ui.unit.dp
21+
import androidx.compose.ui.unit.sp
1922
import io.github.chouaibmo.rowkalendar.extensions.isBefore
2023
import io.github.chouaibmo.rowkalendar.extensions.now
2124
import kotlinx.datetime.LocalDate
@@ -63,27 +66,38 @@ fun DateCell(
6366
}
6467
}
6568

69+
val cellElevation = when {
70+
isSelected -> elevation.selectedElevation
71+
date.isBefore(LocalDate.now()) -> elevation.pastElevation
72+
else -> elevation.futureElevation
73+
}
74+
6675
Card(
67-
modifier = modifier.clickable { onDateSelected(date) },
68-
shape = shape,
76+
modifier = modifier
77+
.shadow(elevation = cellElevation, shape = shape)
78+
.clip(shape = shape)
79+
.clickable { onDateSelected(date) },
6980
border = cellBorder,
7081
colors = CardDefaults.cardColors(containerColor = cellColor),
71-
elevation = CardDefaults.cardElevation(defaultElevation = elevation.defaultElevation)
7282
) {
7383
Column(
7484
horizontalAlignment = Alignment.CenterHorizontally,
7585
verticalArrangement = Arrangement.Center,
76-
modifier = Modifier.fillMaxSize()
86+
modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp)
7787
) {
7888
Text(
79-
text = date.dayOfWeek.name.subSequence(0, 3).toString().uppercase(),
80-
color = textColor
89+
text = date.dayOfWeek.name.subSequence(0, 3).toString()
90+
.lowercase()
91+
.replaceFirstChar { it.uppercase() },
92+
color = textColor,
93+
fontWeight = FontWeight.Bold,
8194
)
8295
Spacer(modifier = Modifier.height(6.dp))
8396
Text(
8497
text = date.dayOfMonth.toString(),
85-
fontWeight = FontWeight.ExtraBold,
86-
color = textColor
98+
fontWeight = FontWeight.Black,
99+
color = textColor,
100+
fontSize = 24.sp
87101
)
88102
}
89103
}

rowKalendar/src/commonMain/kotlin/io/github/chouaibmo/rowkalendar/components/DateCellDefaults.kt

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,15 @@ object DateCellDefaults {
5353
)
5454
}
5555

56-
fun elevation(defaultElevation: Dp = 0.dp): DateCellElevation {
56+
fun elevation(
57+
selectedElevation: Dp = 0.dp,
58+
pastElevation: Dp = 0.dp,
59+
futureElevation: Dp = 0.dp
60+
): DateCellElevation {
5761
return DateCellElevation(
58-
defaultElevation = defaultElevation,
62+
selectedElevation = selectedElevation,
63+
pastElevation = pastElevation,
64+
futureElevation = futureElevation
5965
)
6066
}
6167

@@ -126,8 +132,23 @@ object DateCellDefaults {
126132

127133
/**
128134
* Represents the elevation used in the DateCell.
135+
* Handles the elevation for the selected, past and future states of the DateCell.
129136
*/
130-
data class DateCellElevation(
131-
val defaultElevation: Dp
132-
)
137+
class DateCellElevation(
138+
val selectedElevation: Dp,
139+
val pastElevation: Dp,
140+
val futureElevation: Dp,
141+
) {
142+
fun copy(
143+
selectedElevation: Dp = this.selectedElevation,
144+
pastElevation: Dp = this.pastElevation,
145+
futureElevation: Dp = this.futureElevation
146+
): DateCellElevation {
147+
return DateCellElevation(
148+
selectedElevation = selectedElevation.takeOrElse { this.selectedElevation },
149+
pastElevation = pastElevation.takeOrElse { this.pastElevation },
150+
futureElevation = futureElevation.takeOrElse { this.futureElevation }
151+
)
152+
}
153+
}
133154
}

0 commit comments

Comments
 (0)