-
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.
add: [ANDROAPP-6097] Component, screens and tests added (#246)
* add: [ANDROAPP-6097] Component, screens and tests added * add: [ANDROAPP-6097] snapshot image added, code formatted * update: [ANDROAPP-6097] snapshot test class name modified * update: [ANDROAPP-6097] test path modified * remove: [ANDROAPP-6097] import removed * add: [ANDROAPP-6097] snapshot test modified * remove: [ANDROAPP-6097] comment removed * add: [ANDROAPP-6097] snapshot added * test snapshot --------- Co-authored-by: manu <mmmateos@protonmail.com>
- Loading branch information
1 parent
d8ff7a1
commit 657bd64
Showing
5 changed files
with
280 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
99 changes: 99 additions & 0 deletions
99
...src/androidUnitTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/AssistChipSnapshotTest.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,99 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem | ||
|
||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Search | ||
import androidx.compose.material3.AssistChipDefaults | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.ui.Modifier | ||
import org.hisp.dhis.mobile.ui.designsystem.component.AssistChip | ||
import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class AssistChipSnapshotTest { | ||
@get:Rule | ||
val paparazzi = paparazzi() | ||
|
||
@Test | ||
fun launchAssistChip() { | ||
paparazzi.snapshot { | ||
ColumnComponentContainer(modifier = Modifier.padding(Spacing.Spacing10)) { | ||
AssistChip( | ||
label = "Label", | ||
icon = { | ||
Icon( | ||
imageVector = Icons.Filled.Search, | ||
contentDescription = "search icon", | ||
modifier = Modifier | ||
.size(AssistChipDefaults.IconSize), | ||
) | ||
}, | ||
onClick = {}, | ||
badge = "3", | ||
) | ||
AssistChip( | ||
label = "Label", | ||
onClick = {}, | ||
badge = "3", | ||
) | ||
AssistChip( | ||
label = "Label", | ||
icon = { | ||
Icon( | ||
imageVector = Icons.Filled.Search, | ||
contentDescription = "search icon", | ||
modifier = Modifier | ||
.size(AssistChipDefaults.IconSize), | ||
) | ||
}, | ||
onClick = {}, | ||
) | ||
AssistChip( | ||
label = "Label", | ||
onClick = {}, | ||
) | ||
AssistChip( | ||
label = "Label", | ||
icon = { | ||
Icon( | ||
imageVector = Icons.Filled.Search, | ||
contentDescription = "search icon", | ||
modifier = Modifier | ||
.size(AssistChipDefaults.IconSize), | ||
) | ||
}, | ||
enabled = false, | ||
onClick = {}, | ||
) | ||
AssistChip( | ||
label = "Label", | ||
onClick = {}, | ||
enabled = false, | ||
) | ||
AssistChip( | ||
label = "Label", | ||
icon = { | ||
Icon( | ||
imageVector = Icons.Filled.Search, | ||
contentDescription = "search icon", | ||
modifier = Modifier | ||
.size(AssistChipDefaults.IconSize), | ||
) | ||
}, | ||
enabled = false, | ||
onClick = {}, | ||
badge = "3", | ||
) | ||
AssistChip( | ||
label = "Label", | ||
onClick = {}, | ||
enabled = false, | ||
badge = "3", | ||
) | ||
} | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...system/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/AssistChip.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,97 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component | ||
|
||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.interaction.collectIsPressedAsState | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.offset | ||
import androidx.compose.material.ripple.LocalRippleTheme | ||
import androidx.compose.material3.AssistChip | ||
import androidx.compose.material3.AssistChipDefaults | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
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.platform.testTag | ||
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 | ||
|
||
/** | ||
* DHIS2 [AssistChip] button with custom icon slot. | ||
* wraps Material 3 [AssistChip]. | ||
* AssistChips are used to trigger actions. | ||
* @param label: the text to be shown. | ||
* @param icon: custom leading icon to be shown, use AssistChipDefaults in the | ||
* Icon composable modifier to set the size of the icon. | ||
* @param enabled: controls the enabled state. "False" will disabled the component | ||
* @param modifier: optional [Modifier]. | ||
* @param onClick: Will be called when the user taps the chip. | ||
* @param badge: the text to be displayed within the badge. | ||
*/ | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun AssistChip( | ||
modifier: Modifier = Modifier, | ||
label: String, | ||
icon: @Composable (() -> Unit)? = null, | ||
enabled: Boolean = true, | ||
onClick: (() -> Unit), | ||
badge: String? = null, | ||
) { | ||
val interactionSource = remember { MutableInteractionSource() } | ||
val isPressed by interactionSource.collectIsPressedAsState() | ||
|
||
Box(modifier = Modifier) { | ||
CompositionLocalProvider(LocalRippleTheme provides Ripple.CustomDHISRippleTheme()) { | ||
AssistChip( | ||
onClick = { onClick.invoke() }, | ||
label = { | ||
Text( | ||
label, | ||
color = TextColor.OnSurfaceVariant, | ||
) | ||
}, | ||
modifier = modifier, | ||
enabled = enabled, | ||
colors = if (isPressed) { | ||
AssistChipDefaults.assistChipColors( | ||
containerColor = SurfaceColor.Container, | ||
leadingIconContentColor = TextColor.OnSurfaceVariant, | ||
) | ||
} else { | ||
AssistChipDefaults.assistChipColors( | ||
containerColor = SurfaceColor.SurfaceBright, | ||
leadingIconContentColor = TextColor.OnSurfaceVariant, | ||
) | ||
}, | ||
border = AssistChipDefaults.assistChipBorder( | ||
borderColor = Outline.Dark, | ||
), | ||
leadingIcon = { | ||
icon?.invoke() | ||
}, | ||
|
||
) | ||
} | ||
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 } | ||
.testTag("ASSIST_CHIP_BADGE"), | ||
text = badge, | ||
) | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...m/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/AssistChipTest.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,39 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component | ||
|
||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Search | ||
import androidx.compose.material3.AssistChipDefaults | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class AssistChipTest { | ||
|
||
@get:Rule | ||
val rule = createComposeRule() | ||
|
||
@Test | ||
fun assistChipShouldDisplayBadges() { | ||
rule.setContent { | ||
AssistChip( | ||
label = "Label", | ||
icon = { | ||
Icon( | ||
imageVector = Icons.Filled.Search, | ||
contentDescription = "search icon", | ||
modifier = Modifier | ||
.size(AssistChipDefaults.IconSize), | ||
) | ||
}, | ||
onClick = {}, | ||
badge = "2", | ||
) | ||
} | ||
|
||
rule.onNodeWithTag("ASSIST_CHIP_BADGE").assertExists() | ||
} | ||
} |
Binary file added
BIN
+28.3 KB
...rg.hisp.dhis.mobile.ui.designsystem_AssistChipSnapshotTest_launchAssistChip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.