Skip to content

Commit bfe6827

Browse files
committed
[Items] - Add GrapesStackItem
1 parent c14741d commit bfe6827

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.spendesk.grapes.compose.listitem
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.clickable
5+
import androidx.compose.foundation.layout.Arrangement
6+
import androidx.compose.foundation.layout.Column
7+
import androidx.compose.foundation.layout.Row
8+
import androidx.compose.foundation.layout.Spacer
9+
import androidx.compose.foundation.layout.padding
10+
import androidx.compose.foundation.layout.size
11+
import androidx.compose.material3.Icon
12+
import androidx.compose.material3.Text
13+
import androidx.compose.runtime.Composable
14+
import androidx.compose.runtime.Immutable
15+
import androidx.compose.ui.Alignment
16+
import androidx.compose.ui.Modifier
17+
import androidx.compose.ui.draw.clip
18+
import androidx.compose.ui.graphics.Color
19+
import androidx.compose.ui.res.painterResource
20+
import androidx.compose.ui.semantics.Role
21+
import androidx.compose.ui.text.style.TextOverflow
22+
import androidx.compose.ui.tooling.preview.Preview
23+
import com.spendesk.grapes.compose.R
24+
import com.spendesk.grapes.compose.logo.GrapesStackLogo
25+
import com.spendesk.grapes.compose.theme.GrapesTheme
26+
27+
/**
28+
* @author : dany
29+
* @since : 30/01/2024, Tue
30+
**/
31+
32+
@Immutable
33+
data class GrapesStackItemColors internal constructor(
34+
val titleColor: Color,
35+
val descriptionColor: Color,
36+
val backgroundColor: Color
37+
)
38+
39+
object GrapesStackItemDefaults {
40+
41+
@Composable
42+
fun colors(
43+
titleColor: Color = GrapesTheme.colors.neutralDarker,
44+
descriptionColor: Color = GrapesTheme.colors.neutralDarker,
45+
backgroundColor: Color = GrapesTheme.colors.neutralLightest
46+
): GrapesStackItemColors = GrapesStackItemColors(
47+
titleColor = titleColor,
48+
descriptionColor = descriptionColor,
49+
backgroundColor = backgroundColor
50+
)
51+
}
52+
53+
@Composable
54+
fun GrapesStackItem(
55+
title: String,
56+
description: String,
57+
itemsNumber: Int,
58+
modifier: Modifier = Modifier,
59+
onClick: (() -> Unit)? = null,
60+
colors: GrapesStackItemColors = GrapesStackItemDefaults.colors()
61+
) {
62+
val clickableModifier = if (onClick != null) {
63+
Modifier.clickable(role = Role.Button, onClick = onClick)
64+
} else {
65+
Modifier
66+
}
67+
68+
Row(
69+
horizontalArrangement = Arrangement.spacedBy(GrapesTheme.dimensions.spacing3),
70+
verticalAlignment = Alignment.CenterVertically,
71+
modifier = modifier
72+
.clip(GrapesTheme.shapes.shape2)
73+
.then(clickableModifier)
74+
.background(colors.backgroundColor)
75+
.padding(
76+
vertical = GrapesTheme.dimensions.spacing3,
77+
horizontal = GrapesTheme.dimensions.spacing2,
78+
),
79+
) {
80+
GrapesStackLogo(numberOfStack = itemsNumber)
81+
Row(modifier = Modifier.weight(1f)) {
82+
Column {
83+
Text(
84+
text = title,
85+
style = GrapesTheme.typography.titleM,
86+
color = colors.titleColor,
87+
overflow = TextOverflow.Ellipsis,
88+
maxLines = 1,
89+
)
90+
Text(
91+
text = description,
92+
style = GrapesTheme.typography.bodyS,
93+
color = colors.descriptionColor,
94+
maxLines = 1,
95+
)
96+
}
97+
}
98+
Row {
99+
Icon(
100+
painter = painterResource(R.drawable.ic_chevron_right),
101+
contentDescription = null,
102+
tint = GrapesTheme.colors.neutralLight,
103+
)
104+
}
105+
}
106+
}
107+
108+
@Composable
109+
@Preview(showBackground = true)
110+
private fun GrapesStackItemPreview() {
111+
GrapesTheme {
112+
Column(modifier = Modifier.background(Color.White), verticalArrangement = Arrangement.spacedBy(GrapesTheme.dimensions.spacing1)) {
113+
Spacer(modifier = Modifier.size(GrapesTheme.dimensions.sizing2))
114+
GrapesStackItem(
115+
title = "Awaiting Reimbursement",
116+
description = "Total: 1000€",
117+
itemsNumber = 2,
118+
onClick = {}
119+
)
120+
Spacer(modifier = Modifier.size(GrapesTheme.dimensions.sizing2))
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)