Skip to content

Commit

Permalink
Add configurable content padding (can increase height and width) (#3680)
Browse files Browse the repository at this point in the history
  • Loading branch information
FikriMilano authored Jan 16, 2025
1 parent 3818ab8 commit 62b94e3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ data class ButtonProperties(
val backgroundOpacity: Float = 0f,
val colorOpacity: Float = 0f,
val statusIconSize: Int = 16,
val contentPaddingVertical: Float? = null,
val contentPaddingHorizontal: Float? = null,
) : ViewProperties(), Parcelable {
/**
* This function determines the status color to display depending on the value of the service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,29 @@ fun ActionableButton(
enabled = buttonProperties.enabled.toBoolean(),
border = BorderStroke(width = 0.8.dp, color = statusColor.copy(alpha = 0.1f)),
elevation = null,
contentPadding =
if (buttonProperties.buttonType == ButtonType.TINY) {
PaddingValues(vertical = 2.4.dp, horizontal = 4.dp)
contentPadding = run {
// Determine default padding based on button type
val defaultPadding: PaddingValues = when (buttonProperties.buttonType) {
ButtonType.TINY -> PaddingValues(vertical = 2.4.dp, horizontal = 4.dp)
else -> PaddingValues(vertical = 4.8.dp, horizontal = 8.dp)
}

// Check if custom padding values are provided
val customPadding: PaddingValues? = if (
buttonProperties.contentPaddingHorizontal != null &&
buttonProperties.contentPaddingVertical != null
) {
PaddingValues(
vertical = buttonProperties.contentPaddingVertical!!.dp,
horizontal = buttonProperties.contentPaddingHorizontal!!.dp
)
} else {
PaddingValues(vertical = 4.8.dp, horizontal = 8.dp)
},
null
}

// Use custom padding if available; otherwise, fallback to default padding
customPadding ?: defaultPadding
},
shape = RoundedCornerShape(buttonProperties.borderRadius),
) {
// Each component here uses a new modifier to avoid inheriting the properties of the
Expand Down

0 comments on commit 62b94e3

Please sign in to comment.