-
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 5820 mobile UI implement input chip component (#173)
* rename `Chip` to `FilterChip` * rename `Chip` file to `FilterChip` * add `InputChip` component * fix lint error --------- Co-authored-by: Siddharth Agarwal <[email protected]>
- Loading branch information
Showing
4 changed files
with
147 additions
and
11 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
56 changes: 48 additions & 8 deletions
56
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 |
---|---|---|
@@ -1,22 +1,62 @@ | ||
package org.hisp.dhis.common.screens | ||
|
||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import org.hisp.dhis.mobile.ui.designsystem.component.Chip | ||
import androidx.compose.ui.Modifier | ||
import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer | ||
import org.hisp.dhis.mobile.ui.designsystem.component.FilterChip | ||
import org.hisp.dhis.mobile.ui.designsystem.component.InputChip | ||
import org.hisp.dhis.mobile.ui.designsystem.component.SubTitle | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing | ||
|
||
@Composable | ||
fun ChipsScreen() { | ||
ColumnComponentContainer(title = "Filter Chips") { | ||
ColumnComponentContainer { | ||
SubTitle("Input Chips") | ||
var isSelected by remember { mutableStateOf(false) } | ||
Chip(label = "Label", selected = isSelected, onSelected = { isSelected = it }) | ||
Chip(label = "Label", selected = !isSelected, onSelected = { isSelected = !it }) | ||
} | ||
ColumnComponentContainer(title = "With badges") { | ||
Chip(label = "Label", selected = true, badge = "3") | ||
Chip(label = "Label", selected = false, badge = "3") | ||
var isSelected1 by remember { mutableStateOf(true) } | ||
var isSelected2 by remember { mutableStateOf(false) } | ||
var isSelected3 by remember { mutableStateOf(true) } | ||
InputChip(label = "Label", selected = isSelected, onSelected = { isSelected = it }) | ||
InputChip(label = "Label", selected = !isSelected1, onSelected = { isSelected1 = !it }) | ||
InputChip( | ||
label = "Label", | ||
selected = !isSelected2, | ||
withTrailingIcon = true, | ||
onSelected = { isSelected2 = !it }, | ||
onIconSelected = {}, | ||
) | ||
InputChip( | ||
label = "Label", | ||
selected = !isSelected3, | ||
withTrailingIcon = true, | ||
onSelected = { isSelected3 = !it }, | ||
onIconSelected = {}, | ||
) | ||
InputChip( | ||
label = "Label", | ||
enabled = false, | ||
) | ||
Spacer(Modifier.size(Spacing.Spacing18)) | ||
|
||
SubTitle("Input Chips With badges") | ||
InputChip(label = "Label", selected = false, badge = "3") | ||
InputChip(label = "Label", selected = true, badge = "3") | ||
Spacer(Modifier.size(Spacing.Spacing18)) | ||
|
||
SubTitle("Filter Chips") | ||
var isSelected4 by remember { mutableStateOf(false) } | ||
FilterChip(label = "Label", selected = isSelected4, onSelected = { isSelected4 = it }) | ||
FilterChip(label = "Label", selected = !isSelected4, onSelected = { isSelected4 = !it }) | ||
Spacer(Modifier.size(Spacing.Spacing18)) | ||
|
||
SubTitle("Filter Chips With badges") | ||
FilterChip(label = "Label", selected = true, badge = "3") | ||
FilterChip(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
96 changes: 96 additions & 0 deletions
96
...nsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputChip.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,96 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component | ||
|
||
import androidx.compose.foundation.clickable | ||
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.outlined.Close | ||
import androidx.compose.material.ripple.LocalRippleTheme | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
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.Outline | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.Ripple | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun InputChip( | ||
modifier: Modifier = Modifier, | ||
label: String, | ||
selected: Boolean = false, | ||
withTrailingIcon: Boolean = false, | ||
enabled: Boolean = true, | ||
onSelected: ((Boolean) -> Unit)? = null, | ||
onIconSelected: (() -> Unit)? = null, | ||
badge: String? = null, | ||
) { | ||
Box(modifier = modifier) { | ||
CompositionLocalProvider(LocalRippleTheme provides Ripple.CustomDHISRippleTheme) { | ||
androidx.compose.material3.InputChip( | ||
enabled = enabled, | ||
onClick = { | ||
onSelected?.invoke(!selected) | ||
}, | ||
label = { | ||
Text( | ||
label, | ||
color = if (enabled) { | ||
TextColor.OnSurfaceVariant | ||
} else { | ||
TextColor.OnDisabledSurface | ||
}, | ||
) | ||
}, | ||
selected = selected, | ||
colors = FilterChipDefaults.filterChipColors( | ||
containerColor = SurfaceColor.SurfaceBright, | ||
selectedContainerColor = SurfaceColor.Container, | ||
), | ||
border = FilterChipDefaults.filterChipBorder( | ||
borderColor = Outline.Dark, | ||
disabledBorderColor = Outline.Medium, | ||
), | ||
trailingIcon = if (withTrailingIcon && enabled) { | ||
{ | ||
Icon( | ||
imageVector = Icons.Outlined.Close, | ||
tint = TextColor.OnSurfaceVariant, | ||
contentDescription = "Close icon", | ||
modifier = Modifier | ||
.size(FilterChipDefaults.IconSize) | ||
.clickable { | ||
onIconSelected?.invoke() | ||
}, | ||
) | ||
} | ||
} 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, | ||
) | ||
} | ||
} | ||
} |