Skip to content

Surface

Surface is a foundational container component in Miuix, used to provide consistent background and border effects for application content, offering a unified visual foundation for interface elements. It supports simple custom styles.

Import

kotlin
import top.yukonga.miuix.kmp.basic.Surface

Basic Usage

The Surface component can wrap other content, providing them with background, border, and shadow effects:

kotlin
Surface(
    modifier = Modifier
        .size(200.dp)
        .padding(16.dp),
    color = MiuixTheme.colorScheme.background,
    shape = RoundedCornerShape(16.dp),
    shadowElevation = 4.dp
) {
    Text(
        text = "Surface Example",
        modifier = Modifier.padding(16.dp)
    )
}

Properties

Basic Surface Properties

Property NameTypeDescriptionDefault ValueRequired
modifierModifierModifiers applied to SurfaceModifierNo
shapeShapeShape of the SurfaceRectangleShapeNo
colorColorBackground color of SurfaceMiuixTheme.colorScheme.backgroundNo
borderBorderStroke?Border style of SurfacenullNo
shadowElevationDpShadow elevation of Surface0.dpNo
content@Composable () -> UnitComposable function for the Surface content area-Yes

Additional Properties for Clickable Surface

Property NameTypeDescriptionDefault ValueRequired
onClick() -> UnitCallback triggered on click-Yes
enabledBooleanWhether the Surface is clickabletrueNo

Advanced Usage

Clickable Surface

Create an interactive Surface to respond to user clicks:

kotlin
Surface(
    onClick = { /* Handle click event */ },
    modifier = Modifier.size(200.dp).padding(16.dp),
    shape = RoundedCornerShape(16.dp),
    color = MiuixTheme.colorScheme.primaryContainer,
    shadowElevation = 4.dp
) {
    Box(
        modifier = Modifier.fillMaxSize(),
        contentAlignment = Alignment.Center
    ) {
        Text(
            text = "Clickable, like a button",
            modifier = Modifier.padding(16.dp).fillMaxSize(),
            textAlign = TextAlign.Center,
        )
    }
}

Custom Styles

Create custom styles with different shapes, colors, and borders:

kotlin
Surface(
    modifier = Modifier.size(200.dp).padding(16.dp),
    shape = CircleShape,
    color = MiuixTheme.colorScheme.secondaryContainer,
    border = BorderStroke(2.dp, MiuixTheme.colorScheme.secondary),
    shadowElevation = 8.dp
) {
    Box(
        modifier = Modifier.fillMaxSize(),
        contentAlignment = Alignment.Center
    ) {
        Text(
            text = "Circular Surface",
            modifier = Modifier.padding(16.dp),
            textAlign = TextAlign.Center,
        )
    }
}

Combined Usage

Combine Surface with other components to create card-like layouts:

kotlin
Surface(
    modifier = Modifier.fillMaxWidth().padding(16.dp),
    shape = RoundedCornerShape(16.dp),
    color = MiuixTheme.colorScheme.surface,
    border = BorderStroke(1.dp, MiuixTheme.colorScheme.outline.copy(alpha = 0.2f)),
    shadowElevation = 4.dp
) {
    Column(
        modifier = Modifier.padding(16.dp)
    ) {
        Text(
            text = "Card Title",
            style = MiuixTheme.textStyles.headline1
        )
        Spacer(modifier = Modifier.height(8.dp))
        Text(
            text = "This is the card content area, where various components and information can be placed. The Surface component provides a unified visual container.",
            style = MiuixTheme.textStyles.body1
        )
        Spacer(modifier = Modifier.height(16.dp))
        Button(
            onClick = { /* Handle click event */ }
        ) {
            Text("Action Button")
        }
    }
}

Disabled State

Create a clickable Surface with a disabled state:

kotlin
var isEnabled by remember { mutableStateOf(false) }

Surface(
    onClick = { /* Handle click event */ },
    enabled = isEnabled,
    modifier = Modifier.size(200.dp).padding(16.dp),
    shape = RoundedCornerShape(16.dp),
    color = MiuixTheme.colorScheme.surface.copy(alpha = 0.6f),
    shadowElevation = 1.dp
) {
    Box(
        modifier = Modifier.fillMaxSize(),
        contentAlignment = Alignment.Center
    ) {
        Text(
            text = "Disabled Click State",
            modifier = Modifier.padding(16.dp),
            textAlign = TextAlign.Center,
        )
    }
}

Released under the Apache-2.0 License