KPButton

fun KPButton(onClick: () -> Unit, style: ButtonStyle, size: ButtonSize, modifier: Modifier = Modifier, enabled: Boolean = true, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, elevation: ButtonElevation? = KPButtonDefaults.elevation(), shape: Shape = MaterialTheme.shapes.small, border: BorderStroke? = style.getBorder(width = 1.dp, enabled = enabled), colors: ButtonColors = style.buttonColors, contentPadding: PaddingValues = size.contentPadding, content: @Composable RowScope.() -> Unit)

A customizable button component that wraps androidx.compose.material.Button. It adapts colors, paddings, and other properties based on the provided style and size parameters.

This button provides a standardized appearance and behavior, integrating seamlessly with the application's theme and design requirements.

Parameters

onClick

Lambda to be executed when the button is clicked.

style

Configuration for the button's appearance, defined by ButtonStyle. It includes colors, borders, and other stylistic options.

size

Configuration for the button's dimensions and padding, defined by ButtonSize. It specifies the minimum height, content padding, and typography settings.

modifier

Modifier for adjusting layout or adding additional behavior to the button. Default is Modifier.

enabled

Boolean flag that determines whether the button is clickable. When false, the button is styled as disabled according to the given style. Default is true.

interactionSource

MutableInteractionSource to track interaction events such as clicks and presses. Default is a new instance of MutableInteractionSource.

elevation

Elevation for the button, providing depth and shadow effects. Default is ButtonElevation from KPButtonDefaults.elevation.

shape

Shape of the button's outline. Default is MaterialTheme.shapes.small.

border

BorderStroke for the button's border, determined by style.getBorder. The width defaults to 1.dp, and the appearance depends on the enabled state.

colors

ButtonColors for the button's background, content, and other color properties. Default is style.buttonColors.

contentPadding

PaddingValues for the button's internal padding. Default is provided by size.contentPadding.

content

A composable lambda for defining the content inside the button. Typically includes text or icons.

Example usage:

KPButton(
onClick = { /* Handle click */},
style = KPButtonStyle.Primary,
size = KPButtonSize.Medium,
) {
Text("Click Me")
}

See also