Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

728 - Allow leading icon on OdsPasswordTextField #733

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ private fun TextFieldTextCustomization(textFieldCustomizationState: TextFieldCus
@Composable
private fun TextFieldPasswordCustomization(textFieldCustomizationState: TextFieldCustomizationState) {
with(textFieldCustomizationState) {
OdsListItem(
text = stringResource(id = R.string.component_element_leading_icon),
trailing = OdsListItemTrailingSwitch(leadingIcon.value, { leadingIcon.value = it })
)
DisplayTypeCustomization(displayType)
OdsListItem(
text = stringResource(id = R.string.component_text_field_visualisation_icon),
Expand Down Expand Up @@ -244,4 +248,4 @@ private enum class CustomizationTab(@StringRes val titleRes: Int) {
Keyboard -> KeyboardCustomizationContent(textFieldCustomizationState = textFieldCustomizationState)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import com.orange.ods.app.R
import com.orange.ods.compose.OdsComposable
Expand All @@ -28,11 +29,13 @@ fun TextFieldPassword(customizationState: TextFieldCustomizationState) {
val errorMessage = stringResource(id = R.string.component_text_field_error_message)

with(customizationState) {
val leadingIcon = if (hasLeadingIcon) painterResource(id = R.drawable.ic_lock) else null
Column {
OdsPasswordTextField(
modifier = Modifier
.fillMaxWidth()
.padding(top = dimensionResource(id = com.orange.ods.R.dimen.spacing_s)),
leadingIcon = leadingIcon,
enabled = isEnabled,
isError = isError,
errorMessage = if (isError) errorMessage else null,
Expand All @@ -59,4 +62,4 @@ fun TextFieldPassword(customizationState: TextFieldCustomizationState) {
)
}
}
}
}
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/ic_lock.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillAlpha="0"
android:fillColor="#fff"
android:pathData="M0,0h24v24h-24z"
android:strokeAlpha="0" />
<path
android:fillColor="#FF000000"
android:fillType="evenOdd"
android:pathData="M17.4,9.6h-0.6v-3a4.8,4.8 0,1 0,-9.6 0v3L4.8,9.6L4.8,20.4a1.8,1.8 0,0 0,1.8 1.8L19.2,22.2L19.2,11.4A1.8,1.8 0,0 0,17.4 9.6ZM12.877,15.972L13.2,19.2L10.8,19.2l0.323,-3.228a1.8,1.8 0,1 1,1.754 0ZM15,9.6L9,9.6v-3a3,3 0,1 1,6 0Z" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
Expand Down Expand Up @@ -58,6 +59,10 @@ import com.orange.ods.compose.component.utilities.UiModePreviews
* [Typography.subtitle1] when the text field is not in focus
* @param placeholder the optional placeholder to be displayed when the text field is in focus and
* the input text is empty. The default text style for internal [Text] is [Typography.subtitle1]
* @param leadingIcon the optional leading icon painter to be displayed at the beginning of the text field
* container
* @param leadingIconContentDescription the optional content description for the leading icon.
* @param onLeadingIconClick the optional action executed on leading icon click.
* @param visualisationIcon If `true`, an eye icon will be display to allow showing/hiding password.
* @param isError indicates if the text field's current value is in error state. If set to
* true, the label, bottom indicator and trailing icon by default will be displayed in error color
Expand All @@ -79,6 +84,9 @@ fun OdsPasswordTextField(
readOnly: Boolean = false,
label: String? = null,
placeholder: String? = null,
leadingIcon: Painter? = null,
leadingIconContentDescription: String? = null,
onLeadingIconClick: (() -> Unit)? = null,
visualisationIcon: Boolean = true,
isError: Boolean = false,
errorMessage: String? = null,
Expand All @@ -100,6 +108,9 @@ fun OdsPasswordTextField(
readOnly = readOnly,
label = label,
placeholder = placeholder,
leadingIcon = leadingIcon,
leadingIconContentDescription = leadingIconContentDescription,
onLeadingIconClick = onLeadingIconClick,
trailing = if (visualisationIcon) {
{ OdsPasswordVisualisationIcon(odsPasswordTextFieldState) }
} else null,
Expand Down Expand Up @@ -136,6 +147,7 @@ private fun PreviewOdsPasswordTextField(@PreviewParameter(OdsPasswordTextFieldPr
OdsPasswordTextField(
value = value,
onValueChange = { value = it },
leadingIcon = painterResource(id = android.R.drawable.ic_dialog_info),
placeholder = "Placeholder",
isError = hasErrorMessage,
errorMessage = if (hasErrorMessage) "Error message" else null
Expand Down