diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt index f93aa8757..4d14af648 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt @@ -31,6 +31,7 @@ import org.hisp.dhis.common.screens.Components import org.hisp.dhis.common.screens.FormShellsScreen import org.hisp.dhis.common.screens.FormsComponentsScreen import org.hisp.dhis.common.screens.IconButtonScreen +import org.hisp.dhis.common.screens.InputAgeScreen import org.hisp.dhis.common.screens.InputCheckBoxScreen import org.hisp.dhis.common.screens.InputIntegerScreen import org.hisp.dhis.common.screens.InputLetterScreen @@ -67,7 +68,7 @@ fun App() { @Composable fun Main() { - val currentScreen = remember { mutableStateOf(Components.SWITCH) } + val currentScreen = remember { mutableStateOf(Components.FORM_SHELLS) } var expanded by remember { mutableStateOf(false) } Column( @@ -139,6 +140,7 @@ fun Main() { Components.INPUT_INTEGER -> InputIntegerScreen() Components.INPUT_NUMBER -> InputNumberScreen() Components.INPUT_LETTER -> InputLetterScreen() + Components.AGE_FIELD -> InputAgeScreen() Components.CHIPS -> ChipsScreen() Components.BADGES -> BadgesScreen() Components.SWITCH -> SwitchScreen() diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/Components.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/Components.kt index f9b593e56..ed8ba42a5 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/Components.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/Components.kt @@ -34,4 +34,5 @@ enum class Components(val label: String) { INPUT_SEQUENTIAL("Input Sequential"), QR_CODE_BLOCK("QR Code Block"), INPUT_CHECK_BOX("Input Check Box"), + AGE_FIELD("Age Field"), } diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputAgeScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputAgeScreen.kt new file mode 100644 index 000000000..0b9b6aa6d --- /dev/null +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputAgeScreen.kt @@ -0,0 +1,26 @@ +package org.hisp.dhis.common.screens + +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.ColumnComponentContainer +import org.hisp.dhis.mobile.ui.designsystem.component.Orientation +import org.hisp.dhis.mobile.ui.designsystem.component.RadioButtonData +import org.hisp.dhis.mobile.ui.designsystem.component.SubTitle +import org.hisp.dhis.mobile.ui.designsystem.component.TimeUnitSelector +import org.hisp.dhis.mobile.ui.designsystem.component.TimeUnitValues + +@Composable +fun InputAgeScreen() { + ColumnComponentContainer("Age Field components") { + SubTitle("Horizontal Age Field Helper") + var selectedFieldHorizontal by remember { + mutableStateOf(RadioButtonData("0", selected = true, enabled = true, textInput = TimeUnitValues.YEARS.value)) + } + TimeUnitSelector(Orientation.HORIZONTAL, TimeUnitValues.YEARS.value) { + selectedFieldHorizontal = it + } + } +} diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/AgeFieldHelper.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/AgeFieldHelper.kt new file mode 100644 index 000000000..5daf918a1 --- /dev/null +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/AgeFieldHelper.kt @@ -0,0 +1,58 @@ +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.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +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 TimeUnitSelector( + orientation: Orientation, + optionSelected: String, + onClick: (RadioButtonData) -> Unit, +) { + RowComponentContainer( + modifier = Modifier + .background(color = SurfaceColor.Surface, Shape.SmallBottom) + .padding( + start = Spacing.Spacing8, + end = Spacing.Spacing8, + ), + ) { + val options = TimeUnitValues.values().map { + RadioButtonData(it.value, optionSelected == it.value, true, provideStringResource(it.value)) + } + val selectedItem = options.find { + it.selected + } + var currentItem by remember { + mutableStateOf(selectedItem ?: options[0]) + } + RadioButtonBlock(orientation, options, currentItem) { + currentItem = it + onClick.invoke(it) + } + } +} + +enum class TimeUnitValues(val value: String) { + YEARS("years"), + MONTHS("months"), + DAYS("days"), +} diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/RadioButton.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/RadioButton.kt index 3a7812176..efdf720df 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/RadioButton.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/RadioButton.kt @@ -31,7 +31,7 @@ import org.hisp.dhis.mobile.ui.designsystem.theme.hoverPointerIcon * identifying the component, selected for controlling which option is selected, enabled controls if the component is * clickable and textInput displaying the option text. * @param onClick Will be called when the user clicks the button. -* + * */ @Composable fun RadioButton( diff --git a/designsystem/src/commonMain/resources/values/strings_en.xml b/designsystem/src/commonMain/resources/values/strings_en.xml index 4f5375101..2dc17b4e1 100644 --- a/designsystem/src/commonMain/resources/values/strings_en.xml +++ b/designsystem/src/commonMain/resources/values/strings_en.xml @@ -6,6 +6,8 @@ AGE OR Years + Months + Days %d error %d errors %d warning