Skip to content

Commit

Permalink
update: [ANDROAPP-5467] age field component moved to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAparicioAlbaAsenjo committed Sep 14, 2023
1 parent 2b98214 commit 883c070
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 43 deletions.
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"),
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.hisp.dhis.mobile.ui.designsystem.component

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -19,11 +18,9 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import org.hisp.dhis.mobile.ui.designsystem.resource.provideStringResource
import org.hisp.dhis.mobile.ui.designsystem.theme.InternalSizeValues
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.Shape
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor
import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor
Expand Down Expand Up @@ -160,46 +157,6 @@ fun RadioButtonBlock(
}
}

/**
* 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"),
}

data class RadioButtonData(
val uid: String,
val selected: Boolean,
Expand Down

0 comments on commit 883c070

Please sign in to comment.