OXYGENHUB
◆ v0.1.3 oxygenhub-android / app / src / main / java / io / oxygenhub / android / ui / common / Panel.kt
1.5 KiB · last changed Panels you can see: the hub's palette by default, clear surface steps and a 1 dp edge on every panel (closes #24) 7 days ago source blame history raw
1
package io.oxygenhub.android.ui.common
2
3
import androidx.compose.foundation.BorderStroke
4
import androidx.compose.foundation.layout.ColumnScope
5
import androidx.compose.material3.CardColors
6
import androidx.compose.material3.CardDefaults
7
import androidx.compose.material3.MaterialTheme
8
import androidx.compose.material3.OutlinedCard
9
import androidx.compose.runtime.Composable
10
import androidx.compose.ui.Modifier
11
import androidx.compose.ui.graphics.Color
12
import androidx.compose.ui.unit.dp
13
14
/**
15
 * A panel you can see on any screen (#24): Material's outlined card on a
16
 * tone a clear step above the background, with a 1 dp edge, as the hub's
17
 * pages give theirs. Every card in the app is one.
18
 */
19
@Composable
20
fun Panel(modifier: Modifier = Modifier, colors: CardColors = panelColors(), content: @Composable ColumnScope.() -> Unit) {
21
    OutlinedCard(modifier, colors = colors, border = panelBorder()) {
22
        // What sits on a panel shows the panel: a ListItem, say, paints
23
        // `surface`, which is the screen's own tone.
24
        val scope = this
25
        MaterialTheme(colorScheme = MaterialTheme.colorScheme.copy(surface = Color.Transparent)) { scope.content() }
26
    }
27
}
28
29
/** A panel's colours; `alpha` below 1 lets a backdrop show through. */
30
@Composable
31
fun panelColors(alpha: Float = 1f): CardColors =
32
    CardDefaults.outlinedCardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow.copy(alpha = alpha))
33
34
@Composable
35
fun panelBorder(): BorderStroke = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant)