-
Notifications
You must be signed in to change notification settings - Fork 5
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
14 changed files
with
511 additions
and
66 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
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
72 changes: 72 additions & 0 deletions
72
library-compose/src/main/java/com/spendesk/grapes/compose/textblock/GrapesTextBlock.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,72 @@ | ||
package com.spendesk.grapes.compose.textblock | ||
|
||
import androidx.compose.foundation.BorderStroke | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.spendesk.grapes.compose.textblock.actions.GrapesRetryTextBlockAction | ||
import com.spendesk.grapes.compose.theme.GrapesTheme | ||
|
||
/** | ||
* @author Kélian CLERC | ||
* @since 15/01/2024 | ||
*/ | ||
@Composable | ||
fun GrapesTextBlock( | ||
modifier: Modifier = Modifier, | ||
header: (@Composable () -> Unit)? = null, | ||
content: (@Composable () -> Unit)? = null, | ||
) { | ||
Column( | ||
modifier = modifier | ||
.background(GrapesTheme.colors.structureSurface, GrapesTheme.shapes.shape2) | ||
.border(BorderStroke(0.5.dp, GrapesTheme.colors.neutralLighter), GrapesTheme.shapes.shape2) | ||
) { | ||
header?.invoke() | ||
content?.invoke() | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun TextBlockPreview() { | ||
GrapesTheme { | ||
GrapesTextBlock( | ||
modifier = Modifier | ||
.padding(16.dp) | ||
.fillMaxWidth(), | ||
header = { | ||
GrapesTextBlockHeader( | ||
title = "Title which is very long and need to be truncated", | ||
informativeLabel = { | ||
GrapesTextBlockInformativeLabel( | ||
label = "• Missing", | ||
color = GrapesTheme.colors.warningDark, | ||
) | ||
}, | ||
action = { | ||
GrapesRetryTextBlockAction(retryLabel = "Retry", onRetryClicked = { /*TODO*/ }) | ||
}, | ||
modifier = Modifier | ||
.padding(horizontal = GrapesTheme.dimensions.spacing3) | ||
.padding(top = GrapesTheme.dimensions.spacing3) | ||
) | ||
}, | ||
content = { | ||
Text( | ||
text = "Content", | ||
style = GrapesTheme.typography.bodyM, | ||
color = GrapesTheme.colors.neutralDark, | ||
modifier = Modifier.padding(GrapesTheme.dimensions.spacing3) | ||
) | ||
}, | ||
) | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
library-compose/src/main/java/com/spendesk/grapes/compose/textblock/GrapesTextBlockHeader.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,103 @@ | ||
package com.spendesk.grapes.compose.textblock | ||
|
||
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.width | ||
import androidx.compose.foundation.layout.wrapContentWidth | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.tooling.preview.PreviewParameter | ||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider | ||
import com.spendesk.grapes.compose.textblock.actions.GrapesRetryTextBlockAction | ||
import com.spendesk.grapes.compose.theme.GrapesTheme | ||
|
||
/** | ||
* @author Kélian CLERC | ||
* @since 16/01/2024 | ||
*/ | ||
@Composable | ||
fun GrapesTextBlockHeader( | ||
title: String, | ||
modifier: Modifier = Modifier, | ||
informativeLabel: (@Composable () -> Unit)? = null, | ||
action: (@Composable () -> Unit)? = null, | ||
) { | ||
Row(modifier = modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) { | ||
HeaderText( | ||
title = title, | ||
modifier = Modifier | ||
.weight(1f), | ||
informativeLabel = informativeLabel | ||
) | ||
Spacer(modifier = Modifier.width(GrapesTheme.dimensions.spacing3)) | ||
action?.invoke() | ||
} | ||
} | ||
|
||
@Composable | ||
private fun HeaderText( | ||
title: String, | ||
modifier: Modifier = Modifier, | ||
informativeLabel: (@Composable () -> Unit)? = null, | ||
) { | ||
Row(modifier = modifier.wrapContentWidth(align = Alignment.Start), verticalAlignment = Alignment.CenterVertically) { | ||
Text( | ||
text = title, | ||
style = GrapesTheme.typography.titleS, | ||
color = GrapesTheme.colors.structureComplementary, | ||
maxLines = 1, | ||
overflow = TextOverflow.Ellipsis, | ||
modifier = Modifier.weight(1f, fill = false) | ||
) | ||
informativeLabel?.let { | ||
Spacer(modifier = Modifier.width(GrapesTheme.dimensions.spacing1)) | ||
informativeLabel.invoke() | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun TextBlockHeaderPreview( | ||
@PreviewParameter(TextBlockHeaderProvider::class) item: Triple<String, String?, String?>, | ||
) { | ||
val informativeLabel: (@Composable () -> Unit)? = item.second?.let { | ||
{ | ||
GrapesTextBlockInformativeLabel( | ||
label = "• $it", | ||
color = GrapesTheme.colors.warningDark, | ||
) | ||
} | ||
} | ||
val action: (@Composable () -> Unit)? = item.third?.let { | ||
{ | ||
GrapesRetryTextBlockAction(retryLabel = it, onRetryClicked = { /*TODO*/ }) | ||
} | ||
} | ||
|
||
GrapesTextBlockHeader(title = item.first, informativeLabel = informativeLabel, action = action, modifier = Modifier.padding(GrapesTheme.dimensions.spacing3)) | ||
} | ||
|
||
private class TextBlockHeaderProvider : PreviewParameterProvider<Triple<String, String?, String?>> { | ||
override val values = sequenceOf( | ||
Triple("Title", null, null), | ||
Triple("This is an example of a very long key very long key very long long very key", null, null), | ||
Triple("Title", "Short value", null), | ||
Triple("This is an example of a very long key very long key very long long very key", "Short value", null), | ||
Triple("Title", null, "Short action"), | ||
Triple("This is an example of a very long key very long key very long long very key", null, "Short action"), | ||
Triple("Title", "Short value", "Short action"), | ||
Triple("This is an example of a very long key", "Short value", "Short action"), | ||
Triple("This is an example of a very long key", "Short value", "Short action"), | ||
Triple("This is an example of a very long key", "Long value of a very long value", "Short action"), | ||
Triple("This is an example of a very long key", "Long value of a very long value", "Long action with a very long action"), | ||
Triple("Title", "Long value very long key very long key very long long very key", null), | ||
Triple("This is an example of a very long key very long key very long long very key", "Long value very long key very long key very long long very key", null), | ||
) | ||
} |
60 changes: 60 additions & 0 deletions
60
...se/src/main/java/com/spendesk/grapes/compose/textblock/GrapesTextBlockInformativeLabel.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,60 @@ | ||
package com.spendesk.grapes.compose.textblock | ||
|
||
/** | ||
* @author Kélian CLERC | ||
* @since 16/01/2024 | ||
*/ | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
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.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.spendesk.grapes.compose.theme.GrapesTheme | ||
|
||
@Composable | ||
fun GrapesTextBlockInformativeLabel( | ||
label: String, | ||
color: Color, | ||
modifier: Modifier = Modifier | ||
) { | ||
Row( | ||
modifier = modifier, | ||
horizontalArrangement = Arrangement.spacedBy(GrapesTheme.dimensions.spacing2), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
Spacer( | ||
modifier = Modifier | ||
.size(4.dp) | ||
.background(color, shape = GrapesTheme.shapes.shape4) | ||
) | ||
Text( | ||
text = label, | ||
style = GrapesTheme.typography.bodyM, | ||
color = color, | ||
maxLines = 1, | ||
) | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun TextBlockOptionalTitlePreview() { | ||
GrapesTheme { | ||
Column( | ||
modifier = Modifier.padding(GrapesTheme.dimensions.paddingLarge), | ||
verticalArrangement = Arrangement.spacedBy(GrapesTheme.dimensions.paddingLarge) | ||
) { | ||
GrapesTextBlockInformativeLabel("Missing", color = GrapesTheme.colors.warningNormal) | ||
GrapesTextBlockInformativeLabel("Optional", color = GrapesTheme.colors.neutralNormal) | ||
} | ||
} | ||
} |
Oops, something went wrong.