PasswordField

fun PasswordField(value: String, onValueChange: (String) -> Unit, rules: List<PasswordRule> = rememberPasswordRuleList(), modifier: Modifier = Modifier, visualTransformation: (showPassword: Boolean) -> VisualTransformation = { if(it) VisualTransformation.None else PasswordVisualTransformation() }, keyboardActions: KeyboardActions = KeyboardActions(), keyboardOptions: KeyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password), readOnly: Boolean = false, enabled: Boolean = true, singleLine: Boolean = true, isError: Boolean? = null, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, textStyle: TextStyle = LocalTextStyle.current, shape: Shape = TextFieldDefaults.shape, colors: TextFieldColors = TextFieldDefaults.colors(), label: @Composable () -> Unit? = null, leadingIcon: @Composable () -> Unit? = { Icon(AuthIcons.rememberLockIcon(), "Lock") }, supportingText: @Composable (rules: List<PasswordRuleResult>) -> Unit? = { if (value.isNotEmpty()) it.firstUnfulfilled()?.let { rule -> Text(rule.description) } }, trailingIcon: @Composable (showPassword: MutableState<Boolean>) -> Unit? = { showPassword -> IconButton(onClick = { showPassword.value = !showPassword.value }) { Icon(if(showPassword.value) AuthIcons.rememberVisibilityIcon() else AuthIcons.rememberVisibilityOffIcon(), "Visibility") } }, placeholder: @Composable () -> Unit? = null, formKey: String = "PASSWORD", mandatory: Boolean = true)(source)
fun PasswordField(value: TextFieldValue, onValueChange: (TextFieldValue) -> Unit, rules: List<PasswordRule> = rememberPasswordRuleList(), modifier: Modifier = Modifier, visualTransformation: (showPassword: Boolean) -> VisualTransformation = { if(it) VisualTransformation.None else PasswordVisualTransformation() }, keyboardActions: KeyboardActions = KeyboardActions(), keyboardOptions: KeyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password), readOnly: Boolean = false, enabled: Boolean = true, singleLine: Boolean = true, isError: Boolean? = null, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, textStyle: TextStyle = LocalTextStyle.current, shape: Shape = TextFieldDefaults.shape, colors: TextFieldColors = TextFieldDefaults.colors(), label: @Composable () -> Unit? = null, leadingIcon: @Composable () -> Unit? = { Icon(AuthIcons.rememberLockIcon(), "Lock") }, supportingText: @Composable (rules: List<PasswordRuleResult>) -> Unit? = { if (value.text.isNotEmpty()) it.firstUnfulfilled()?.let { rule -> Text(rule.description) } }, trailingIcon: @Composable (showPassword: MutableState<Boolean>) -> Unit? = { showPassword -> IconButton(onClick = { showPassword.value = !showPassword.value }) { Icon(if(showPassword.value) AuthIcons.rememberVisibilityIcon() else AuthIcons.rememberVisibilityOffIcon(), "Visibility") } }, placeholder: @Composable () -> Unit? = null, formKey: String = "PASSWORD", mandatory: Boolean = true)(source)

A custom password input field with custom rules and pre-defined styling.

Parameters

value

The current value of the password field.

onValueChange

The callback function for when the value of the password field changes.

rules

The rules for the password field.

modifier

The modifier for styling the password field. Defaults to Modifier.

label

The label for the password field. Defaults to null.

keyboardOptions

The keyboard options for the password field. Defaults to KeyboardOptions(keyboardType = KeyboardType.Password).

keyboardActions

The keyboard actions for the password field. Defaults to KeyboardActions.Default.

leadingIcon

The leading icon for the password field. Defaults to an email icon.

singleLine

Whether the password field should be a single line or multiline. Defaults to true.

enabled

Whether the password field should be enabled for user interaction. Defaults to true.

isError

Whether the password field should display an error state. Defaults to null (handled automatically).

interactionSource

The interaction source for the password field. Defaults to MutableInteractionSource.

textStyle

The text style for the password field. Defaults to LocalTextStyle.current.

shape

The shape of the password field. Defaults to TextFieldDefaults.shape.

colors

The colors for the password field. Defaults to TextFieldDefaults.colors().

supportingText

A composable function to display supporting text based on the validity of the password field value. Defaults to displaying "Please enter a valid email address" if the value is not a valid email.

trailingIcon

The trailing icon for the password field. Defaults to null.

placeholder

The placeholder for the password field. Defaults to null.

formKey

The key to store the validity of the password field in the AuthState. Defaults to "EMAIL".

mandatory

Whether the form field is mandatory or not. If false, will not affect the AuthState.validForm value. You can also make this value dynamic and only make the field mandatory, if e.g. the value is not empty. Default is true.