-
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.
- Loading branch information
1 parent
57598e7
commit 321db4e
Showing
4 changed files
with
128 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
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
60 changes: 60 additions & 0 deletions
60
common/src/commonMain/kotlin/org/hisp/dhis/common/screens/IconCardsScreen.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,60 @@ | ||
package org.hisp.dhis.common.screens | ||
|
||
import androidx.compose.material3.Icon | ||
import androidx.compose.runtime.Composable | ||
import org.hisp.dhis.mobile.ui.designsystem.component.AvatarSize | ||
import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer | ||
import org.hisp.dhis.mobile.ui.designsystem.component.MetadataAvatar | ||
import org.hisp.dhis.mobile.ui.designsystem.component.RowComponentContainer | ||
import org.hisp.dhis.mobile.ui.designsystem.resource.provideDHIS2Icon | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor | ||
|
||
@Composable | ||
fun IconCardsScreen() { | ||
ColumnComponentContainer(title = "Metadata Avatar") { | ||
RowComponentContainer { | ||
MetadataAvatar( | ||
icon = { | ||
Icon( | ||
painter = provideDHIS2Icon("dhis2_microscope_outline"), | ||
contentDescription = "", | ||
) | ||
}, | ||
iconTint = SurfaceColor.Primary, | ||
size = AvatarSize.Normal, | ||
) | ||
MetadataAvatar( | ||
icon = { | ||
Icon( | ||
painter = provideDHIS2Icon("dhis2_microscope_outline"), | ||
contentDescription = "", | ||
) | ||
}, | ||
iconTint = SurfaceColor.Primary, | ||
size = AvatarSize.Large, | ||
) | ||
} | ||
RowComponentContainer { | ||
MetadataAvatar( | ||
icon = { | ||
Icon( | ||
painter = provideDHIS2Icon("dhis2_nurse_positive"), | ||
contentDescription = "", | ||
) | ||
}, | ||
iconTint = SurfaceColor.CustomGreen, | ||
size = AvatarSize.Normal, | ||
) | ||
MetadataAvatar( | ||
icon = { | ||
Icon( | ||
painter = provideDHIS2Icon("dhis2_nurse_positive"), | ||
contentDescription = "", | ||
) | ||
}, | ||
iconTint = SurfaceColor.CustomGreen, | ||
size = AvatarSize.Large, | ||
) | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...em/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/MetadataAvatar.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,65 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.LocalContentColor | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
import org.hisp.dhis.mobile.ui.designsystem.component.AvatarSize.Large | ||
import org.hisp.dhis.mobile.ui.designsystem.component.AvatarSize.Normal | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.Radius | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing | ||
|
||
/** | ||
* DHIS2 metadata avatar | ||
* | ||
* @param icon: Icon content | ||
* @param iconTint: Color of the icon | ||
* @param backgroundColor: Background color of the avatar. By default it's icon tine with 10% alpha | ||
* @param size: size of the component [AvatarSize] | ||
*/ | ||
@Composable | ||
fun MetadataAvatar( | ||
icon: @Composable () -> Unit, | ||
modifier: Modifier = Modifier, | ||
iconTint: Color = Color.Unspecified, | ||
backgroundColor: Color = Color.Unspecified, | ||
size: AvatarSize = Normal, | ||
) { | ||
val backgroundPadding = when (size) { | ||
Normal -> 0.dp | ||
Large -> 4.dp | ||
} | ||
val boxBackgroundColor = if (backgroundColor != Color.Unspecified) { | ||
backgroundColor | ||
} else { | ||
iconTint.copy(alpha = 0.1f) | ||
} | ||
Box( | ||
modifier = modifier | ||
.background( | ||
color = boxBackgroundColor, | ||
shape = RoundedCornerShape(Radius.XS), | ||
) | ||
.padding(backgroundPadding) | ||
.size(Spacing.Spacing40), | ||
contentAlignment = Alignment.Center, | ||
) { | ||
CompositionLocalProvider( | ||
LocalContentColor provides iconTint, | ||
) { | ||
icon() | ||
} | ||
} | ||
} | ||
|
||
enum class AvatarSize { | ||
Normal, Large | ||
} |