xfy bacc2bc8dc Use primaryContainer colors when today is also selected
Distinguish the selected-today state from regular selection by using
primaryContainer/onPrimaryContainer instead of primary/onPrimary,
providing a softer visual treatment for the combined state.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-14 17:53:33 +08:00

70 lines
2.4 KiB
Kotlin

package plus.rua.project.ui
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
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.unit.dp
import androidx.compose.ui.text.style.TextAlign
import kotlinx.datetime.LocalDate
/**
* 单个日期单元格,显示日期数字并支持选中/今天/非当月状态。
*
* @param date 日期
* @param isCurrentMonth 是否属于当前显示月份
* @param isSelected 是否为选中日期
* @param isToday 是否为今天
* @param onClick 点击回调
* @param modifier 外部布局修饰符
*/
@Composable
fun DayCell(
date: LocalDate,
isCurrentMonth: Boolean,
isSelected: Boolean,
isToday: Boolean,
onClick: () -> Unit,
modifier: Modifier = Modifier
) {
val contentColor = when {
isSelected && isToday -> MaterialTheme.colorScheme.onPrimaryContainer
isSelected -> MaterialTheme.colorScheme.onPrimary
isToday -> MaterialTheme.colorScheme.primary
!isCurrentMonth -> MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
else -> MaterialTheme.colorScheme.onSurface
}
Box(
modifier = modifier
.aspectRatio(1f)
.clip(CircleShape)
.then(
when {
isSelected && isToday -> Modifier.background(MaterialTheme.colorScheme.primaryContainer)
isSelected -> Modifier.background(MaterialTheme.colorScheme.primary)
isToday -> Modifier.border(BorderStroke(1.5.dp, MaterialTheme.colorScheme.primary), CircleShape)
else -> Modifier
}
)
.clickable(onClick = onClick),
contentAlignment = Alignment.Center
) {
Text(
text = date.day.toString(),
textAlign = TextAlign.Center,
color = contentColor,
style = MaterialTheme.typography.bodyMedium
)
}
}