Skip to content

Commit

Permalink
ANDROAPP-5571-mobile-ui-Create-InputEmail-component
Browse files Browse the repository at this point in the history
Co-authored-by: Siddharth Agarwal <[email protected]>
  • Loading branch information
siddh1004 and Siddharth Agarwal authored Oct 5, 2023
1 parent 9c25f50 commit f688092
Show file tree
Hide file tree
Showing 6 changed files with 416 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ 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.InputEmailScreen
import org.hisp.dhis.common.screens.InputIntegerScreen
import org.hisp.dhis.common.screens.InputLetterScreen
import org.hisp.dhis.common.screens.InputLinkScreen
Expand Down Expand Up @@ -163,6 +164,7 @@ fun Main() {
Components.INPUT_YES_NO_FIELD -> InputYesNoFieldScreen()
Components.INPUT_PHONE_NUMBER -> InputPhoneNumberScreen()
Components.INPUT_LINK -> InputLinkScreen()
Components.INPUT_EMAIL -> InputEmailScreen()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ enum class Components(val label: String) {
INPUT_YES_NO_FIELD("Input Yes/No field"),
INPUT_PHONE_NUMBER("Input Phone Number"),
INPUT_LINK("Input Link"),
INPUT_EMAIL("Input Email"),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package org.hisp.dhis.common.screens

import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer
import org.hisp.dhis.mobile.ui.designsystem.component.InputEmail
import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState
import org.hisp.dhis.mobile.ui.designsystem.component.SubTitle
import org.hisp.dhis.mobile.ui.designsystem.component.SupportingTextData
import org.hisp.dhis.mobile.ui.designsystem.component.SupportingTextState
import org.hisp.dhis.mobile.ui.designsystem.component.Title
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing
import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor

@Composable
fun InputEmailScreen() {
ColumnComponentContainer {
Title("Input Email component", textColor = TextColor.OnSurfaceVariant)
SubTitle("Basic Email ", textColor = TextColor.OnSurfaceVariant)
var inputText1 by rememberSaveable { mutableStateOf("") }

InputEmail(
title = "Label",
supportingText = listOf(SupportingTextData("Example: [email protected]")),
inputText = inputText1,
onValueChanged = {
if (it != null) {
inputText1 = it
}
},
onEmailActionCLicked = {},
)
Spacer(Modifier.size(Spacing.Spacing18))

SubTitle("Basic Email with content ", textColor = TextColor.OnSurfaceVariant)
var inputText2 by rememberSaveable { mutableStateOf("[email protected]") }

InputEmail(
title = "Label",
supportingText = listOf(SupportingTextData("Example: [email protected]")),
inputText = inputText2,
onValueChanged = {
if (it != null) {
inputText2 = it
}
},
onEmailActionCLicked = {},
)
Spacer(Modifier.size(Spacing.Spacing18))

SubTitle("Error Email with content ", textColor = TextColor.OnSurfaceVariant)
var inputText3 by rememberSaveable { mutableStateOf("[email protected]") }

InputEmail(
title = "Label",
state = InputShellState.ERROR,
supportingText = listOf(SupportingTextData("Enter a valid email address", SupportingTextState.ERROR)),
inputText = inputText3,
onValueChanged = {
if (it != null) {
inputText3 = it
}
},
onEmailActionCLicked = {},
)
Spacer(Modifier.size(Spacing.Spacing18))

SubTitle("Error Email required field ", textColor = TextColor.OnSurfaceVariant)
var inputText4 by rememberSaveable { mutableStateOf("") }
InputEmail(
title = "Label",
state = InputShellState.ERROR,
supportingText = listOf(SupportingTextData("Enter email address", SupportingTextState.ERROR)),
inputText = inputText4,
isRequiredField = true,
onValueChanged = {
if (it != null) {
inputText4 = it
}
},
onEmailActionCLicked = {},
)
Spacer(Modifier.size(Spacing.Spacing18))

SubTitle("Disabled Email with content ", textColor = TextColor.OnSurfaceVariant)
var inputText5 by rememberSaveable { mutableStateOf("[email protected]") }
InputEmail(
title = "Label",
state = InputShellState.DISABLED,
inputText = inputText5,
onValueChanged = {
if (it != null) {
inputText5 = it
}
},
onEmailActionCLicked = {},
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.hisp.dhis.mobile.ui.designsystem.component

import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Email
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations

/**
* DHIS2 Input email. Wraps DHIS · [BasicTextInput].
* @param title controls the text to be shown for the title
* @param state Manages the InputShell state
* @param supportingText is a list of SupportingTextData that
* manages all the messages to be shown
* @param legendData manages the legendComponent
* @param inputText manages the value of the text in the input field
* @param isRequiredField controls whether the field is mandatory or not
* @param onNextClicked gives access to the imeAction event
* @param onValueChanged gives access to the onValueChanged event
* @param onFocusChanged gives access to the onFocusChanged returns true if
* item is focused
* @param imeAction controls the imeAction button to be shown
* @param modifier allows a modifier to be passed externally
* @param onEmailActionCLicked callback to when email button is clicked
*/
@Composable
fun InputEmail(
title: String,
state: InputShellState = InputShellState.UNFOCUSED,
supportingText: List<SupportingTextData>? = null,
legendData: LegendData? = null,
inputText: String? = null,
isRequiredField: Boolean = false,
onNextClicked: (() -> Unit)? = null,
onValueChanged: ((String?) -> Unit)? = null,
onFocusChanged: ((Boolean) -> Unit)? = null,
imeAction: ImeAction = ImeAction.Next,
modifier: Modifier = Modifier,
onEmailActionCLicked: () -> Unit,
) {
val isValidEmailAddress = RegExValidations.EMAIL.regex.matches(inputText.orEmpty())
BasicTextInput(
title = title,
state = state,
supportingText = supportingText,
legendData = legendData,
inputText = inputText,
isRequiredField = isRequiredField,
onNextClicked = onNextClicked,
onValueChanged = onValueChanged,
keyboardOptions = KeyboardOptions(
imeAction = imeAction,
keyboardType = KeyboardType.Email,
),
modifier = modifier,
testTag = "EMAIL",
onFocusChanged = onFocusChanged,
actionButton = {
SquareIconButton(
modifier = Modifier.testTag("EMAIL_BUTTON"),
enabled = isValidEmailAddress,
icon = {
Icon(
imageVector = Icons.Outlined.Email,
contentDescription = "email_icon",
)
},
onClick = onEmailActionCLicked,
)
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ enum class RegExValidations(val regex: Regex) {
POSITIVE_INTEGER_OR_ZERO("^(0|[1-9]\\d*)\$".toRegex()),
PHONE_NUMBER("^[+0-9-()]+$".toRegex()),
LINK("((https?|ftp|smtp)://)?(www\\.)?[a-zA-Z0-9@:%._+~#=-]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&/=-]*)".toRegex()),
EMAIL("^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}\$".toRegex()),
}
Loading

0 comments on commit f688092

Please sign in to comment.