Skip to content

Commit 7790a5c

Browse files
committed
Add iconOnly property to buttons. Change default Icon size to 16dp.
1 parent 4ccc64c commit 7790a5c

File tree

4 files changed

+38
-15
lines changed
  • example/src/jvmMain/kotlin/com/konyaco/fluent/example
  • fluent-icons-core/src/jvmMain/kotlin/com/konyaco/fluent/icons
  • fluent/src/jvmMain/kotlin/com/konyaco/fluent/component

4 files changed

+38
-15
lines changed

example/src/jvmMain/kotlin/com/konyaco/fluent/example/Main.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,26 @@ private fun Buttons() {
206206
Button(onClick) { Text(text) }
207207

208208
AccentButton(onClick) {
209-
Icon(
210-
modifier = Modifier.size(16.dp),
211-
imageVector = Icons.Default.Checkmark,
212-
contentDescription = null
213-
)
209+
Icon(Icons.Default.Checkmark, contentDescription = null)
214210
Text(text)
215211
}
216212

217213
SubtleButton(onClick) {
218214
Text("Text Button")
219215
}
216+
217+
218+
}
219+
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
220+
AccentButton({}, iconOnly = true) {
221+
Icon(Icons.Default.Navigation, contentDescription = null)
222+
}
223+
Button({}, iconOnly = true) {
224+
Icon(Icons.Default.Navigation, contentDescription = null)
225+
}
226+
SubtleButton({}, iconOnly = true) {
227+
Icon(Icons.Default.Navigation, contentDescription = null)
228+
}
220229
}
221230
}
222231

fluent-icons-core/src/jvmMain/kotlin/com/konyaco/fluent/icons/Icons.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ inline fun ImageVector.Builder.fluentPath(
5959

6060
// All Fluent icons (currently) are 12dp by 12dp, with a viewport size of 12 by 12.
6161
@PublishedApi
62-
internal const val FluentIconDimension = 12f
62+
internal const val FluentIconDimension = 16f

fluent/src/jvmMain/kotlin/com/konyaco/fluent/component/Button.kt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
1212
import androidx.compose.runtime.*
1313
import androidx.compose.ui.Alignment
1414
import androidx.compose.ui.Modifier
15+
import androidx.compose.ui.composed
1516
import androidx.compose.ui.graphics.Brush
1617
import androidx.compose.ui.graphics.Color
1718
import androidx.compose.ui.graphics.SolidColor
@@ -44,9 +45,10 @@ fun Button(
4445
disabled: Boolean = false,
4546
buttonColors: ButtonColors = buttonColors(),
4647
interaction: MutableInteractionSource = remember { MutableInteractionSource() },
48+
iconOnly: Boolean = false,
4749
content: @Composable RowScope.() -> Unit
4850
) {
49-
Button(modifier, interaction, disabled, buttonColors, false, onClick, content)
51+
Button(modifier, interaction, disabled, buttonColors, false, onClick, iconOnly, content)
5052
}
5153

5254
@Composable
@@ -56,9 +58,10 @@ fun AccentButton(
5658
disabled: Boolean = false,
5759
buttonColors: ButtonColors = accentButtonColors(),
5860
interaction: MutableInteractionSource = remember { MutableInteractionSource() },
61+
iconOnly: Boolean = false,
5962
content: @Composable RowScope.() -> Unit
6063
) {
61-
Button(modifier, interaction, disabled, buttonColors, true, onClick, content)
64+
Button(modifier, interaction, disabled, buttonColors, true, onClick, iconOnly, content)
6265
}
6366

6467
@Composable
@@ -68,9 +71,10 @@ fun SubtleButton(
6871
disabled: Boolean = false,
6972
buttonColors: ButtonColors = subtleButtonColors(),
7073
interaction: MutableInteractionSource = remember { MutableInteractionSource() },
74+
iconOnly: Boolean = false,
7175
content: @Composable RowScope.() -> Unit
7276
) {
73-
Button(modifier, interaction, disabled, buttonColors, true, onClick, content)
77+
Button(modifier, interaction, disabled, buttonColors, true, onClick, iconOnly, content)
7478
}
7579

7680
@Composable
@@ -81,6 +85,7 @@ private fun Button(
8185
buttonColors: ButtonColors,
8286
accentButton: Boolean,
8387
onClick: () -> Unit,
88+
iconOnly: Boolean,
8489
content: @Composable RowScope.() -> Unit
8590
) {
8691
val hovered by interaction.collectIsHoveredAsState()
@@ -104,10 +109,16 @@ private fun Button(
104109
)
105110

106111
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+
},
111122
shape = RoundedCornerShape(4.dp),
112123
border = BorderStroke(1.dp, buttonColor.borderBrush),
113124
color = fillColor,
@@ -122,7 +133,10 @@ private fun Button(
122133
interactionSource = interaction,
123134
indication = null
124135
)
125-
.padding(horizontal = 12.dp),
136+
.composed {
137+
if (!iconOnly) this
138+
else padding(horizontal = 12.dp)
139+
},
126140
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterHorizontally),
127141
verticalAlignment = Alignment.CenterVertically,
128142
content = content

fluent/src/jvmMain/kotlin/com/konyaco/fluent/component/Icon.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ private fun Modifier.defaultSizeFor(painter: Painter) =
8989
private fun Size.isInfinite() = width.isInfinite() && height.isInfinite()
9090

9191
// Default icon size, for icons with no intrinsic size information
92-
private val DefaultIconSizeModifier = Modifier.size(12.dp)
92+
private val DefaultIconSizeModifier = Modifier.size(16.dp)

0 commit comments

Comments
 (0)