Skip to content

Button

Button is a basic interactive component in Miuix, used to trigger actions or events. It provides multiple style options, including primary buttons, secondary buttons, and text buttons.

Import

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

Basic Usage

The Button component can be used to trigger actions or events:

kotlin
Button(
    onClick = { /* Handle click event */ }
) {
    Text("Button")
}

Button Types

Miuix provides various types of buttons suitable for different scenarios and levels of importance:

Primary Button

kotlin
Button(
    onClick = { /* Handle click event */ },
    colors = ButtonDefaults.buttonColorsPrimary()
) {
    Text("Primary Button")
}

Secondary Button

kotlin
Button(
    onClick = { /* Handle click event */ },
    colors = ButtonDefaults.buttonColors()
) {
    Text("Secondary Button")
}

Text Button

kotlin
TextButton(
    text = "Text Button",
    onClick = { /* Handle click event */ }
)

Component States

Disabled State

kotlin
Button(
    onClick = { /* Handle click event */ },
    enabled = false
) {
    Text("Disabled Button")
}

Properties

Button Properties

Property NameTypeDescriptionDefault ValueRequired
onClick() -> UnitCallback triggered on click-Yes
modifierModifierModifier applied to the buttonModifierNo
enabledBooleanWhether the button is clickabletrueNo
cornerRadiusDpCorner radius of the buttonButtonDefaults.CornerRadiusNo
minWidthDpMinimum width of the buttonButtonDefaults.MinWidthNo
minHeightDpMinimum height of the buttonButtonDefaults.MinHeightNo
colorsButtonColorsButton color configurationButtonDefaults.buttonColors()No
insideMarginPaddingValuesInternal padding of the buttonButtonDefaults.InsideMarginNo
content@Composable RowScope.() -> UnitComposable function for button content-Yes

TextButton Properties

Property NameTypeDescriptionDefault ValueRequired
textStringText displayed on the button-Yes
onClick() -> UnitCallback triggered on click-Yes
modifierModifierModifier applied to the buttonModifierNo
enabledBooleanWhether the button is clickabletrueNo
colorsTextButtonColorsText button color configurationButtonDefaults.textButtonColors()No
cornerRadiusDpCorner radius of the buttonButtonDefaults.CornerRadiusNo
minWidthDpMinimum width of the buttonButtonDefaults.MinWidthNo
minHeightDpMinimum height of the buttonButtonDefaults.MinHeightNo
insideMarginPaddingValuesInternal padding of the buttonButtonDefaults.InsideMarginNo

ButtonDefaults Object

The ButtonDefaults object provides default values and color configurations for button components.

Constants

Constant NameTypeDescriptionDefault Value
MinWidthDpMinimum width of the button58.dp
MinHeightDpMinimum height of the button40.dp
CornerRadiusDpCorner radius of the button16.dp
InsideMarginPaddingValuesInternal padding of the buttonPaddingValues(16.dp)

Methods

Method NameTypeDescription
buttonColors()ButtonColorsCreates color configuration for secondary buttons
buttonColorsPrimary()ButtonColorsCreates color configuration for primary buttons
textButtonColors()TextButtonColorsCreates color configuration for secondary text buttons
textButtonColorsPrimary()TextButtonColorsCreates color configuration for primary text buttons

Advanced Usage

Button with Icon

kotlin
Button(
    onClick = { /* Handle click event */ }
) {
    Icon(
        imageVector = MiuixIcons.Useful.Like,
        contentDescription = "Icon"
    )
    Spacer(modifier = Modifier.width(8.dp))
    Text("Button with Icon")
}

Custom Style Button

kotlin
Button(
    onClick = { /* Handle click event */ },
    colors = ButtonDefaults.buttonColors(
        color = Color.Red.copy(alpha = 0.7f)
    ),
    cornerRadius = 8.dp
) {
    Text("Custom Button")
}

Loading State Button

kotlin
var isLoading by remember { mutableStateOf(false) }
val scope = rememberCoroutineScope()

Button(
    onClick = {
        isLoading = true
        // Simulate operation
        scope.launch {
            delay(2000)
            isLoading = false
        }
    },
    enabled = !isLoading
) {
     AnimatedVisibility(
        visible = isLoading
    ) {
        CircularProgressIndicator(
            modifier = Modifier.padding(end = 8.dp),
            size = 20.dp,
            strokeWidth = 4.dp
        )
    }
    Text("Submit")
}

Released under the Apache-2.0 License