@@ -12,6 +12,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
12
12
import androidx.compose.runtime.*
13
13
import androidx.compose.ui.Alignment
14
14
import androidx.compose.ui.Modifier
15
+ import androidx.compose.ui.composed
15
16
import androidx.compose.ui.graphics.Brush
16
17
import androidx.compose.ui.graphics.Color
17
18
import androidx.compose.ui.graphics.SolidColor
@@ -44,9 +45,10 @@ fun Button(
44
45
disabled : Boolean = false,
45
46
buttonColors : ButtonColors = buttonColors(),
46
47
interaction : MutableInteractionSource = remember { MutableInteractionSource () },
48
+ iconOnly : Boolean = false,
47
49
content : @Composable RowScope .() -> Unit
48
50
) {
49
- Button (modifier, interaction, disabled, buttonColors, false , onClick, content)
51
+ Button (modifier, interaction, disabled, buttonColors, false , onClick, iconOnly, content)
50
52
}
51
53
52
54
@Composable
@@ -56,9 +58,10 @@ fun AccentButton(
56
58
disabled : Boolean = false,
57
59
buttonColors : ButtonColors = accentButtonColors(),
58
60
interaction : MutableInteractionSource = remember { MutableInteractionSource () },
61
+ iconOnly : Boolean = false,
59
62
content : @Composable RowScope .() -> Unit
60
63
) {
61
- Button (modifier, interaction, disabled, buttonColors, true , onClick, content)
64
+ Button (modifier, interaction, disabled, buttonColors, true , onClick, iconOnly, content)
62
65
}
63
66
64
67
@Composable
@@ -68,9 +71,10 @@ fun SubtleButton(
68
71
disabled : Boolean = false,
69
72
buttonColors : ButtonColors = subtleButtonColors(),
70
73
interaction : MutableInteractionSource = remember { MutableInteractionSource () },
74
+ iconOnly : Boolean = false,
71
75
content : @Composable RowScope .() -> Unit
72
76
) {
73
- Button (modifier, interaction, disabled, buttonColors, true , onClick, content)
77
+ Button (modifier, interaction, disabled, buttonColors, true , onClick, iconOnly, content)
74
78
}
75
79
76
80
@Composable
@@ -81,6 +85,7 @@ private fun Button(
81
85
buttonColors : ButtonColors ,
82
86
accentButton : Boolean ,
83
87
onClick : () -> Unit ,
88
+ iconOnly : Boolean ,
84
89
content : @Composable RowScope .() -> Unit
85
90
) {
86
91
val hovered by interaction.collectIsHoveredAsState()
@@ -104,10 +109,16 @@ private fun Button(
104
109
)
105
110
106
111
Layer (
107
- modifier = modifier.defaultMinSize(
108
- minWidth = 120 .dp,
109
- minHeight = 32 .dp
110
- ),
112
+ modifier = modifier.let {
113
+ if (iconOnly) {
114
+ it.defaultMinSize(32 .dp, 32 .dp)
115
+ } else {
116
+ it.defaultMinSize(
117
+ minWidth = 120 .dp,
118
+ minHeight = 32 .dp
119
+ )
120
+ }
121
+ },
111
122
shape = RoundedCornerShape (4 .dp),
112
123
border = BorderStroke (1 .dp, buttonColor.borderBrush),
113
124
color = fillColor,
@@ -122,7 +133,10 @@ private fun Button(
122
133
interactionSource = interaction,
123
134
indication = null
124
135
)
125
- .padding(horizontal = 12 .dp),
136
+ .composed {
137
+ if (! iconOnly) this
138
+ else padding(horizontal = 12 .dp)
139
+ },
126
140
horizontalArrangement = Arrangement .spacedBy(8 .dp, Alignment .CenterHorizontally ),
127
141
verticalAlignment = Alignment .CenterVertically ,
128
142
content = content
0 commit comments