Modern.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/components/Modern.kt
1package eu.friedcutlet.yokan.ui.components23import androidx.compose.animation.animateColorAsState4import androidx.compose.animation.core.animateDpAsState5import androidx.compose.foundation.background6import androidx.compose.foundation.border7import androidx.compose.foundation.clickable8import androidx.compose.foundation.hoverable9import androidx.compose.foundation.interaction.MutableInteractionSource10import androidx.compose.foundation.interaction.collectIsHoveredAsState11import androidx.compose.foundation.interaction.collectIsPressedAsState12import androidx.compose.foundation.layout.Box13import androidx.compose.foundation.layout.Column14import androidx.compose.foundation.layout.PaddingValues15import androidx.compose.foundation.layout.Spacer16import androidx.compose.foundation.layout.fillMaxWidth17import androidx.compose.foundation.layout.height18import androidx.compose.foundation.layout.padding19import androidx.compose.foundation.layout.size20import androidx.compose.foundation.layout.width21import androidx.compose.foundation.shape.RoundedCornerShape22import androidx.compose.material.icons.Icons23import androidx.compose.material.icons.automirrored.filled.ArrowBack24import androidx.compose.material3.Button25import androidx.compose.material3.ButtonDefaults26import androidx.compose.material3.ExperimentalMaterial3Api27import androidx.compose.material3.Icon28import androidx.compose.material3.IconButton29import androidx.compose.material3.ListItem30import androidx.compose.material3.ListItemDefaults31import androidx.compose.material3.MaterialTheme32import androidx.compose.material3.SegmentedButton33import androidx.compose.material3.SegmentedButtonDefaults34import androidx.compose.material3.SingleChoiceSegmentedButtonRow35import androidx.compose.material3.Surface36import androidx.compose.material3.Text37import androidx.compose.material3.TopAppBar38import androidx.compose.material3.TopAppBarDefaults39import androidx.compose.runtime.Composable40import androidx.compose.runtime.getValue41import androidx.compose.runtime.remember42import androidx.compose.ui.Alignment43import androidx.compose.ui.Modifier44import androidx.compose.ui.draw.clip45import androidx.compose.ui.graphics.Color46import androidx.compose.ui.graphics.vector.ImageVector47import androidx.compose.ui.unit.Dp48import androidx.compose.ui.unit.dp49import androidx.compose.ui.unit.sp50import org.jetbrains.compose.resources.stringResource51import yokan.composeapp.generated.resources.Res52import yokan.composeapp.generated.resources.action_back5354/**55 * Adds stable hover and press feedback without moving content under the56 * pointer. Touch input keeps the same pressed-color path.57 */58@Composable59fun Modifier.hoverHighlight(onClick: (() -> Unit)? = null): Modifier {60 val interactionSource = remember { MutableInteractionSource() }61 val hovered by interactionSource.collectIsHoveredAsState()62 val pressed by interactionSource.collectIsPressedAsState()63 val tint by animateColorAsState(64 targetValue = when {65 pressed -> MaterialTheme.colorScheme.primary.copy(alpha = 0.12f)66 hovered -> MaterialTheme.colorScheme.primary.copy(alpha = 0.06f)67 else -> Color.Transparent68 },69 )70 return this71 .hoverable(interactionSource = interactionSource)72 .background(tint)73 .let { base ->74 if (onClick != null) {75 base.clickable(76 interactionSource = interactionSource,77 indication = null,78 onClick = onClick,79 )80 } else {81 base82 }83 }84}8586/**87 * Interactive surface with a quiet outline and elevation transition. The88 * bounds stay fixed across hover and press states so dense grids do not89 * visually jitter.90 */91@Composable92fun YokanCard(93 modifier: Modifier = Modifier,94 onClick: (() -> Unit)? = null,95 padding: PaddingValues = PaddingValues(16.dp),96 content: @Composable () -> Unit,97) {98 val interactionSource = remember { MutableInteractionSource() }99 val hovered by interactionSource.collectIsHoveredAsState()100 val pressed by interactionSource.collectIsPressedAsState()101102 val borderColor by animateColorAsState(103 targetValue = when {104 pressed -> MaterialTheme.colorScheme.primary105 hovered -> MaterialTheme.colorScheme.primary.copy(alpha = 0.6f)106 else -> MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.4f)107 },108 )109 val elevation by animateDpAsState(110 targetValue = when {111 pressed -> 6.dp112 hovered -> 3.dp113 else -> 1.dp114 },115 )116117 Surface(118 modifier = modifier119 .hoverable(interactionSource = interactionSource)120 .let { base ->121 if (onClick != null) {122 base.clickable(123 interactionSource = interactionSource,124 indication = null,125 onClick = onClick,126 )127 } else {128 base129 }130 },131 shape = MaterialTheme.shapes.large,132 color = MaterialTheme.colorScheme.surfaceContainer,133 border = androidx.compose.foundation.BorderStroke(1.dp, borderColor),134 tonalElevation = elevation,135 shadowElevation = elevation,136 ) {137 Box(Modifier.padding(padding)) { content() }138 }139}140141/**142 * Pill-shaped primary button with optional leading icon. The shape is forced143 * regardless of the host theme so call sites don't have to repeat the144 * RoundedCornerShape(50) idiom MUI uses for its `Button shape="pill"`.145 */146@Composable147fun YokanPrimaryButton(148 text: String,149 modifier: Modifier = Modifier,150 icon: ImageVector? = null,151 enabled: Boolean = true,152 onClick: () -> Unit,153) {154 Button(155 onClick = onClick,156 enabled = enabled,157 modifier = modifier.height(46.dp),158 shape = RoundedCornerShape(50),159 contentPadding = PaddingValues(horizontal = 20.dp, vertical = 0.dp),160 ) {161 icon?.let {162 Icon(it, contentDescription = null, modifier = Modifier.size(18.dp))163 Spacer(Modifier.width(8.dp))164 }165 Text(text, style = MaterialTheme.typography.labelLarge, letterSpacing = 0.3.sp)166 }167}168169/** Mangayomi-compatible transparent, start-aligned Material app bar. */170@OptIn(ExperimentalMaterial3Api::class)171@Composable172fun YokanTopBar(173 title: String,174 subtitle: String? = null,175 onBack: (() -> Unit)? = null,176 actions: @Composable () -> Unit = {},177) {178 TopAppBar(179 title = {180 Column {181 Text(title)182 subtitle?.let {183 Text(184 text = it,185 style = MaterialTheme.typography.bodySmall,186 color = MaterialTheme.colorScheme.onSurfaceVariant,187 )188 }189 }190 },191 navigationIcon = {192 onBack?.let {193 IconButton(onClick = it) {194 Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = stringResource(Res.string.action_back))195 }196 }197 },198 actions = { actions() },199 colors = TopAppBarDefaults.topAppBarColors(200 containerColor = Color.Transparent,201 scrolledContainerColor = Color.Transparent,202 titleContentColor = MaterialTheme.colorScheme.onSurface,203 navigationIconContentColor = MaterialTheme.colorScheme.onSurface,204 actionIconContentColor = MaterialTheme.colorScheme.onSurfaceVariant,205 ),206 )207}208209/**210 * Compact Material 3 single-choice control for short option lists.211 *212 * Segmented buttons provide selected-state semantics and platform-standard213 * minimum touch targets without each caller rebuilding those contracts.214 */215@OptIn(ExperimentalMaterial3Api::class)216@Composable217fun YokanChipTabs(218 options: List<String>,219 selectedIndex: Int,220 onSelect: (Int) -> Unit,221 modifier: Modifier = Modifier,222) {223 SingleChoiceSegmentedButtonRow(modifier = modifier) {224 options.forEachIndexed { index, label ->225 SegmentedButton(226 selected = index == selectedIndex,227 onClick = { onSelect(index) },228 shape = SegmentedButtonDefaults.itemShape(index, options.size),229 icon = {},230 label = { Text(label) },231 )232 }233 }234}235236/** Hairline horizontal divider with consistent tint across screens. */237@Composable238fun YokanDivider(modifier: Modifier = Modifier, inset: Dp = 0.dp) {239 eu.friedcutlet.yokan.ui.theme.YokanHorizontalDivider(240 modifier = modifier.padding(horizontal = inset),241 thickness = 1.dp,242 )243}244245/** Mangayomi-compatible ListTile: primary leading icon and no implicit chevron. */246@Composable247fun YokanListRow(248 title: String,249 onClick: () -> Unit,250 modifier: Modifier = Modifier,251 subtitle: String? = null,252 icon: ImageVector? = null,253 trailingContent: (@Composable () -> Unit)? = null,254) {255 ListItem(256 modifier = modifier257 .fillMaxWidth()258 .hoverHighlight(onClick),259 headlineContent = { Text(title) },260 supportingContent = subtitle?.let {261 {262 Text(263 text = it,264 fontSize = 11.sp,265 color = MaterialTheme.colorScheme.secondary,266 )267 }268 },269 leadingContent = icon?.let {270 {271 Box(modifier = Modifier.height(40.dp), contentAlignment = Alignment.Center) {272 Icon(273 imageVector = it,274 contentDescription = null,275 tint = MaterialTheme.colorScheme.primary,276 )277 }278 }279 },280 trailingContent = trailingContent,281 colors = ListItemDefaults.colors(containerColor = Color.Transparent),282 )283}284