-
Notifications
You must be signed in to change notification settings - Fork 5
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
Create menu bottom sheet components #307
Merged
RomainGF
merged 5 commits into
develop
from
task/AA-3165-create-menu-bottom-sheet-component
Dec 1, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
160 changes: 160 additions & 0 deletions
160
library-compose/src/main/java/com/spendesk/grapes/compose/actionmenu/ActionMenuItem.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,160 @@ | ||
package com.spendesk.grapes.compose.actionmenu | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.layout.sizeIn | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.ButtonDefaults | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.LocalContentColor | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.spendesk.grapes.compose.R | ||
import com.spendesk.grapes.compose.theme.GrapesTheme | ||
|
||
/** | ||
* @author : RomainGF | ||
* @since : 09/10/2023 | ||
**/ | ||
private val iconMaxSize = 16.dp | ||
private val verticalInnerPadding = 20.dp | ||
private const val ACTION_TEXT_MAX_LINES = 2 | ||
|
||
/** | ||
* ActionMenuItem is a button with an icon and a text. | ||
* | ||
* @param text Text to display on the button | ||
* @param icon Slot for the icon to display on the left of the text. Size is constrained to 16dp. | ||
* @param onClick Callback when the button is clicked | ||
* @param modifier Modifier | ||
* @param enabled Whether the button is enabled or not | ||
*/ | ||
@Composable | ||
fun ActionMenuItem( | ||
text: String, | ||
icon: @Composable () -> Unit, | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
enabled: Boolean = true, | ||
) { | ||
Button( | ||
onClick = onClick, | ||
enabled = enabled, | ||
colors = ButtonDefaults.buttonColors( | ||
containerColor = GrapesTheme.colors.neutralLightest, | ||
contentColor = GrapesTheme.colors.primaryNormal, | ||
disabledContainerColor = GrapesTheme.colors.neutralLightest, | ||
disabledContentColor = GrapesTheme.colors.neutralNormal, | ||
), | ||
contentPadding = PaddingValues( | ||
start = GrapesTheme.dimensions.paddingXLarge, | ||
end = GrapesTheme.dimensions.paddingLarge, | ||
top = verticalInnerPadding, | ||
bottom = verticalInnerPadding, | ||
), | ||
shape = GrapesTheme.shapes.small, | ||
modifier = modifier, | ||
) { | ||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
ActionMenuItemIcon( | ||
enabled = enabled, | ||
icon = icon, | ||
) | ||
Spacer(Modifier.width(GrapesTheme.dimensions.paddingXLarge)) | ||
Text( | ||
text = text, | ||
maxLines = ACTION_TEXT_MAX_LINES, | ||
overflow = TextOverflow.Ellipsis, | ||
style = GrapesTheme.typography.titleS, | ||
modifier = Modifier.weight(1f), | ||
) | ||
if (enabled) { | ||
Spacer(Modifier.width(GrapesTheme.dimensions.paddingLarge)) | ||
Icon( | ||
painter = painterResource(R.drawable.ic_chevron_right), | ||
contentDescription = null, | ||
tint = GrapesTheme.colors.primaryLighter, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ActionMenuItemIcon( | ||
enabled: Boolean, | ||
icon: @Composable () -> Unit, | ||
) { | ||
Box( | ||
modifier = Modifier.sizeIn( | ||
maxWidth = iconMaxSize, | ||
maxHeight = iconMaxSize, | ||
), | ||
) { | ||
val iconContentColor = if (enabled) { | ||
GrapesTheme.colors.primaryNormal | ||
} else { | ||
GrapesTheme.colors.neutralNormal | ||
} | ||
CompositionLocalProvider(LocalContentColor provides iconContentColor) { | ||
icon() | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Preview(fontScale = 2f) | ||
@Composable | ||
private fun ActionMenuItemPreview() { | ||
GrapesTheme { | ||
val icon = @Composable { | ||
Icon( | ||
painter = painterResource(R.drawable.ic_neutral), | ||
contentDescription = null, | ||
modifier = Modifier.size(48.dp) | ||
) | ||
} | ||
val text = "Action" | ||
val longText = "Action with a very long title which will not fit in one line. Event two lines will not be enough" | ||
val modifier = Modifier.fillMaxWidth() | ||
Column( | ||
verticalArrangement = Arrangement.spacedBy(8.dp) | ||
) { | ||
ActionMenuItem( | ||
text = text, | ||
icon = icon, | ||
onClick = {}, | ||
modifier = modifier, | ||
) | ||
ActionMenuItem( | ||
text = longText, | ||
icon = icon, | ||
onClick = {}, | ||
modifier = modifier, | ||
) | ||
ActionMenuItem( | ||
text = text, | ||
icon = icon, | ||
onClick = {}, | ||
enabled = false, | ||
modifier = modifier, | ||
) | ||
} | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
library-compose/src/main/java/com/spendesk/grapes/compose/actionmenu/ActionMenuSection.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,137 @@ | ||
package com.spendesk.grapes.compose.actionmenu | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.ColumnScope | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.sizeIn | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.CardDefaults | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.spendesk.grapes.compose.R | ||
import com.spendesk.grapes.compose.theme.GrapesTheme | ||
|
||
/** | ||
* @author : RomainGF | ||
* @since : 09/10/2023 | ||
**/ | ||
|
||
private val iconMaxSize = 56.dp | ||
private val sectionShape = RoundedCornerShape(16.dp) | ||
private const val TITLE_MAX_LINES = 2 | ||
private const val DESCRIPTION_MAX_LINES = 3 | ||
|
||
@Composable | ||
fun ActionMenuSection( | ||
title: String, | ||
description: String, | ||
illustration: @Composable () -> Unit, | ||
modifier: Modifier = Modifier, | ||
content: @Composable ColumnScope.() -> Unit, | ||
) { | ||
Card( | ||
modifier = modifier, | ||
colors = CardDefaults.cardColors( | ||
containerColor = GrapesTheme.colors.structureSurface, | ||
), | ||
shape = sectionShape, | ||
) { | ||
Column( | ||
verticalArrangement = Arrangement.spacedBy(GrapesTheme.dimensions.paddingSmall), | ||
modifier = Modifier.padding(GrapesTheme.dimensions.paddingSmall), | ||
) { | ||
ActionMenuSectionHeader( | ||
title = title, | ||
description = description, | ||
illustration = illustration, | ||
) | ||
content() | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ActionMenuSectionHeader( | ||
title: String, | ||
description: String, | ||
illustration: @Composable () -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Row( | ||
horizontalArrangement = Arrangement.spacedBy(GrapesTheme.dimensions.paddingSmall), | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = modifier, | ||
) { | ||
Box( | ||
content = { illustration() }, | ||
contentAlignment = Alignment.Center, | ||
modifier = Modifier.sizeIn( | ||
maxWidth = iconMaxSize, | ||
maxHeight = iconMaxSize, | ||
), | ||
) | ||
Column( | ||
verticalArrangement = Arrangement.spacedBy(GrapesTheme.dimensions.paddingXSmall), | ||
modifier = Modifier.padding( | ||
bottom = GrapesTheme.dimensions.paddingSmall, | ||
top = GrapesTheme.dimensions.paddingSmall, | ||
end = GrapesTheme.dimensions.paddingSmall, | ||
) | ||
) { | ||
Text( | ||
text = title, | ||
style = GrapesTheme.typography.titleM, | ||
color = GrapesTheme.colors.structureComplementary, | ||
maxLines = TITLE_MAX_LINES, | ||
overflow = TextOverflow.Ellipsis, | ||
) | ||
Text( | ||
text = description, | ||
style = GrapesTheme.typography.bodyS, | ||
color = GrapesTheme.colors.neutralDark, | ||
maxLines = DESCRIPTION_MAX_LINES, | ||
overflow = TextOverflow.Ellipsis, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Preview(fontScale = 2f) | ||
@Composable | ||
private fun ActionMenuSectionPreview() { | ||
GrapesTheme { | ||
ActionMenuSection( | ||
title = "Make a purchase request", | ||
description = "Order a virtual card to directly use company money online", | ||
illustration = { | ||
Icon(painterResource(R.drawable.ic_neutral), null, Modifier.fillMaxSize()) | ||
}, | ||
modifier = Modifier.fillMaxWidth(), | ||
) { | ||
ActionMenuItem( | ||
text = "Ask for a virtual card", | ||
icon = { Icon(painterResource(R.drawable.ic_neutral), null) }, | ||
onClick = {}, | ||
) | ||
ActionMenuItem( | ||
text = "Ask for a virtual card", | ||
icon = { Icon(painterResource(R.drawable.ic_neutral), null) }, | ||
onClick = {}, | ||
) | ||
} | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
library-compose/src/main/res/drawable/ic_chevron_right.xml
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,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="16dp" | ||
android:height="16dp" | ||
android:viewportWidth="16" | ||
android:viewportHeight="16"> | ||
<path | ||
android:fillColor="#000000" | ||
android:fillType="evenOdd" | ||
android:pathData="M8.645,8L5,4.373L6.379,3L10.714,7.314C11.095,7.693 11.095,8.307 10.714,8.686L6.379,13L5,11.627L8.645,8Z" /> | ||
</vector> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the alignment of the content be specified ?
It might be a dump comment. You only define a maxSize, so I guess that while the contnet is smaller, the box will just wrap it.
And if it's too big, it will be cropped so ne need to specify in which direction it will be cropped, it just shouldn't happen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes should specify it if the content is smaller, even if there's no min size let's play it safe