Skip to content

FloatingActionButton

FloatingActionButton is a floating button component in Miuix, typically used to display the most important or frequently used actions on a page. It usually floats above the interface with a prominent visual effect for quick user access.

This component is typically used in conjunction with the Scaffold component to maintain consistent layout and behavior across different pages in the application.

Import

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

Basic Usage

The FloatingActionButton component can be used to trigger important actions:

kotlin
FloatingActionButton(
    onClick = { /* Handle click event */ }
) {
    Icon(
        imageVector = MiuixIcons.Useful.New,
        contentDescription = "Add"
    )
}

Component States

Since this component is typically used for the most common actions, it does not have built-in state variations.

Properties

FloatingActionButton Properties

Property NameTypeDescriptionDefault ValueRequired
onClick() -> UnitCallback triggered when clicked-Yes
modifierModifierModifier applied to the buttonModifierNo
shapeShapeShape of the buttonCircleShapeNo
containerColorColorBackground color of the buttonMiuixTheme.colorScheme.primaryNo
shadowElevationDpShadow elevation of the button4.dpNo
minWidthDpMinimum width of the button60.dpNo
minHeightDpMinimum height of the button60.dpNo
defaultWindowInsetsPaddingBooleanApply default window insets paddingtrueNo
content@Composable () -> UnitComposable content of the button-Yes

Advanced Usage

Custom Color

kotlin
FloatingActionButton(
    onClick = { /* Handle click event */ },
    containerColor = Color.Red
) {
    Icon(
        imageVector = MiuixIcons.Useful.Like,
        contentDescription = "Like",
        tint = Color.White
    )
}

Extended Floating Action Button

kotlin
FloatingActionButton(
    onClick = { /* Handle click event */ },
    shape = RoundedCornerShape(16.dp),
    minWidth = 120.dp
) {
    Row(
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.Center,
        modifier = Modifier.padding(horizontal = 16.dp)
    ) {
        Icon(
            imageVector = MiuixIcons.Useful.New,
            contentDescription = "Add",
            tint = Color.White
        )
        Spacer(modifier = Modifier.width(8.dp))
        Text("Add", color = Color.White)
    }
}

Floating Action Button with Scaffold

kotlin
Scaffold(
    floatingActionButton = {
        FloatingActionButton(
            onClick = { /* Handle click event */ }
        ) {
            Icon(
                imageVector = MiuixIcons.Useful.Add,
                contentDescription = "Add"
            )
        }
    },
    floatingActionButtonPosition = FabPosition.End
) { paddingValues ->
    // Content area needs to consider padding
    Box(
        modifier = Modifier
            .fillMaxSize()
            .padding(paddingValues)
    ) {
        // ...
    }
}

Animated Floating Action Button

kotlin
var expanded by remember { mutableStateOf(false) }
val animatedSize by animateDpAsState(
    targetValue = if (expanded) 65.dp else 60.dp,
    label = "FAB size animation",
)

FloatingActionButton(
    onClick = { expanded = !expanded },
    minWidth = animatedSize,
    minHeight = animatedSize
) {
    Icon(
        imageVector = if (expanded) MiuixIcons.Useful.Remove else MiuixIcons.Useful.New,
        contentDescription = if (expanded) "Remove" else "Add",
        tint = Color.White
    )
}

Released under the Apache-2.0 License