-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
221 changes: 221 additions & 0 deletions
221
czan/src/commonMain/kotlin/com/tweener/czan/designsystem/atom/text/TrailingIconText.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,221 @@ | ||
package com.tweener.czan.designsystem.atom.text | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.LocalTextStyle | ||
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.vector.ImageVector | ||
import androidx.compose.ui.text.AnnotatedString | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import com.tweener.czan.designsystem.atom.icon.Icon | ||
import com.tweener.czan.theme.Size | ||
import org.jetbrains.compose.resources.DrawableResource | ||
|
||
/** | ||
* @author Vivien Mahe | ||
* @since 20/04/2024 | ||
*/ | ||
|
||
@Composable | ||
fun TrailingIconText( | ||
text: String, | ||
icon: DrawableResource, | ||
modifier: Modifier = Modifier, | ||
contentPadding: Dp = Size.Padding.Small, | ||
iconSize: Dp = 24.dp, | ||
iconTint: Color = Color.Unspecified, | ||
style: TextStyle = LocalTextStyle.current, | ||
color: Color = Color.Unspecified, | ||
fontStyle: FontStyle? = null, | ||
fontWeight: FontWeight? = null, | ||
textAlign: TextAlign? = null, | ||
overflow: TextOverflow = TextOverflow.Clip, | ||
lines: Int? = null, | ||
maxLines: Int = Int.MAX_VALUE, | ||
minLines: Int = 1, | ||
) { | ||
TrailingIconText( | ||
modifier = modifier, | ||
text = text, | ||
icon = { | ||
Icon( | ||
modifier = Modifier.size(iconSize), | ||
resource = icon, | ||
tint = iconTint, | ||
) | ||
}, | ||
contentPadding = contentPadding, | ||
style = style, | ||
color = color, | ||
fontStyle = fontStyle, | ||
fontWeight = fontWeight, | ||
textAlign = textAlign, | ||
overflow = overflow, | ||
lines = lines, | ||
maxLines = maxLines, | ||
minLines = minLines, | ||
) | ||
} | ||
|
||
@Composable | ||
fun TrailingIconText( | ||
text: String, | ||
icon: ImageVector, | ||
modifier: Modifier = Modifier, | ||
contentPadding: Dp = Size.Padding.Small, | ||
iconSize: Dp = 24.dp, | ||
iconTint: Color = Color.Unspecified, | ||
style: TextStyle = LocalTextStyle.current, | ||
color: Color = Color.Unspecified, | ||
fontStyle: FontStyle? = null, | ||
fontWeight: FontWeight? = null, | ||
textAlign: TextAlign? = null, | ||
overflow: TextOverflow = TextOverflow.Clip, | ||
lines: Int? = null, | ||
maxLines: Int = Int.MAX_VALUE, | ||
minLines: Int = 1, | ||
) { | ||
TrailingIconText( | ||
modifier = modifier, | ||
text = text, | ||
icon = { | ||
Icon( | ||
modifier = Modifier.size(iconSize), | ||
imageVector = icon, | ||
tint = iconTint, | ||
) | ||
}, | ||
contentPadding = contentPadding, | ||
style = style, | ||
color = color, | ||
fontStyle = fontStyle, | ||
fontWeight = fontWeight, | ||
textAlign = textAlign, | ||
overflow = overflow, | ||
lines = lines, | ||
maxLines = maxLines, | ||
minLines = minLines, | ||
) | ||
} | ||
|
||
@Composable | ||
fun TrailingIconText( | ||
text: AnnotatedString, | ||
icon: DrawableResource, | ||
modifier: Modifier = Modifier, | ||
contentPadding: Dp = Size.Padding.Small, | ||
iconSize: Dp = 24.dp, | ||
iconTint: Color = Color.Unspecified, | ||
style: TextStyle = LocalTextStyle.current, | ||
color: Color = Color.Unspecified, | ||
fontStyle: FontStyle? = null, | ||
fontWeight: FontWeight? = null, | ||
textAlign: TextAlign? = null, | ||
overflow: TextOverflow = TextOverflow.Clip, | ||
lines: Int? = null, | ||
maxLines: Int = Int.MAX_VALUE, | ||
minLines: Int = 1, | ||
) { | ||
TrailingIconText( | ||
modifier = modifier, | ||
text = text, | ||
icon = { | ||
Icon( | ||
modifier = Modifier.size(iconSize), | ||
resource = icon, | ||
tint = iconTint, | ||
) | ||
}, | ||
contentPadding = contentPadding, | ||
style = style, | ||
color = color, | ||
fontStyle = fontStyle, | ||
fontWeight = fontWeight, | ||
textAlign = textAlign, | ||
overflow = overflow, | ||
lines = lines, | ||
maxLines = maxLines, | ||
minLines = minLines, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun TrailingIconText( | ||
text: String, | ||
icon: @Composable () -> Unit, | ||
modifier: Modifier = Modifier, | ||
contentPadding: Dp = Size.Padding.Small, | ||
style: TextStyle = LocalTextStyle.current, | ||
color: Color = Color.Unspecified, | ||
fontStyle: FontStyle? = null, | ||
fontWeight: FontWeight? = null, | ||
textAlign: TextAlign? = null, | ||
overflow: TextOverflow = TextOverflow.Clip, | ||
lines: Int? = null, | ||
maxLines: Int = Int.MAX_VALUE, | ||
minLines: Int = 1, | ||
) { | ||
TrailingIconText( | ||
modifier = modifier, | ||
text = AnnotatedString(text), | ||
icon = icon, | ||
contentPadding = contentPadding, | ||
style = style, | ||
color = color, | ||
fontStyle = fontStyle, | ||
fontWeight = fontWeight, | ||
textAlign = textAlign, | ||
overflow = overflow, | ||
lines = lines, | ||
maxLines = maxLines, | ||
minLines = minLines, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun TrailingIconText( | ||
text: AnnotatedString, | ||
icon: @Composable () -> Unit, | ||
modifier: Modifier = Modifier, | ||
contentPadding: Dp = Size.Padding.Small, | ||
style: TextStyle = LocalTextStyle.current, | ||
color: Color = Color.Unspecified, | ||
fontStyle: FontStyle? = null, | ||
fontWeight: FontWeight? = null, | ||
textAlign: TextAlign? = null, | ||
overflow: TextOverflow = TextOverflow.Clip, | ||
lines: Int? = null, | ||
maxLines: Int = Int.MAX_VALUE, | ||
minLines: Int = 1, | ||
) { | ||
Row( | ||
modifier = modifier, | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.spacedBy(contentPadding), | ||
) { | ||
Text( | ||
text = text, | ||
color = color, | ||
style = style, | ||
fontStyle = fontStyle, | ||
fontWeight = fontWeight, | ||
textAlign = textAlign, | ||
overflow = overflow, | ||
lines = lines, | ||
maxLines = maxLines, | ||
minLines = minLines, | ||
) | ||
|
||
icon() | ||
} | ||
} |
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