Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/aa 3953 prepare information card for clickable icon #385

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
package com.spendesk.grapes.compose.card

import androidx.annotation.DrawableRes
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Card
import androidx.compose.material3.CardColors
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.ripple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
Expand All @@ -33,6 +45,79 @@ fun GrapesInformationCard(
border: BorderStroke = GrapesInformationCardDefaults.border,
contentVerticalArrangement: Arrangement.Vertical = GrapesInformationCardDefaults.contentVerticalArrangement,
content: @Composable ColumnScope.() -> Unit = {},
) {
InformationCard(
header = {
Text(
text = title,
style = GrapesTheme.typography.titleM,
modifier = Modifier.padding(horizontal = GrapesTheme.dimensions.spacing3),
)
},
modifier = modifier,
colors = colors,
border = border,
contentVerticalArrangement = contentVerticalArrangement,
content = content,
)
}

@Composable
fun GrapesInformationCard(
title: String,
@DrawableRes headerIcon: Int,
onHeaderIconClicked: () -> Unit,
modifier: Modifier = Modifier,
iconColor: Color = GrapesInformationCardDefaults.iconColor,
colors: CardColors = GrapesInformationCardDefaults.colors,
border: BorderStroke = GrapesInformationCardDefaults.border,
contentVerticalArrangement: Arrangement.Vertical = GrapesInformationCardDefaults.contentVerticalArrangement,
content: @Composable ColumnScope.() -> Unit = {},
) {
InformationCard(
header = {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = GrapesTheme.dimensions.spacing3),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = title,
style = GrapesTheme.typography.titleM,
modifier = Modifier.weight(1f),
)
Spacer(modifier = Modifier.size(GrapesTheme.dimensions.spacing3))
Icon(
painter = painterResource(id = headerIcon),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be an IconButton if clickable, and it must be at least 48.dp width&height for accessibility (might be handled by the IconButton composable)

Copy link
Collaborator Author

@kelianClerc kelianClerc Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true

contentDescription = null,
tint = iconColor,
modifier = Modifier
.size(GrapesTheme.dimensions.sizing2)
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = ripple(bounded = false),
onClick = onHeaderIconClicked
)
)
}
},
modifier = modifier,
colors = colors,
border = border,
contentVerticalArrangement = contentVerticalArrangement,
content = content,
)
}

@Composable
private fun InformationCard(
header: @Composable () -> Unit,
content: @Composable ColumnScope.() -> Unit,
modifier: Modifier = Modifier,
colors: CardColors = GrapesInformationCardDefaults.colors,
border: BorderStroke = GrapesInformationCardDefaults.border,
contentVerticalArrangement: Arrangement.Vertical = GrapesInformationCardDefaults.contentVerticalArrangement,
) {
Card(
modifier = modifier,
Expand All @@ -43,11 +128,7 @@ fun GrapesInformationCard(
verticalArrangement = Arrangement.spacedBy(GrapesTheme.dimensions.spacing3),
modifier = Modifier.padding(vertical = GrapesTheme.dimensions.spacing3),
) {
Text(
text = title,
style = GrapesTheme.typography.titleM,
modifier = Modifier.padding(horizontal = GrapesTheme.dimensions.spacing3),
)
header()
GrapesDivider()
Column(
verticalArrangement = contentVerticalArrangement,
Expand All @@ -67,6 +148,9 @@ object GrapesInformationCardDefaults {
containerColor = GrapesTheme.colors.mainWhite,
)

val iconColor: Color
@Composable get() = GrapesTheme.colors.structureComplementary

val border: BorderStroke
@Composable get() = BorderStroke(
width = borderThickness,
Expand Down Expand Up @@ -98,6 +182,29 @@ private fun PreviewDescription(
}
}

@Preview
@Composable
private fun PreviewWithIconDescription(
@PreviewParameter(DescriptionParameterProvider::class) texts: Pair<String, String>,
) {
GrapesTheme {
Surface(
color = GrapesTheme.colors.structureBackground,
) {
GrapesInformationCard(
title = texts.first,
headerIcon = android.R.drawable.ic_delete,
onHeaderIconClicked = {},
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
) {
Text(texts.second)
}
}
}
}

private class DescriptionParameterProvider : PreviewParameterProvider<Pair<String, String>> {

override val values = sequenceOf(
Expand Down
Loading