-
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.
ANDROAPP-5510/ANDROAPP-5511-mobile-ui-Create-Chips-and-Badges (#55)
* feat: [ANDROAPP-5510, ANDROAPP-5511] chips and badges * fixes chips and badges * fixes chips and badges --------- Co-authored-by: Pablo <[email protected]>
- Loading branch information
Showing
6 changed files
with
165 additions
and
0 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
18 changes: 18 additions & 0 deletions
18
common/src/commonMain/kotlin/org/hisp/dhis/common/screens/BadgesScreen.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,18 @@ | ||
package org.hisp.dhis.common.screens | ||
|
||
import androidx.compose.runtime.Composable | ||
import org.hisp.dhis.mobile.ui.designsystem.component.Badge | ||
import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer | ||
import org.hisp.dhis.mobile.ui.designsystem.component.ErrorBadge | ||
|
||
@Composable | ||
fun BadgesScreen() { | ||
ColumnComponentContainer(title = "Badges") { | ||
Badge() | ||
Badge(text = "32") | ||
} | ||
ColumnComponentContainer(title = "Error badges") { | ||
ErrorBadge() | ||
ErrorBadge(text = "32") | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
common/src/commonMain/kotlin/org/hisp/dhis/common/screens/ChipsScreen.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,17 @@ | ||
package org.hisp.dhis.common.screens | ||
|
||
import androidx.compose.runtime.Composable | ||
import org.hisp.dhis.mobile.ui.designsystem.component.Chip | ||
import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer | ||
|
||
@Composable | ||
fun ChipsScreen() { | ||
ColumnComponentContainer(title = "Filter Chips") { | ||
Chip(label = "Label", selected = true) | ||
Chip(label = "Label", selected = false) | ||
} | ||
ColumnComponentContainer(title = "With badges") { | ||
Chip(label = "Label", selected = true, badge = "3") | ||
Chip(label = "Label", selected = false, badge = "3") | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/Badge.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,49 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.defaultMinSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.style.TextAlign | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor | ||
|
||
@Composable | ||
fun Badge( | ||
modifier: Modifier = Modifier, | ||
text: String? = null, | ||
color: Color = SurfaceColor.Primary, | ||
textColor: Color = TextColor.OnPrimary, | ||
) { | ||
Box( | ||
modifier | ||
.defaultMinSize(Spacing.Spacing6, Spacing.Spacing6) | ||
.background(color, CircleShape), | ||
) { | ||
text?.let { | ||
Text( | ||
modifier = Modifier | ||
.padding(horizontal = Spacing.Spacing4) | ||
.padding(bottom = Spacing.Spacing1), | ||
text = it, | ||
textAlign = TextAlign.Center, | ||
style = MaterialTheme.typography.labelSmall.copy(color = textColor), | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun ErrorBadge( | ||
modifier: Modifier = Modifier, | ||
text: String? = null, | ||
) { | ||
Badge(modifier, text, SurfaceColor.Error, TextColor.OnError) | ||
} |
75 changes: 75 additions & 0 deletions
75
designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/Chip.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,75 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.offset | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Done | ||
import androidx.compose.material.ripple.LocalRippleTheme | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.FilterChip | ||
import androidx.compose.material3.FilterChipDefaults | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.onSizeChanged | ||
import androidx.compose.ui.unit.IntOffset | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.Ripple | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun Chip( | ||
modifier: Modifier = Modifier, | ||
label: String, | ||
selected: Boolean = false, | ||
onSelected: ((Boolean) -> Unit)? = null, | ||
badge: String? = null, | ||
) { | ||
Box(modifier = modifier) { | ||
CompositionLocalProvider(LocalRippleTheme provides Ripple.CustomDHISRippleTheme) { | ||
var isSelected by remember { mutableStateOf(selected) } | ||
|
||
FilterChip( | ||
onClick = { | ||
isSelected = !isSelected | ||
onSelected?.invoke(isSelected) | ||
}, | ||
label = { Text(label) }, | ||
selected = isSelected, | ||
colors = FilterChipDefaults.filterChipColors( | ||
containerColor = SurfaceColor.SurfaceBright, | ||
selectedContainerColor = SurfaceColor.Container, | ||
), | ||
leadingIcon = if (isSelected) { | ||
{ | ||
Icon( | ||
imageVector = Icons.Filled.Done, | ||
contentDescription = "Done icon", | ||
modifier = Modifier.size(FilterChipDefaults.IconSize), | ||
) | ||
} | ||
} else { | ||
null | ||
}, | ||
) | ||
} | ||
badge?.let { | ||
var offset by remember { mutableStateOf(IntOffset(0, 0)) } | ||
Badge( | ||
modifier = Modifier | ||
.align(Alignment.TopEnd) | ||
.onSizeChanged { offset = IntOffset(it.width / 3, it.height / 3) } | ||
.offset { offset }, | ||
text = badge, | ||
) | ||
} | ||
} | ||
} |