-
-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/mobile button #766
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
Merged
Merged
Feat/mobile button #766
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c13b966
fix(theme): elevations for semitransparent background
comfrt1k 38dbfe2
feat(button): expand button states
comfrt1k e9c60a1
feat(button): appearances update
comfrt1k 8190aad
feat(button): shapes update
comfrt1k f0d09ba
refactor(button): layout
comfrt1k f4042aa
feat(button): update stories
comfrt1k c6677f5
fix(theme): let gradient background passing in elevation
comfrt1k cf51342
refactor(theme): remove legacy button colors
comfrt1k d6a7bcd
chore(common): update stories using button
comfrt1k 74a48be
chore(common): remove unused spacing
comfrt1k 5e9fb73
fix(button): align content by width
comfrt1k dddff76
test(button): add layout controls to story
comfrt1k 756c6ba
fix(button): reserve space around centered content
comfrt1k dd88d34
Merge branch 'master' into feat/mobile-button
comfrt1k cb68e74
fix(button): center content vertically
comfrt1k 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
This file contains hidden or 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
71 changes: 71 additions & 0 deletions
71
mobile/kmp/ui/src/commonMain/kotlin/com/atls/hyperion/ui/components/button/Container.kt
This file contains hidden or 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,71 @@ | ||
| package com.atls.hyperion.ui.components.button | ||
|
|
||
| import androidx.compose.foundation.BorderStroke | ||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.interaction.MutableInteractionSource | ||
| import androidx.compose.foundation.layout.heightIn | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.material.LocalContentAlpha | ||
| import androidx.compose.material.LocalContentColor | ||
| import androidx.compose.material.Surface | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.CompositionLocalProvider | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.semantics.Role | ||
| import com.atls.hyperion.ui.components.button.styles.appearance.Colors | ||
| import com.atls.hyperion.ui.components.button.styles.shape.ButtonShape | ||
| import com.atls.hyperion.ui.primitives.elevation | ||
| import com.atls.hyperion.ui.theme.tokens.elevation.Elevation | ||
|
|
||
| @Composable | ||
| internal fun ButtonContainer( | ||
| modifier: Modifier, | ||
| enabled: Boolean, | ||
| interactionSource: MutableInteractionSource, | ||
| colors: Colors, | ||
| elevation: Elevation, | ||
| shape: ButtonShape, | ||
| onClick: () -> Unit, | ||
| content: @Composable () -> Unit | ||
| ) { | ||
| val buttonShape = RoundedCornerShape(shape.cornerRadius) | ||
| val containerModifier = when (colors) { | ||
| is Colors.Solid -> modifier | ||
| .heightIn(min = shape.minHeight) | ||
| .elevation( | ||
| elevation = elevation, | ||
| backgroundColor = colors.background, | ||
| shape = buttonShape | ||
| ) | ||
|
|
||
| is Colors.Gradient -> modifier | ||
| .heightIn(min = shape.minHeight) | ||
| .elevation( | ||
| elevation = elevation, | ||
| backgroundBrush = colors.background, | ||
| shape = buttonShape, | ||
| backgroundAlpha = colors.backgroundAlpha | ||
| ) | ||
| } | ||
|
|
||
| Surface( | ||
| shape = buttonShape, | ||
| color = Color.Transparent, | ||
| contentColor = colors.content, | ||
| border = BorderStroke(shape.borderWidth, colors.border), | ||
| modifier = containerModifier.clickable( | ||
| interactionSource = interactionSource, | ||
| indication = null, | ||
| enabled = enabled, | ||
| role = Role.Button, | ||
| onClick = onClick | ||
| ) | ||
| ) { | ||
| CompositionLocalProvider( | ||
| LocalContentColor provides colors.content, | ||
| LocalContentAlpha provides 1f, | ||
| content = content | ||
| ) | ||
| } | ||
| } |
108 changes: 108 additions & 0 deletions
108
mobile/kmp/ui/src/commonMain/kotlin/com/atls/hyperion/ui/components/button/Content.kt
This file contains hidden or 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,108 @@ | ||
| package com.atls.hyperion.ui.components.button | ||
|
|
||
| import androidx.compose.foundation.layout.* | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.unit.Dp | ||
| import com.atls.hyperion.ui.components.button.styles.shape.ButtonShape | ||
| import com.atls.hyperion.ui.shared.addon.Addon | ||
| import com.atls.hyperion.ui.shared.addon.AddonPosition | ||
| import com.atls.hyperion.ui.shared.addon.AddonSlotManager | ||
|
|
||
| @Composable | ||
| internal fun ButtonContent( | ||
| addons: AddonSlotManager, | ||
| shape: ButtonShape, | ||
| content: @Composable () -> Unit | ||
| ) { | ||
| val beforeAddons = addons.get(AddonPosition.Before) | ||
| val afterAddons = addons.get(AddonPosition.After) | ||
|
|
||
| BoxWithConstraints( | ||
| modifier = Modifier.padding(shape.paddings), | ||
| contentAlignment = Alignment.Center | ||
| ) { | ||
| if (constraints.hasFixedWidth) { | ||
| val sideWidth = (shape.addonSize + shape.gap) * maxOf( | ||
| beforeAddons.size, | ||
| afterAddons.size | ||
| ).toFloat() | ||
|
|
||
| Box(modifier = Modifier.fillMaxWidth()) { | ||
| Addons( | ||
| addons = beforeAddons, | ||
| addonSize = shape.addonSize, | ||
| gap = shape.gap, | ||
| position = AddonPosition.Before, | ||
| modifier = Modifier.align(Alignment.CenterStart) | ||
| ) | ||
| Box( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .padding(horizontal = sideWidth) | ||
| .align(Alignment.Center), | ||
| contentAlignment = Alignment.Center, | ||
| content = { content() } | ||
| ) | ||
| Addons( | ||
| addons = afterAddons, | ||
| addonSize = shape.addonSize, | ||
| gap = shape.gap, | ||
| position = AddonPosition.After, | ||
| modifier = Modifier.align(Alignment.CenterEnd) | ||
| ) | ||
| } | ||
| } else { | ||
| Row(verticalAlignment = Alignment.CenterVertically) { | ||
| Addons( | ||
| addons = beforeAddons, | ||
| addonSize = shape.addonSize, | ||
| gap = shape.gap, | ||
| position = AddonPosition.Before | ||
| ) | ||
| Box(contentAlignment = Alignment.Center) { | ||
| content() | ||
| } | ||
| Addons( | ||
| addons = afterAddons, | ||
| addonSize = shape.addonSize, | ||
| gap = shape.gap, | ||
| position = AddonPosition.After | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun Addons( | ||
| addons: List<Addon>, | ||
| addonSize: Dp, | ||
| gap: Dp, | ||
| position: AddonPosition, | ||
| modifier: Modifier = Modifier | ||
| ) { | ||
| Row( | ||
| modifier = modifier, | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| if (addons.isNotEmpty() && position == AddonPosition.After) { | ||
| Spacer(modifier = Modifier.width(gap)) | ||
| } | ||
| addons.forEachIndexed { index, addon -> | ||
| if (index > 0) { | ||
| Spacer(modifier = Modifier.width(gap)) | ||
| } | ||
| Box( | ||
| modifier = Modifier.size(addonSize), | ||
| contentAlignment = Alignment.Center | ||
| ) { | ||
| addon.Content() | ||
| } | ||
| } | ||
| if (addons.isNotEmpty() && position == AddonPosition.Before) { | ||
| Spacer(modifier = Modifier.width(gap)) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.