Skip to content

Commit

Permalink
added readonly field (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco authored Feb 1, 2024
1 parent e837852 commit 2a29534
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ enum class FieldType {
DATE,
DROPDOWN,
RADIO_BUTTONS,
READONLY_TEXT,
READONLY,
;

fun value() = name.lowercase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.alfresco.content.process.ui.components.DropdownField
import com.alfresco.content.process.ui.components.IntegerInputField
import com.alfresco.content.process.ui.components.MultiLineInputField
import com.alfresco.content.process.ui.components.RadioButtonField
import com.alfresco.content.process.ui.components.ReadOnlyField
import com.alfresco.content.process.ui.components.SingleLineInputField

@OptIn(ExperimentalComposeUiApi::class)
Expand Down Expand Up @@ -146,6 +147,14 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel) {
fieldsData = field,
)
}

FieldType.READONLY_TEXT.value(), FieldType.READONLY.value() -> {
val textFieldValue by remember { mutableStateOf(field.value as? String ?: "") }
ReadOnlyField(
textFieldValue = textFieldValue,
fieldsData = field,
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.alfresco.content.process.ui.components

import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.tooling.preview.Preview
import com.alfresco.content.data.payloads.FieldsData
import inputField

@Composable
fun ReadOnlyField(
textFieldValue: String = "",
fieldsData: FieldsData = FieldsData(),
) {
val keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Next,
keyboardType = KeyboardType.Text,
)

val textFieldColors = if (textFieldValue.isEmpty()) {
OutlinedTextFieldDefaults.colors(
disabledBorderColor = MaterialTheme.colorScheme.primary,
disabledTextColor = MaterialTheme.colorScheme.onSurface,
disabledPlaceholderColor = MaterialTheme.colorScheme.primary,
)
} else
OutlinedTextFieldDefaults.colors(
disabledBorderColor = MaterialTheme.colorScheme.primary,
disabledTextColor = MaterialTheme.colorScheme.onSurface,
disabledPlaceholderColor = MaterialTheme.colorScheme.primary,
disabledLabelColor = MaterialTheme.colorScheme.primary,
)

InputField(
colors = textFieldColors,
modifier = Modifier
.inputField(),
maxLines = 1,
textFieldValue = textFieldValue,
fieldsData = fieldsData,
keyboardOptions = keyboardOptions,
isEnabled = false,
)
}

@Preview
@Composable
fun ReadOnlyFieldPreview() {
ReadOnlyField()
}

0 comments on commit 2a29534

Please sign in to comment.