Yusuf Ibragimov
12/20/2023, 4:27 AMYusuf Ibragimov
12/20/2023, 4:33 AM/**
* @param content you can change default content with your custom content
* @param rightIcon use to add icon after the text in button
* @param leftIcon use to add icon before the text in button
* @param interactionSource - the MutableInteractionSource representing
* the stream of Interactions for this Button. You can create and pass
* in your own remembered MutableInteractionSource if you want to observe
* Interactions and customize the appearance / behavior of this Button in different Interactions.
* */
@Composable
fun DavrButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
title: String = "",
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
shape: Shape = ButtonShape,
border: BorderStroke? = null,
backgroundColor: Color = DavrTheme.backgroundColors.button,
disableBackgroundColor: Color = DavrTheme.backgroundColors.muted,
contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
content: @Composable RowScope.() -> Unit = {
DefaultContentButton(
modifier,
enabled,
title,
leadingIcon,
trailingIcon
)
}
) {
Surface(
shape = shape,
color = Color.Transparent,
border = border,
modifier = modifier
.clip(shape)
.background(if (enabled) backgroundColor else disableBackgroundColor)
.clickable(
onClick = onClick,
enabled = enabled,
role = Role.Button,
interactionSource = interactionSource,
indication = null
)
) {
ProvideTextStyle(
value = B1SemiBold
) {
Row(
Modifier
.defaultMinSize(
minWidth = ButtonDefaults.MinWidth,
minHeight = ButtonDefaults.MinHeight
)
.indication(interactionSource, rememberRipple())
.padding(contentPadding),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
content = content
)
}
}
}
@Composable
internal fun DefaultContentButton(
modifier: Modifier,
enabled: Boolean = true,
title: String = "",
leadingIcon: @Composable() (() -> Unit)?,
trailingIcon: @Composable() (() -> Unit)?
) {
leadingIcon?.invoke()
Text(
text = title,
color = if (enabled) DavrTheme.textColors.contrast else DavrTheme.textColors.disable
)
trailingIcon?.invoke()
}
private val ButtonShape = RoundedCornerShape(CornerSize(16.dp))
here is my component, i will wait your answers to improve my component