-
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.
update: [ANDROAPP-5467] age field component moved to separate file
- Loading branch information
1 parent
2b98214
commit 883c070
Showing
2 changed files
with
50 additions
and
43 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...em/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/AgeFieldHelper.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,50 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import org.hisp.dhis.mobile.ui.designsystem.resource.provideStringResource | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.Shape | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor | ||
|
||
/** | ||
* DHIS2 age field helper. | ||
* | ||
* @param orientation Controls how the radio buttons will be displayed, HORIZONTAL for rows or | ||
* VERTICAL for columns. | ||
* @param optionSelected controls which item is selected. | ||
* @param onClick is a callback to notify which item has changed into the block. | ||
*/ | ||
@Composable | ||
fun AgeFieldHelper( | ||
orientation: Orientation, | ||
optionSelected: String, | ||
onClick: (RadioButtonData) -> Unit, | ||
) { | ||
RowComponentContainer( | ||
modifier = Modifier | ||
.padding( | ||
start = Spacing.Spacing8, | ||
end = Spacing.Spacing8, | ||
) | ||
.background(color = SurfaceColor.Surface, Shape.SmallBottom), | ||
) { | ||
val options = AgeFieldHelperValues.values().map { | ||
RadioButtonData(it.value, optionSelected == it.value, true, provideStringResource(it.value)) | ||
} | ||
val selectedItem = options.find { | ||
it.selected | ||
} | ||
RadioButtonBlock(orientation, options, selectedItem ?: options[0]) { | ||
onClick.invoke(it) | ||
} | ||
} | ||
} | ||
|
||
enum class AgeFieldHelperValues(val value: String) { | ||
YEARS("Years"), | ||
MONTHS("Months"), | ||
DAYS("Days"), | ||
} |
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