-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centralize commonly reused label/icon pair component
- Loading branch information
Showing
7 changed files
with
142 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/component/LabeledIcon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.materiiapps.gloom.ui.component | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.LocalContentColor | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.graphics.vector.rememberVectorPainter | ||
import androidx.compose.ui.unit.dp | ||
|
||
/** | ||
* Simple icon and label pair | ||
* | ||
* @param icon The icon to show with the label | ||
* @param label Label to display | ||
* @param modifier The [Modifier] for this [LabeledIcon] | ||
* @param iconTint The color to use for the [icon] | ||
* @param labelColor The color to use for the [label] text | ||
*/ | ||
@Composable | ||
fun LabeledIcon( | ||
icon: Painter, | ||
label: String, | ||
modifier: Modifier = Modifier, | ||
iconTint: Color = LocalContentColor.current, | ||
labelColor: Color = LocalContentColor.current.copy(alpha = 0.6f) | ||
) { | ||
Row( | ||
horizontalArrangement = Arrangement.spacedBy(6.dp), | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = modifier | ||
) { | ||
Icon( | ||
painter = icon, | ||
contentDescription = null, | ||
modifier = Modifier.size(18.dp), | ||
tint = iconTint | ||
) | ||
|
||
Text( | ||
text = label, | ||
style = MaterialTheme.typography.labelLarge, | ||
color = labelColor | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Simple icon and label pair | ||
* | ||
* @param icon The icon to show with the label | ||
* @param label Label to display | ||
* @param modifier The [Modifier] for this [LabeledIcon] | ||
* @param iconTint The color to use for the [icon] | ||
* @param labelColor The color to use for the [label] text | ||
*/ | ||
@Composable | ||
fun LabeledIcon( | ||
icon: ImageVector, | ||
label: String, | ||
modifier: Modifier = Modifier, | ||
iconTint: Color = LocalContentColor.current, | ||
labelColor: Color = LocalContentColor.current.copy(alpha = 0.6f) | ||
) { | ||
LabeledIcon( | ||
icon = rememberVectorPainter(icon), | ||
label = label, | ||
modifier = modifier, | ||
iconTint = iconTint, | ||
labelColor = labelColor | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.