Skip to content

Commit

Permalink
Add new composable TrailingIconText
Browse files Browse the repository at this point in the history
  • Loading branch information
Tweener committed Sep 23, 2024
1 parent 8194ea3 commit 6b8bdfa
Show file tree
Hide file tree
Showing 2 changed files with 224 additions and 0 deletions.
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.tweener.czan._internal.kotlinextensions.clickableRipple
import com.tweener.czan._internal.kotlinextensions.conditional
import com.tweener.czan.theme.Size

Expand All @@ -35,6 +36,7 @@ fun Card(
borderStrokeWidth: Dp = CardDefaults.borderStrokeWidth,
contentPadding: Dp = Size.Padding.Default,
showDividers: Boolean = true,
onClick: (() -> Unit)? = null,
header: @Composable (() -> Unit)? = null,
footer: @Composable (() -> Unit)? = null,
content: @Composable () -> Unit,
Expand All @@ -59,6 +61,7 @@ fun Card(
ifTrue = { background(colors.containerBrush()!!) },
ifFalse = { background(colors.containerColor()) },
)
.clickableRipple(enabled = onClick != null) { onClick?.invoke() }
.padding(vertical = contentPadding),
) {
// Header, if provided
Expand Down

0 comments on commit 6b8bdfa

Please sign in to comment.