-
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.
ANDROAPP-5470-mobile-ui-Create-text-input (#33)
* reset button functionality and padding corrections * add documentation, remove unnecessary mutable values , add disabled examples * small correction after rebase
- Loading branch information
1 parent
950b4c8
commit 58f161a
Showing
10 changed files
with
203 additions
and
25 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
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
49 changes: 49 additions & 0 deletions
49
common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputTextScreen.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,49 @@ | ||
package org.hisp.dhis.common.screens | ||
|
||
import androidx.compose.runtime.Composable | ||
import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer | ||
import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState | ||
import org.hisp.dhis.mobile.ui.designsystem.component.InputText | ||
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.TextColor | ||
|
||
@Composable | ||
fun InputTextScreen() { | ||
ColumnComponentContainer { | ||
Title("Input text component", textColor = TextColor.OnSurfaceVariant) | ||
SubTitle(" Basic Input text", textColor = TextColor.OnSurfaceVariant) | ||
InputText(title = "Label", inputText = "") | ||
|
||
SubTitle("Input text with legend", textColor = TextColor.OnSurfaceVariant) | ||
InputText(title = "Label", inputText = "", legendText = "Legend") | ||
|
||
SubTitle("Input text with Supporting text", textColor = TextColor.OnSurfaceVariant) | ||
InputText(title = "Label", inputText = "", supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT))) | ||
|
||
SubTitle("Input text with Supporting text and legend", textColor = TextColor.OnSurfaceVariant) | ||
InputText(title = "Label", inputText = "", supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), legendText = "Legend") | ||
|
||
SubTitle("Input text with error and warning text and legend", textColor = TextColor.OnSurfaceVariant) | ||
InputText( | ||
title = "Label", | ||
inputText = "", | ||
supportingText = listOf( | ||
SupportingTextData("Supporting text", SupportingTextState.DEFAULT), | ||
SupportingTextData("Supporting text", SupportingTextState.WARNING), | ||
SupportingTextData("Supporting text", SupportingTextState.ERROR) | ||
|
||
), | ||
legendText = "Legend", | ||
state = InputShellState.ERROR | ||
) | ||
|
||
SubTitle("Disabled Input text ", textColor = TextColor.OnSurfaceVariant) | ||
InputText(title = "Label", inputText = "", state = InputShellState.DISABLED) | ||
|
||
SubTitle("Disabled Input text with content ", textColor = TextColor.OnSurfaceVariant) | ||
InputText(title = "Label", inputText = "Content", state = InputShellState.DISABLED) | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/Input.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,76 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component | ||
|
||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.outlined.Cancel | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor | ||
|
||
/** | ||
* DHIS2 Input Text. Wraps DHIS · [InputShell]. | ||
* @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 legendText manages the text to be shown with the legend component | ||
* @param inputText manages the value of the text in the input field | ||
* @param modifier allows a modifier to be passed externally | ||
*/ | ||
@Composable | ||
fun InputText( | ||
title: String, | ||
state: InputShellState = InputShellState.UNFOCUSED, | ||
supportingText: List<SupportingTextData>? = null, | ||
legendText: String? = null, | ||
inputText: String = "", | ||
modifier: Modifier = Modifier | ||
) { | ||
var inputValue by rememberSaveable { mutableStateOf(inputText) } | ||
var deleteButtonIsVisible by remember { mutableStateOf(false) } | ||
InputShell( | ||
modifier = modifier, | ||
title = title, | ||
primaryButton = { | ||
if (deleteButtonIsVisible) { | ||
IconButton( | ||
icon = { | ||
Icon( | ||
imageVector = Icons.Outlined.Cancel, | ||
contentDescription = "Icon Button" | ||
) | ||
}, | ||
onClick = { | ||
inputValue = "" | ||
deleteButtonIsVisible = false | ||
}, | ||
enabled = state != InputShellState.DISABLED | ||
) | ||
} | ||
}, | ||
state = state, | ||
legend = { | ||
legendText?.let { | ||
Legend(SurfaceColor.CustomGreen, legendText) {} | ||
} | ||
}, | ||
supportingText = { | ||
supportingText?.forEach { label -> SupportingText(label.text, label.state) } | ||
}, | ||
inputField = { | ||
BasicInput( | ||
inputText = inputValue, | ||
onInputChanged = { | ||
inputValue = it | ||
deleteButtonIsVisible = inputValue.isNotEmpty() | ||
}, | ||
enabled = state != InputShellState.DISABLED | ||
) | ||
} | ||
) | ||
} |
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
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