From 00a24e58fd7b88747e4a7a894ea2a973a1cf5fe4 Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 14 May 2026 13:20:32 +0800 Subject: [PATCH] Add MonthHeader, WeekdayHeader, and DayCell UI components Co-Authored-By: Claude Opus 4.7 --- .../kotlin/plus/rua/project/ui/DayCell.kt | 52 +++++++++++++++++++ .../kotlin/plus/rua/project/ui/MonthHeader.kt | 29 +++++++++++ .../plus/rua/project/ui/WeekdayHeader.kt | 26 ++++++++++ 3 files changed, 107 insertions(+) create mode 100644 shared/src/commonMain/kotlin/plus/rua/project/ui/DayCell.kt create mode 100644 shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt create mode 100644 shared/src/commonMain/kotlin/plus/rua/project/ui/WeekdayHeader.kt diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/DayCell.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/DayCell.kt new file mode 100644 index 0000000..257fe10 --- /dev/null +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/DayCell.kt @@ -0,0 +1,52 @@ +package plus.rua.project.ui + +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.text.style.TextAlign +import kotlinx.datetime.LocalDate + +@Composable +fun DayCell( + date: LocalDate, + isCurrentMonth: Boolean, + isSelected: Boolean, + isToday: Boolean, + onClick: () -> Unit, + modifier: Modifier = Modifier +) { + val contentColor = when { + isSelected -> MaterialTheme.colorScheme.onPrimary + !isCurrentMonth -> MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f) + else -> MaterialTheme.colorScheme.onSurface + } + + val backgroundColor = when { + isSelected -> MaterialTheme.colorScheme.primary + else -> MaterialTheme.colorScheme.surface + } + + Box( + modifier = modifier + .aspectRatio(1f) + .clip(CircleShape) + .background(backgroundColor) + .clickable(onClick = onClick), + contentAlignment = Alignment.Center + ) { + Text( + text = date.day.toString(), + textAlign = TextAlign.Center, + color = contentColor, + style = MaterialTheme.typography.bodyMedium + ) + } +} diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt new file mode 100644 index 0000000..db4d118 --- /dev/null +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt @@ -0,0 +1,29 @@ +package plus.rua.project.ui + +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp + +@Composable +fun MonthHeader( + year: Int, + month: Int, + weekNumber: Int, + modifier: Modifier = Modifier +) { + Row( + modifier = modifier + .fillMaxWidth() + .padding(horizontal = 16.dp, vertical = 12.dp) + ) { + Text( + text = "${year}年${month}月 第${weekNumber}周", + style = MaterialTheme.typography.titleMedium + ) + } +} diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/WeekdayHeader.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/WeekdayHeader.kt new file mode 100644 index 0000000..7bbd3f5 --- /dev/null +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/WeekdayHeader.kt @@ -0,0 +1,26 @@ +package plus.rua.project.ui + +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.style.TextAlign + +private val WEEKDAY_LABELS = listOf("一", "二", "三", "四", "五", "六", "日") + +@Composable +fun WeekdayHeader(modifier: Modifier = Modifier) { + Row(modifier = modifier.fillMaxWidth()) { + WEEKDAY_LABELS.forEach { label -> + Text( + text = label, + modifier = Modifier.weight(1f), + textAlign = TextAlign.Center, + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + } + } +}