design : TextField2 is now TextField
This commit is contained in:
parent
6a68ebe467
commit
a293ea0f2b
17 changed files with 456 additions and 466 deletions
|
|
@ -46,7 +46,7 @@ import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||||
import io.element.android.libraries.designsystem.preview.PreviewWithLargeHeight
|
import io.element.android.libraries.designsystem.preview.PreviewWithLargeHeight
|
||||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||||
import io.element.android.libraries.designsystem.theme.aliasScreenTitle
|
import io.element.android.libraries.designsystem.theme.aliasScreenTitle
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField2
|
import io.element.android.libraries.designsystem.theme.components.TextField
|
||||||
import io.element.android.libraries.designsystem.theme.components.ListItem
|
import io.element.android.libraries.designsystem.theme.components.ListItem
|
||||||
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
||||||
import io.element.android.libraries.designsystem.theme.components.Text
|
import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
|
|
@ -216,7 +216,7 @@ private fun RoomNameWithAvatar(
|
||||||
modifier = Modifier.clickable(onClick = onAvatarClick),
|
modifier = Modifier.clickable(onClick = onAvatarClick),
|
||||||
)
|
)
|
||||||
|
|
||||||
TextField2(
|
TextField(
|
||||||
label = stringResource(R.string.screen_create_room_room_name_label),
|
label = stringResource(R.string.screen_create_room_room_name_label),
|
||||||
value = roomName,
|
value = roomName,
|
||||||
placeholder = stringResource(CommonStrings.common_room_name_placeholder),
|
placeholder = stringResource(CommonStrings.common_room_name_placeholder),
|
||||||
|
|
@ -232,7 +232,7 @@ private fun RoomTopic(
|
||||||
onTopicChange: (String) -> Unit,
|
onTopicChange: (String) -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
TextField2(
|
TextField(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
label = stringResource(R.string.screen_create_room_topic_label),
|
label = stringResource(R.string.screen_create_room_topic_label),
|
||||||
value = topic,
|
value = topic,
|
||||||
|
|
@ -322,7 +322,7 @@ private fun RoomAddressField(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
TextField2(
|
TextField(
|
||||||
modifier = modifier.fillMaxWidth(),
|
modifier = modifier.fillMaxWidth(),
|
||||||
value = address.value,
|
value = address.value,
|
||||||
label = stringResource(R.string.screen_create_room_room_address_section_title),
|
label = stringResource(R.string.screen_create_room_room_address_section_title),
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ import io.element.android.libraries.designsystem.theme.components.Button
|
||||||
import io.element.android.libraries.designsystem.theme.components.Icon
|
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||||
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
||||||
import io.element.android.libraries.designsystem.theme.components.Text
|
import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField2
|
import io.element.android.libraries.designsystem.theme.components.TextField
|
||||||
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
||||||
import io.element.android.libraries.testtags.TestTags
|
import io.element.android.libraries.testtags.TestTags
|
||||||
import io.element.android.libraries.testtags.testTag
|
import io.element.android.libraries.testtags.testTag
|
||||||
|
|
@ -268,7 +268,7 @@ private fun Content(
|
||||||
// Ensure password is hidden when user submits the form
|
// Ensure password is hidden when user submits the form
|
||||||
passwordVisible = false
|
passwordVisible = false
|
||||||
}
|
}
|
||||||
TextField2(
|
TextField(
|
||||||
value = passwordFieldState,
|
value = passwordFieldState,
|
||||||
label = stringResource(CommonStrings.action_confirm_password),
|
label = stringResource(CommonStrings.action_confirm_password),
|
||||||
readOnly = isLoading,
|
readOnly = isLoading,
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ import io.element.android.libraries.designsystem.theme.components.Button
|
||||||
import io.element.android.libraries.designsystem.theme.components.ButtonSize
|
import io.element.android.libraries.designsystem.theme.components.ButtonSize
|
||||||
import io.element.android.libraries.designsystem.theme.components.OutlinedButton
|
import io.element.android.libraries.designsystem.theme.components.OutlinedButton
|
||||||
import io.element.android.libraries.designsystem.theme.components.Text
|
import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField2
|
import io.element.android.libraries.designsystem.theme.components.TextField
|
||||||
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
||||||
import io.element.android.libraries.matrix.api.core.RoomIdOrAlias
|
import io.element.android.libraries.matrix.api.core.RoomIdOrAlias
|
||||||
import io.element.android.libraries.matrix.api.room.RoomType
|
import io.element.android.libraries.matrix.api.room.RoomType
|
||||||
|
|
@ -390,7 +390,7 @@ private fun DefaultLoadedContent(
|
||||||
)
|
)
|
||||||
} else if (contentState.joinAuthorisationStatus is JoinAuthorisationStatus.CanKnock) {
|
} else if (contentState.joinAuthorisationStatus is JoinAuthorisationStatus.CanKnock) {
|
||||||
Spacer(modifier = Modifier.height(24.dp))
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
TextField2(
|
TextField(
|
||||||
value = knockMessage,
|
value = knockMessage,
|
||||||
onValueChange = onKnockMessageUpdate,
|
onValueChange = onKnockMessageUpdate,
|
||||||
maxLines = 3,
|
maxLines = 3,
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||||
import io.element.android.libraries.designsystem.theme.components.Button
|
import io.element.android.libraries.designsystem.theme.components.Button
|
||||||
import io.element.android.libraries.designsystem.theme.components.Icon
|
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||||
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField2
|
import io.element.android.libraries.designsystem.theme.components.TextField
|
||||||
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
||||||
import io.element.android.libraries.testtags.TestTags
|
import io.element.android.libraries.testtags.TestTags
|
||||||
import io.element.android.libraries.testtags.testTag
|
import io.element.android.libraries.testtags.testTag
|
||||||
|
|
@ -169,7 +169,7 @@ private fun LoginForm(
|
||||||
val eventSink = state.eventSink
|
val eventSink = state.eventSink
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
TextField2(
|
TextField(
|
||||||
label = stringResource(R.string.screen_login_form_header),
|
label = stringResource(R.string.screen_login_form_header),
|
||||||
value = loginFieldState,
|
value = loginFieldState,
|
||||||
enabled = !isLoading,
|
enabled = !isLoading,
|
||||||
|
|
@ -221,7 +221,7 @@ private fun LoginForm(
|
||||||
passwordVisible = false
|
passwordVisible = false
|
||||||
}
|
}
|
||||||
Spacer(Modifier.height(20.dp))
|
Spacer(Modifier.height(20.dp))
|
||||||
TextField2(
|
TextField(
|
||||||
value = passwordFieldState,
|
value = passwordFieldState,
|
||||||
enabled = !isLoading,
|
enabled = !isLoading,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||||
import io.element.android.libraries.designsystem.theme.components.CircularProgressIndicator
|
import io.element.android.libraries.designsystem.theme.components.CircularProgressIndicator
|
||||||
import io.element.android.libraries.designsystem.theme.components.Icon
|
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField2
|
import io.element.android.libraries.designsystem.theme.components.TextField
|
||||||
import io.element.android.libraries.testtags.TestTags
|
import io.element.android.libraries.testtags.TestTags
|
||||||
import io.element.android.libraries.testtags.testTag
|
import io.element.android.libraries.testtags.testTag
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
|
|
@ -102,7 +102,7 @@ fun SearchAccountProviderView(
|
||||||
// TextInput
|
// TextInput
|
||||||
var userInputState by textFieldState(stateValue = state.userInput)
|
var userInputState by textFieldState(stateValue = state.userInput)
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
TextField2(
|
TextField(
|
||||||
value = userInputState,
|
value = userInputState,
|
||||||
// readOnly = isLoading,
|
// readOnly = isLoading,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ import io.element.android.libraries.designsystem.theme.aliasScreenTitle
|
||||||
import io.element.android.libraries.designsystem.theme.components.Button
|
import io.element.android.libraries.designsystem.theme.components.Button
|
||||||
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
||||||
import io.element.android.libraries.designsystem.theme.components.Text
|
import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField2
|
import io.element.android.libraries.designsystem.theme.components.TextField
|
||||||
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
|
|
||||||
|
|
@ -88,7 +88,7 @@ fun ReportMessageView(
|
||||||
) {
|
) {
|
||||||
Spacer(modifier = Modifier.height(20.dp))
|
Spacer(modifier = Modifier.height(20.dp))
|
||||||
|
|
||||||
TextField2(
|
TextField(
|
||||||
value = state.reason,
|
value = state.reason,
|
||||||
onValueChange = { state.eventSink(ReportMessageEvents.UpdateReason(it)) },
|
onValueChange = { state.eventSink(ReportMessageEvents.UpdateReason(it)) },
|
||||||
placeholder = stringResource(R.string.screen_report_content_hint),
|
placeholder = stringResource(R.string.screen_report_content_hint),
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ import io.element.android.libraries.designsystem.theme.components.ListItemStyle
|
||||||
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
||||||
import io.element.android.libraries.designsystem.theme.components.Text
|
import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextButton
|
import io.element.android.libraries.designsystem.theme.components.TextButton
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField2
|
import io.element.android.libraries.designsystem.theme.components.TextField
|
||||||
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
||||||
import io.element.android.libraries.matrix.api.poll.PollKind
|
import io.element.android.libraries.matrix.api.poll.PollKind
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
|
|
@ -110,7 +110,7 @@ fun CreatePollView(
|
||||||
Column {
|
Column {
|
||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = {
|
headlineContent = {
|
||||||
TextField2(
|
TextField(
|
||||||
label = stringResource(id = R.string.screen_create_poll_question_desc),
|
label = stringResource(id = R.string.screen_create_poll_question_desc),
|
||||||
value = state.question,
|
value = state.question,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
|
|
@ -130,7 +130,7 @@ fun CreatePollView(
|
||||||
val isLastItem = index == state.answers.size - 1
|
val isLastItem = index == state.answers.size - 1
|
||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = {
|
headlineContent = {
|
||||||
TextField2(
|
TextField(
|
||||||
value = answer.text,
|
value = answer.text,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
state.eventSink(CreatePollEvents.SetAnswer(index, it))
|
state.eventSink(CreatePollEvents.SetAnswer(index, it))
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ import io.element.android.libraries.designsystem.theme.aliasScreenTitle
|
||||||
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
||||||
import io.element.android.libraries.designsystem.theme.components.Text
|
import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextButton
|
import io.element.android.libraries.designsystem.theme.components.TextButton
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField2
|
import io.element.android.libraries.designsystem.theme.components.TextField
|
||||||
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
||||||
import io.element.android.libraries.matrix.ui.components.AvatarActionBottomSheet
|
import io.element.android.libraries.matrix.ui.components.AvatarActionBottomSheet
|
||||||
import io.element.android.libraries.matrix.ui.components.EditableAvatarView
|
import io.element.android.libraries.matrix.ui.components.EditableAvatarView
|
||||||
|
|
@ -112,7 +112,7 @@ fun EditUserProfileView(
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(40.dp))
|
Spacer(modifier = Modifier.height(40.dp))
|
||||||
TextField2(
|
TextField(
|
||||||
label = stringResource(R.string.screen_edit_profile_display_name),
|
label = stringResource(R.string.screen_edit_profile_display_name),
|
||||||
value = state.displayName,
|
value = state.displayName,
|
||||||
placeholder = stringResource(CommonStrings.common_room_name_placeholder),
|
placeholder = stringResource(CommonStrings.common_room_name_placeholder),
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||||
import io.element.android.libraries.designsystem.preview.debugPlaceholderBackground
|
import io.element.android.libraries.designsystem.preview.debugPlaceholderBackground
|
||||||
import io.element.android.libraries.designsystem.theme.components.Button
|
import io.element.android.libraries.designsystem.theme.components.Button
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField2
|
import io.element.android.libraries.designsystem.theme.components.TextField
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
@ -69,7 +69,7 @@ fun BugReportView(
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
PreferenceRow {
|
PreferenceRow {
|
||||||
TextField2(
|
TextField(
|
||||||
value = descriptionFieldState,
|
value = descriptionFieldState,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ import io.element.android.libraries.designsystem.theme.aliasScreenTitle
|
||||||
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
||||||
import io.element.android.libraries.designsystem.theme.components.Text
|
import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextButton
|
import io.element.android.libraries.designsystem.theme.components.TextButton
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField2
|
import io.element.android.libraries.designsystem.theme.components.TextField
|
||||||
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
||||||
import io.element.android.libraries.matrix.ui.components.AvatarActionBottomSheet
|
import io.element.android.libraries.matrix.ui.components.AvatarActionBottomSheet
|
||||||
import io.element.android.libraries.matrix.ui.components.EditableAvatarView
|
import io.element.android.libraries.matrix.ui.components.EditableAvatarView
|
||||||
|
|
@ -108,7 +108,7 @@ fun RoomDetailsEditView(
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(60.dp))
|
Spacer(modifier = Modifier.height(60.dp))
|
||||||
|
|
||||||
TextField2(
|
TextField(
|
||||||
label = stringResource(id = R.string.screen_room_details_room_name_label),
|
label = stringResource(id = R.string.screen_room_details_room_name_label),
|
||||||
value = state.roomRawName,
|
value = state.roomRawName,
|
||||||
placeholder = stringResource(CommonStrings.common_room_name_placeholder),
|
placeholder = stringResource(CommonStrings.common_room_name_placeholder),
|
||||||
|
|
@ -119,7 +119,7 @@ fun RoomDetailsEditView(
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(28.dp))
|
Spacer(modifier = Modifier.height(28.dp))
|
||||||
|
|
||||||
TextField2(
|
TextField(
|
||||||
label = stringResource(CommonStrings.common_topic),
|
label = stringResource(CommonStrings.common_topic),
|
||||||
value = state.roomTopic,
|
value = state.roomTopic,
|
||||||
placeholder = stringResource(CommonStrings.common_topic_placeholder),
|
placeholder = stringResource(CommonStrings.common_topic_placeholder),
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ import io.element.android.libraries.designsystem.theme.components.Icon
|
||||||
import io.element.android.libraries.designsystem.theme.components.IconButton
|
import io.element.android.libraries.designsystem.theme.components.IconButton
|
||||||
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
||||||
import io.element.android.libraries.designsystem.theme.components.Text
|
import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField
|
import io.element.android.libraries.designsystem.theme.components.FilledTextField
|
||||||
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
||||||
import io.element.android.libraries.testtags.TestTags
|
import io.element.android.libraries.testtags.TestTags
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
|
|
@ -194,7 +194,7 @@ private fun SearchTextField(
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
TextField(
|
FilledTextField(
|
||||||
modifier = modifier.testTag(TestTags.searchTextField.value),
|
modifier = modifier.testTag(TestTags.searchTextField.value),
|
||||||
textStyle = ElementTheme.typography.fontBodyLgRegular,
|
textStyle = ElementTheme.typography.fontBodyLgRegular,
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ import io.element.android.libraries.designsystem.theme.components.Icon
|
||||||
import io.element.android.libraries.designsystem.theme.components.IconButton
|
import io.element.android.libraries.designsystem.theme.components.IconButton
|
||||||
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
||||||
import io.element.android.libraries.designsystem.theme.components.Text
|
import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField
|
import io.element.android.libraries.designsystem.theme.components.FilledTextField
|
||||||
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
||||||
import io.element.android.libraries.designsystem.utils.copy
|
import io.element.android.libraries.designsystem.utils.copy
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
|
|
@ -130,7 +130,7 @@ private fun RoomListSearchContent(
|
||||||
title = {
|
title = {
|
||||||
val filter = state.query
|
val filter = state.query
|
||||||
val focusRequester = FocusRequester()
|
val focusRequester = FocusRequester()
|
||||||
TextField(
|
FilledTextField(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.focusRequester(focusRequester),
|
.focusRequester(focusRequester),
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||||
import io.element.android.libraries.designsystem.theme.components.Button
|
import io.element.android.libraries.designsystem.theme.components.Button
|
||||||
import io.element.android.libraries.designsystem.theme.components.Icon
|
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField2
|
import io.element.android.libraries.designsystem.theme.components.TextField
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
@ -80,7 +80,7 @@ fun ResetIdentityPasswordView(
|
||||||
@Composable
|
@Composable
|
||||||
private fun Content(text: String, onTextChange: (String) -> Unit, hasError: Boolean) {
|
private fun Content(text: String, onTextChange: (String) -> Unit, hasError: Boolean) {
|
||||||
var showPassword by remember { mutableStateOf(false) }
|
var showPassword by remember { mutableStateOf(false) }
|
||||||
TextField2(
|
TextField(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.onTabOrEnterKeyFocusNext(LocalFocusManager.current),
|
.onTabOrEnterKeyFocusNext(LocalFocusManager.current),
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||||
import io.element.android.libraries.designsystem.theme.components.CircularProgressIndicator
|
import io.element.android.libraries.designsystem.theme.components.CircularProgressIndicator
|
||||||
import io.element.android.libraries.designsystem.theme.components.Icon
|
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||||
import io.element.android.libraries.designsystem.theme.components.Text
|
import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
import io.element.android.libraries.designsystem.theme.components.TextField2
|
import io.element.android.libraries.designsystem.theme.components.TextField
|
||||||
import io.element.android.libraries.testtags.TestTags
|
import io.element.android.libraries.testtags.TestTags
|
||||||
import io.element.android.libraries.testtags.testTag
|
import io.element.android.libraries.testtags.testTag
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
|
|
@ -158,7 +158,7 @@ private fun RecoveryKeyFormContent(
|
||||||
// Do not apply a visual transformation if the key has spaces, to let user enter passphrase
|
// Do not apply a visual transformation if the key has spaces, to let user enter passphrase
|
||||||
if (keyHasSpace) VisualTransformation.None else RecoveryKeyVisualTransformation()
|
if (keyHasSpace) VisualTransformation.None else RecoveryKeyVisualTransformation()
|
||||||
}
|
}
|
||||||
TextField2(
|
TextField(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.testTag(TestTags.recoveryKey)
|
.testTag(TestTags.recoveryKey)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,202 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023, 2024 New Vector Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
* Please see LICENSE in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.designsystem.theme.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
|
import androidx.compose.material3.LocalTextStyle
|
||||||
|
import androidx.compose.material3.TextFieldColors
|
||||||
|
import androidx.compose.material3.TextFieldDefaults
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Shape
|
||||||
|
import androidx.compose.ui.text.TextRange
|
||||||
|
import androidx.compose.ui.text.TextStyle
|
||||||
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
|
import androidx.compose.ui.text.input.VisualTransformation
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import io.element.android.compound.theme.ElementTheme
|
||||||
|
import io.element.android.libraries.architecture.coverage.ExcludeFromCoverage
|
||||||
|
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||||
|
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||||
|
import io.element.android.libraries.designsystem.preview.PreviewGroup
|
||||||
|
import io.element.android.libraries.designsystem.utils.allBooleans
|
||||||
|
import io.element.android.libraries.designsystem.utils.asInt
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun FilledTextField(
|
||||||
|
value: String,
|
||||||
|
onValueChange: (String) -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
readOnly: Boolean = false,
|
||||||
|
textStyle: TextStyle = LocalTextStyle.current,
|
||||||
|
label: @Composable (() -> Unit)? = null,
|
||||||
|
placeholder: @Composable (() -> Unit)? = null,
|
||||||
|
leadingIcon: @Composable (() -> Unit)? = null,
|
||||||
|
trailingIcon: @Composable (() -> Unit)? = null,
|
||||||
|
supportingText: @Composable (() -> Unit)? = null,
|
||||||
|
isError: Boolean = false,
|
||||||
|
visualTransformation: VisualTransformation = VisualTransformation.None,
|
||||||
|
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
|
||||||
|
keyboardActions: KeyboardActions = KeyboardActions.Default,
|
||||||
|
singleLine: Boolean = false,
|
||||||
|
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
|
||||||
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||||
|
shape: Shape = TextFieldDefaults.shape,
|
||||||
|
colors: TextFieldColors = TextFieldDefaults.colors(
|
||||||
|
unfocusedContainerColor = ElementTheme.colors.bgSubtleSecondary,
|
||||||
|
focusedContainerColor = ElementTheme.colors.bgSubtleSecondary,
|
||||||
|
disabledContainerColor = ElementTheme.colors.bgSubtleSecondary,
|
||||||
|
errorContainerColor = ElementTheme.colors.bgSubtleSecondary,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
androidx.compose.material3.TextField(
|
||||||
|
value = value,
|
||||||
|
onValueChange = onValueChange,
|
||||||
|
modifier = modifier,
|
||||||
|
enabled = enabled,
|
||||||
|
readOnly = readOnly,
|
||||||
|
textStyle = textStyle,
|
||||||
|
label = label,
|
||||||
|
placeholder = placeholder,
|
||||||
|
leadingIcon = leadingIcon,
|
||||||
|
trailingIcon = trailingIcon,
|
||||||
|
supportingText = supportingText,
|
||||||
|
isError = isError,
|
||||||
|
visualTransformation = visualTransformation,
|
||||||
|
keyboardOptions = keyboardOptions,
|
||||||
|
keyboardActions = keyboardActions,
|
||||||
|
singleLine = singleLine,
|
||||||
|
maxLines = maxLines,
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
shape = shape,
|
||||||
|
colors = colors,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun FilledTextField(
|
||||||
|
value: TextFieldValue,
|
||||||
|
onValueChange: (TextFieldValue) -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
readOnly: Boolean = false,
|
||||||
|
textStyle: TextStyle = LocalTextStyle.current,
|
||||||
|
label: @Composable (() -> Unit)? = null,
|
||||||
|
placeholder: @Composable (() -> Unit)? = null,
|
||||||
|
leadingIcon: @Composable (() -> Unit)? = null,
|
||||||
|
trailingIcon: @Composable (() -> Unit)? = null,
|
||||||
|
supportingText: @Composable (() -> Unit)? = null,
|
||||||
|
isError: Boolean = false,
|
||||||
|
visualTransformation: VisualTransformation = VisualTransformation.None,
|
||||||
|
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
|
||||||
|
keyboardActions: KeyboardActions = KeyboardActions.Default,
|
||||||
|
singleLine: Boolean = false,
|
||||||
|
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
|
||||||
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||||
|
shape: Shape = TextFieldDefaults.shape,
|
||||||
|
colors: TextFieldColors = TextFieldDefaults.colors()
|
||||||
|
) {
|
||||||
|
androidx.compose.material3.TextField(
|
||||||
|
value = value,
|
||||||
|
onValueChange = onValueChange,
|
||||||
|
modifier = modifier,
|
||||||
|
enabled = enabled,
|
||||||
|
readOnly = readOnly,
|
||||||
|
textStyle = textStyle,
|
||||||
|
label = label,
|
||||||
|
placeholder = placeholder,
|
||||||
|
leadingIcon = leadingIcon,
|
||||||
|
trailingIcon = trailingIcon,
|
||||||
|
supportingText = supportingText,
|
||||||
|
isError = isError,
|
||||||
|
visualTransformation = visualTransformation,
|
||||||
|
keyboardOptions = keyboardOptions,
|
||||||
|
keyboardActions = keyboardActions,
|
||||||
|
singleLine = singleLine,
|
||||||
|
maxLines = maxLines,
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
shape = shape,
|
||||||
|
colors = colors,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(group = PreviewGroup.TextFields)
|
||||||
|
@Composable
|
||||||
|
internal fun FilledTextFieldLightPreview() =
|
||||||
|
ElementPreviewLight { ContentToPreview() }
|
||||||
|
|
||||||
|
@Preview(group = PreviewGroup.TextFields)
|
||||||
|
@Composable
|
||||||
|
internal fun FilledTextFieldDarkPreview() =
|
||||||
|
ElementPreviewDark { ContentToPreview() }
|
||||||
|
|
||||||
|
@ExcludeFromCoverage
|
||||||
|
@Composable
|
||||||
|
private fun ContentToPreview() {
|
||||||
|
Column(modifier = Modifier.padding(4.dp)) {
|
||||||
|
allBooleans.forEach { isError ->
|
||||||
|
allBooleans.forEach { enabled ->
|
||||||
|
allBooleans.forEach { readonly ->
|
||||||
|
FilledTextField(
|
||||||
|
value = "Hello er=${isError.asInt()}, en=${enabled.asInt()}, ro=${readonly.asInt()}",
|
||||||
|
onValueChange = {},
|
||||||
|
label = { Text(text = "label") },
|
||||||
|
isError = isError,
|
||||||
|
enabled = enabled,
|
||||||
|
readOnly = readonly,
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.height(2.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(group = PreviewGroup.TextFields)
|
||||||
|
@Composable
|
||||||
|
internal fun FilledTextFieldValueLightPreview() =
|
||||||
|
ElementPreviewLight { FilledTextFieldValueContentToPreview() }
|
||||||
|
|
||||||
|
@Preview(group = PreviewGroup.TextFields)
|
||||||
|
@Composable
|
||||||
|
internal fun FilledTextFieldValueTextFieldDarkPreview() =
|
||||||
|
ElementPreviewDark { FilledTextFieldValueContentToPreview() }
|
||||||
|
|
||||||
|
@ExcludeFromCoverage
|
||||||
|
@Composable
|
||||||
|
private fun FilledTextFieldValueContentToPreview() {
|
||||||
|
Column(modifier = Modifier.padding(4.dp)) {
|
||||||
|
allBooleans.forEach { isError ->
|
||||||
|
allBooleans.forEach { enabled ->
|
||||||
|
allBooleans.forEach { readonly ->
|
||||||
|
FilledTextField(
|
||||||
|
value = TextFieldValue(
|
||||||
|
text = "Hello er=${isError.asInt()}, en=${enabled.asInt()}, ro=${readonly.asInt()}",
|
||||||
|
selection = TextRange(0, "Hello".length),
|
||||||
|
),
|
||||||
|
onValueChange = {},
|
||||||
|
label = { Text(text = "label") },
|
||||||
|
isError = isError,
|
||||||
|
enabled = enabled,
|
||||||
|
readOnly = readonly,
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.height(2.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,36 +7,37 @@
|
||||||
|
|
||||||
package io.element.android.libraries.designsystem.theme.components
|
package io.element.android.libraries.designsystem.theme.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
|
import androidx.compose.foundation.interaction.collectIsFocusedAsState
|
||||||
|
import androidx.compose.foundation.layout.Arrangement.Absolute.spacedBy
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.text.BasicTextField
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material3.LocalTextStyle
|
import androidx.compose.material3.LocalContentColor
|
||||||
import androidx.compose.material3.TextFieldColors
|
|
||||||
import androidx.compose.material3.TextFieldDefaults
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.autofill.AutofillNode
|
import androidx.compose.ui.graphics.SolidColor
|
||||||
import androidx.compose.ui.autofill.AutofillType
|
import androidx.compose.ui.text.TextLayoutResult
|
||||||
import androidx.compose.ui.composed
|
|
||||||
import androidx.compose.ui.focus.onFocusChanged
|
|
||||||
import androidx.compose.ui.graphics.Shape
|
|
||||||
import androidx.compose.ui.layout.boundsInWindow
|
|
||||||
import androidx.compose.ui.layout.onGloballyPositioned
|
|
||||||
import androidx.compose.ui.platform.LocalAutofill
|
|
||||||
import androidx.compose.ui.platform.LocalAutofillTree
|
|
||||||
import androidx.compose.ui.text.TextRange
|
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
import androidx.compose.ui.text.input.VisualTransformation
|
import androidx.compose.ui.text.input.VisualTransformation
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import io.element.android.compound.theme.ElementTheme
|
import io.element.android.compound.theme.ElementTheme
|
||||||
|
import io.element.android.compound.tokens.generated.CompoundIcons
|
||||||
import io.element.android.libraries.architecture.coverage.ExcludeFromCoverage
|
import io.element.android.libraries.architecture.coverage.ExcludeFromCoverage
|
||||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||||
|
|
@ -44,161 +45,265 @@ import io.element.android.libraries.designsystem.preview.PreviewGroup
|
||||||
import io.element.android.libraries.designsystem.utils.allBooleans
|
import io.element.android.libraries.designsystem.utils.allBooleans
|
||||||
import io.element.android.libraries.designsystem.utils.asInt
|
import io.element.android.libraries.designsystem.utils.asInt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://www.figma.com/design/G1xy0HDZKJf5TCRFmKb5d5/Compound-Android-Components?node-id=2008-37137
|
||||||
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun TextField(
|
fun TextField(
|
||||||
value: String,
|
value: String,
|
||||||
onValueChange: (String) -> Unit,
|
onValueChange: (String) -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
label: String? = null,
|
||||||
enabled: Boolean = true,
|
supportingText: String? = null,
|
||||||
readOnly: Boolean = false,
|
placeholder: String? = null,
|
||||||
textStyle: TextStyle = LocalTextStyle.current,
|
|
||||||
label: @Composable (() -> Unit)? = null,
|
|
||||||
placeholder: @Composable (() -> Unit)? = null,
|
|
||||||
leadingIcon: @Composable (() -> Unit)? = null,
|
leadingIcon: @Composable (() -> Unit)? = null,
|
||||||
trailingIcon: @Composable (() -> Unit)? = null,
|
trailingIcon: @Composable (() -> Unit)? = null,
|
||||||
supportingText: @Composable (() -> Unit)? = null,
|
|
||||||
isError: Boolean = false,
|
isError: Boolean = false,
|
||||||
visualTransformation: VisualTransformation = VisualTransformation.None,
|
enabled: Boolean = true,
|
||||||
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
|
readOnly: Boolean = false,
|
||||||
keyboardActions: KeyboardActions = KeyboardActions.Default,
|
|
||||||
singleLine: Boolean = false,
|
singleLine: Boolean = false,
|
||||||
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
|
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
|
||||||
|
minLines: Int = 1,
|
||||||
|
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
|
||||||
|
keyboardActions: KeyboardActions = KeyboardActions.Default,
|
||||||
|
visualTransformation: VisualTransformation = VisualTransformation.None,
|
||||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||||
shape: Shape = TextFieldDefaults.shape,
|
onTextLayout: (TextLayoutResult) -> Unit = {},
|
||||||
colors: TextFieldColors = TextFieldDefaults.colors(
|
modifier: Modifier = Modifier
|
||||||
unfocusedContainerColor = ElementTheme.colors.bgSubtleSecondary,
|
|
||||||
focusedContainerColor = ElementTheme.colors.bgSubtleSecondary,
|
|
||||||
disabledContainerColor = ElementTheme.colors.bgSubtleSecondary,
|
|
||||||
errorContainerColor = ElementTheme.colors.bgSubtleSecondary,
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
androidx.compose.material3.TextField(
|
val isFocused by interactionSource.collectIsFocusedAsState()
|
||||||
|
BasicTextField(
|
||||||
value = value,
|
value = value,
|
||||||
onValueChange = onValueChange,
|
onValueChange = onValueChange,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
|
textStyle = textFieldStyle(enabled),
|
||||||
|
interactionSource = interactionSource,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
readOnly = readOnly,
|
|
||||||
textStyle = textStyle,
|
|
||||||
label = label,
|
|
||||||
placeholder = placeholder,
|
|
||||||
leadingIcon = leadingIcon,
|
|
||||||
trailingIcon = trailingIcon,
|
|
||||||
supportingText = supportingText,
|
|
||||||
isError = isError,
|
|
||||||
visualTransformation = visualTransformation,
|
|
||||||
keyboardOptions = keyboardOptions,
|
|
||||||
keyboardActions = keyboardActions,
|
|
||||||
singleLine = singleLine,
|
singleLine = singleLine,
|
||||||
maxLines = maxLines,
|
maxLines = maxLines,
|
||||||
interactionSource = interactionSource,
|
minLines = minLines,
|
||||||
shape = shape,
|
readOnly = readOnly,
|
||||||
colors = colors,
|
cursorBrush = SolidColor(ElementTheme.colors.textPrimary),
|
||||||
)
|
keyboardOptions = keyboardOptions,
|
||||||
|
keyboardActions = keyboardActions,
|
||||||
|
visualTransformation = visualTransformation,
|
||||||
|
onTextLayout = onTextLayout,
|
||||||
|
) { innerTextField ->
|
||||||
|
DecorationBox(
|
||||||
|
label = label,
|
||||||
|
readOnly = readOnly,
|
||||||
|
enabled = enabled,
|
||||||
|
isFocused = isFocused,
|
||||||
|
isError = isError,
|
||||||
|
leadingIcon = leadingIcon,
|
||||||
|
placeholder = placeholder,
|
||||||
|
isTextEmpty = value.isEmpty(),
|
||||||
|
innerTextField = innerTextField,
|
||||||
|
trailingIcon = trailingIcon,
|
||||||
|
supportingText = supportingText
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TextField(
|
fun TextField(
|
||||||
value: TextFieldValue,
|
value: TextFieldValue,
|
||||||
onValueChange: (TextFieldValue) -> Unit,
|
onValueChange: (TextFieldValue) -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
label: String? = null,
|
||||||
enabled: Boolean = true,
|
supportingText: String? = null,
|
||||||
readOnly: Boolean = false,
|
placeholder: String? = null,
|
||||||
textStyle: TextStyle = LocalTextStyle.current,
|
|
||||||
label: @Composable (() -> Unit)? = null,
|
|
||||||
placeholder: @Composable (() -> Unit)? = null,
|
|
||||||
leadingIcon: @Composable (() -> Unit)? = null,
|
leadingIcon: @Composable (() -> Unit)? = null,
|
||||||
trailingIcon: @Composable (() -> Unit)? = null,
|
trailingIcon: @Composable (() -> Unit)? = null,
|
||||||
supportingText: @Composable (() -> Unit)? = null,
|
|
||||||
isError: Boolean = false,
|
isError: Boolean = false,
|
||||||
visualTransformation: VisualTransformation = VisualTransformation.None,
|
enabled: Boolean = true,
|
||||||
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
|
readOnly: Boolean = false,
|
||||||
keyboardActions: KeyboardActions = KeyboardActions.Default,
|
|
||||||
singleLine: Boolean = false,
|
singleLine: Boolean = false,
|
||||||
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
|
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
|
||||||
|
minLines: Int = 1,
|
||||||
|
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
|
||||||
|
keyboardActions: KeyboardActions = KeyboardActions.Default,
|
||||||
|
visualTransformation: VisualTransformation = VisualTransformation.None,
|
||||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||||
shape: Shape = TextFieldDefaults.shape,
|
onTextLayout: (TextLayoutResult) -> Unit = {},
|
||||||
colors: TextFieldColors = TextFieldDefaults.colors()
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
androidx.compose.material3.TextField(
|
val isFocused by interactionSource.collectIsFocusedAsState()
|
||||||
|
BasicTextField(
|
||||||
value = value,
|
value = value,
|
||||||
onValueChange = onValueChange,
|
onValueChange = onValueChange,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
|
textStyle = textFieldStyle(enabled),
|
||||||
|
interactionSource = interactionSource,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
readOnly = readOnly,
|
|
||||||
textStyle = textStyle,
|
|
||||||
label = label,
|
|
||||||
placeholder = placeholder,
|
|
||||||
leadingIcon = leadingIcon,
|
|
||||||
trailingIcon = trailingIcon,
|
|
||||||
supportingText = supportingText,
|
|
||||||
isError = isError,
|
|
||||||
visualTransformation = visualTransformation,
|
|
||||||
keyboardOptions = keyboardOptions,
|
|
||||||
keyboardActions = keyboardActions,
|
|
||||||
singleLine = singleLine,
|
singleLine = singleLine,
|
||||||
maxLines = maxLines,
|
maxLines = maxLines,
|
||||||
interactionSource = interactionSource,
|
minLines = minLines,
|
||||||
shape = shape,
|
readOnly = readOnly,
|
||||||
colors = colors,
|
cursorBrush = SolidColor(ElementTheme.colors.textPrimary),
|
||||||
|
keyboardOptions = keyboardOptions,
|
||||||
|
keyboardActions = keyboardActions,
|
||||||
|
visualTransformation = visualTransformation,
|
||||||
|
onTextLayout = onTextLayout,
|
||||||
|
) { innerTextField ->
|
||||||
|
DecorationBox(
|
||||||
|
label = label,
|
||||||
|
readOnly = readOnly,
|
||||||
|
enabled = enabled,
|
||||||
|
isFocused = isFocused,
|
||||||
|
isError = isError,
|
||||||
|
leadingIcon = leadingIcon,
|
||||||
|
placeholder = placeholder,
|
||||||
|
isTextEmpty = value.text.isEmpty(),
|
||||||
|
innerTextField = innerTextField,
|
||||||
|
trailingIcon = trailingIcon,
|
||||||
|
supportingText = supportingText
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun DecorationBox(
|
||||||
|
label: String?,
|
||||||
|
enabled: Boolean,
|
||||||
|
readOnly: Boolean,
|
||||||
|
isFocused: Boolean,
|
||||||
|
isError: Boolean,
|
||||||
|
placeholder: String?,
|
||||||
|
isTextEmpty: Boolean,
|
||||||
|
supportingText: String?,
|
||||||
|
leadingIcon: @Composable (() -> Unit)?,
|
||||||
|
trailingIcon: @Composable (() -> Unit)?,
|
||||||
|
innerTextField: @Composable () -> Unit,
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
if (label != null) {
|
||||||
|
Text(
|
||||||
|
text = label,
|
||||||
|
color = ElementTheme.colors.textPrimary,
|
||||||
|
style = ElementTheme.typography.fontBodyMdRegular,
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
}
|
||||||
|
TextFieldContainer(
|
||||||
|
enabled = enabled,
|
||||||
|
readOnly = readOnly,
|
||||||
|
isFocused = isFocused,
|
||||||
|
isError = isError
|
||||||
|
) {
|
||||||
|
Row(modifier = Modifier.padding(16.dp)) {
|
||||||
|
if (leadingIcon != null) {
|
||||||
|
CompositionLocalProvider(LocalContentColor provides ElementTheme.colors.iconSecondary) {
|
||||||
|
leadingIcon()
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
}
|
||||||
|
Box(modifier = Modifier.weight(1f)) {
|
||||||
|
if (placeholder != null && isTextEmpty) {
|
||||||
|
Text(
|
||||||
|
text = placeholder,
|
||||||
|
color = ElementTheme.colors.textPlaceholder,
|
||||||
|
style = ElementTheme.typography.fontBodyLgRegular,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
innerTextField()
|
||||||
|
}
|
||||||
|
if (trailingIcon != null) {
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
CompositionLocalProvider(LocalContentColor provides ElementTheme.colors.iconSecondary) {
|
||||||
|
trailingIcon()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (supportingText != null) {
|
||||||
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
|
SupportingTextLayout(isError, supportingText)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun TextFieldContainer(
|
||||||
|
enabled: Boolean,
|
||||||
|
readOnly: Boolean,
|
||||||
|
isFocused: Boolean,
|
||||||
|
isError: Boolean,
|
||||||
|
content: @Composable () -> Unit
|
||||||
|
) {
|
||||||
|
Surface(
|
||||||
|
shape = RoundedCornerShape(4.dp),
|
||||||
|
border = if (readOnly) {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
BorderStroke(
|
||||||
|
width = if (isFocused) 2.dp else 1.dp,
|
||||||
|
color = when {
|
||||||
|
!enabled -> ElementTheme.colors.borderDisabled
|
||||||
|
isError -> ElementTheme.colors.borderCriticalPrimary
|
||||||
|
isFocused -> ElementTheme.colors.borderInteractiveHovered
|
||||||
|
else -> ElementTheme.colors.borderInteractiveSecondary
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
color = when {
|
||||||
|
readOnly -> ElementTheme.colors.bgSubtleSecondary
|
||||||
|
!enabled -> ElementTheme.colors.bgCanvasDisabled
|
||||||
|
else -> ElementTheme.colors.bgCanvasDefault
|
||||||
|
},
|
||||||
|
content = content
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun SupportingTextLayout(isError: Boolean, supportingText: String) {
|
||||||
|
Row(horizontalArrangement = spacedBy(4.dp)) {
|
||||||
|
if (isError) {
|
||||||
|
Icon(
|
||||||
|
imageVector = CompoundIcons.Error(),
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(16.dp),
|
||||||
|
tint = ElementTheme.colors.iconCriticalPrimary
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
text = supportingText,
|
||||||
|
color = if (isError) ElementTheme.colors.textCriticalPrimary else ElementTheme.colors.textSecondary,
|
||||||
|
style = ElementTheme.typography.fontBodySmRegular,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun textFieldStyle(enabled: Boolean): TextStyle {
|
||||||
|
return ElementTheme.typography.fontBodyLgRegular.copy(
|
||||||
|
color = if (enabled) {
|
||||||
|
ElementTheme.colors.textPrimary
|
||||||
|
} else {
|
||||||
|
ElementTheme.colors.textSecondary
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview(group = PreviewGroup.TextFields)
|
@Preview(group = PreviewGroup.TextFields)
|
||||||
@Composable
|
@Composable
|
||||||
internal fun TextFieldLightPreview() =
|
internal fun TextFieldsLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||||
ElementPreviewLight { ContentToPreview() }
|
|
||||||
|
|
||||||
@Preview(group = PreviewGroup.TextFields)
|
@Preview(group = PreviewGroup.TextFields)
|
||||||
@Composable
|
@Composable
|
||||||
internal fun TextFieldDarkPreview() =
|
internal fun TextFieldsDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||||
ElementPreviewDark { ContentToPreview() }
|
|
||||||
|
|
||||||
@ExcludeFromCoverage
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ExcludeFromCoverage
|
||||||
private fun ContentToPreview() {
|
private fun ContentToPreview() {
|
||||||
Column(modifier = Modifier.padding(4.dp)) {
|
Column(modifier = Modifier.padding(4.dp)) {
|
||||||
allBooleans.forEach { isError ->
|
allBooleans.forEach { isError ->
|
||||||
allBooleans.forEach { enabled ->
|
allBooleans.forEach { enabled ->
|
||||||
allBooleans.forEach { readonly ->
|
allBooleans.forEach { readonly ->
|
||||||
TextField(
|
TextField(
|
||||||
|
onValueChange = {},
|
||||||
|
label = "Label",
|
||||||
value = "Hello er=${isError.asInt()}, en=${enabled.asInt()}, ro=${readonly.asInt()}",
|
value = "Hello er=${isError.asInt()}, en=${enabled.asInt()}, ro=${readonly.asInt()}",
|
||||||
onValueChange = {},
|
supportingText = "Supporting text",
|
||||||
label = { Text(text = "label") },
|
|
||||||
isError = isError,
|
|
||||||
enabled = enabled,
|
|
||||||
readOnly = readonly,
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(2.dp))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Preview(group = PreviewGroup.TextFields)
|
|
||||||
@Composable
|
|
||||||
internal fun TextFieldValueLightPreview() =
|
|
||||||
ElementPreviewLight { TextFieldValueContentToPreview() }
|
|
||||||
|
|
||||||
@Preview(group = PreviewGroup.TextFields)
|
|
||||||
@Composable
|
|
||||||
internal fun TextFieldValueTextFieldDarkPreview() =
|
|
||||||
ElementPreviewDark { TextFieldValueContentToPreview() }
|
|
||||||
|
|
||||||
@ExcludeFromCoverage
|
|
||||||
@Composable
|
|
||||||
private fun TextFieldValueContentToPreview() {
|
|
||||||
Column(modifier = Modifier.padding(4.dp)) {
|
|
||||||
allBooleans.forEach { isError ->
|
|
||||||
allBooleans.forEach { enabled ->
|
|
||||||
allBooleans.forEach { readonly ->
|
|
||||||
TextField(
|
|
||||||
value = TextFieldValue(
|
|
||||||
text = "Hello er=${isError.asInt()}, en=${enabled.asInt()}, ro=${readonly.asInt()}",
|
|
||||||
selection = TextRange(0, "Hello".length),
|
|
||||||
),
|
|
||||||
onValueChange = {},
|
|
||||||
label = { Text(text = "label") },
|
|
||||||
isError = isError,
|
isError = isError,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
readOnly = readonly,
|
readOnly = readonly,
|
||||||
|
|
|
||||||
|
|
@ -1,317 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2023, 2024 New Vector Ltd.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
* Please see LICENSE in the repository root for full details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.element.android.libraries.designsystem.theme.components
|
|
||||||
|
|
||||||
import androidx.compose.foundation.BorderStroke
|
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
||||||
import androidx.compose.foundation.interaction.collectIsFocusedAsState
|
|
||||||
import androidx.compose.foundation.layout.Arrangement.Absolute.spacedBy
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.foundation.text.BasicTextField
|
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
|
||||||
import androidx.compose.material3.LocalContentColor
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.CompositionLocalProvider
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.graphics.SolidColor
|
|
||||||
import androidx.compose.ui.text.TextLayoutResult
|
|
||||||
import androidx.compose.ui.text.TextStyle
|
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
|
||||||
import androidx.compose.ui.text.input.VisualTransformation
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import io.element.android.compound.theme.ElementTheme
|
|
||||||
import io.element.android.compound.tokens.generated.CompoundIcons
|
|
||||||
import io.element.android.libraries.architecture.coverage.ExcludeFromCoverage
|
|
||||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
|
||||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
|
||||||
import io.element.android.libraries.designsystem.preview.PreviewGroup
|
|
||||||
import io.element.android.libraries.designsystem.utils.allBooleans
|
|
||||||
import io.element.android.libraries.designsystem.utils.asInt
|
|
||||||
|
|
||||||
/**
|
|
||||||
* https://www.figma.com/design/G1xy0HDZKJf5TCRFmKb5d5/Compound-Android-Components?node-id=2008-37137
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun TextField2(
|
|
||||||
value: String,
|
|
||||||
onValueChange: (String) -> Unit,
|
|
||||||
label: String? = null,
|
|
||||||
supportingText: String? = null,
|
|
||||||
placeholder: String? = null,
|
|
||||||
leadingIcon: @Composable (() -> Unit)? = null,
|
|
||||||
trailingIcon: @Composable (() -> Unit)? = null,
|
|
||||||
isError: Boolean = false,
|
|
||||||
enabled: Boolean = true,
|
|
||||||
readOnly: Boolean = false,
|
|
||||||
singleLine: Boolean = false,
|
|
||||||
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
|
|
||||||
minLines: Int = 1,
|
|
||||||
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
|
|
||||||
keyboardActions: KeyboardActions = KeyboardActions.Default,
|
|
||||||
visualTransformation: VisualTransformation = VisualTransformation.None,
|
|
||||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
|
||||||
onTextLayout: (TextLayoutResult) -> Unit = {},
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
val isFocused by interactionSource.collectIsFocusedAsState()
|
|
||||||
BasicTextField(
|
|
||||||
value = value,
|
|
||||||
onValueChange = onValueChange,
|
|
||||||
modifier = modifier,
|
|
||||||
textStyle = textFieldStyle(enabled),
|
|
||||||
interactionSource = interactionSource,
|
|
||||||
enabled = enabled,
|
|
||||||
singleLine = singleLine,
|
|
||||||
maxLines = maxLines,
|
|
||||||
minLines = minLines,
|
|
||||||
readOnly = readOnly,
|
|
||||||
cursorBrush = SolidColor(ElementTheme.colors.textPrimary),
|
|
||||||
keyboardOptions = keyboardOptions,
|
|
||||||
keyboardActions = keyboardActions,
|
|
||||||
visualTransformation = visualTransformation,
|
|
||||||
onTextLayout = onTextLayout,
|
|
||||||
) { innerTextField ->
|
|
||||||
DecorationBox(
|
|
||||||
label = label,
|
|
||||||
readOnly = readOnly,
|
|
||||||
enabled = enabled,
|
|
||||||
isFocused = isFocused,
|
|
||||||
isError = isError,
|
|
||||||
leadingIcon = leadingIcon,
|
|
||||||
placeholder = placeholder,
|
|
||||||
isTextEmpty = value.isEmpty(),
|
|
||||||
innerTextField = innerTextField,
|
|
||||||
trailingIcon = trailingIcon,
|
|
||||||
supportingText = supportingText
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun TextField2(
|
|
||||||
value: TextFieldValue,
|
|
||||||
onValueChange: (TextFieldValue) -> Unit,
|
|
||||||
label: String? = null,
|
|
||||||
supportingText: String? = null,
|
|
||||||
placeholder: String? = null,
|
|
||||||
leadingIcon: @Composable (() -> Unit)? = null,
|
|
||||||
trailingIcon: @Composable (() -> Unit)? = null,
|
|
||||||
isError: Boolean = false,
|
|
||||||
enabled: Boolean = true,
|
|
||||||
readOnly: Boolean = false,
|
|
||||||
singleLine: Boolean = false,
|
|
||||||
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
|
|
||||||
minLines: Int = 1,
|
|
||||||
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
|
|
||||||
keyboardActions: KeyboardActions = KeyboardActions.Default,
|
|
||||||
visualTransformation: VisualTransformation = VisualTransformation.None,
|
|
||||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
|
||||||
onTextLayout: (TextLayoutResult) -> Unit = {},
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
val isFocused by interactionSource.collectIsFocusedAsState()
|
|
||||||
BasicTextField(
|
|
||||||
value = value,
|
|
||||||
onValueChange = onValueChange,
|
|
||||||
modifier = modifier,
|
|
||||||
textStyle = textFieldStyle(enabled),
|
|
||||||
interactionSource = interactionSource,
|
|
||||||
enabled = enabled,
|
|
||||||
singleLine = singleLine,
|
|
||||||
maxLines = maxLines,
|
|
||||||
minLines = minLines,
|
|
||||||
readOnly = readOnly,
|
|
||||||
cursorBrush = SolidColor(ElementTheme.colors.textPrimary),
|
|
||||||
keyboardOptions = keyboardOptions,
|
|
||||||
keyboardActions = keyboardActions,
|
|
||||||
visualTransformation = visualTransformation,
|
|
||||||
onTextLayout = onTextLayout,
|
|
||||||
) { innerTextField ->
|
|
||||||
DecorationBox(
|
|
||||||
label = label,
|
|
||||||
readOnly = readOnly,
|
|
||||||
enabled = enabled,
|
|
||||||
isFocused = isFocused,
|
|
||||||
isError = isError,
|
|
||||||
leadingIcon = leadingIcon,
|
|
||||||
placeholder = placeholder,
|
|
||||||
isTextEmpty = value.text.isEmpty(),
|
|
||||||
innerTextField = innerTextField,
|
|
||||||
trailingIcon = trailingIcon,
|
|
||||||
supportingText = supportingText
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun DecorationBox(
|
|
||||||
label: String?,
|
|
||||||
enabled: Boolean,
|
|
||||||
readOnly: Boolean,
|
|
||||||
isFocused: Boolean,
|
|
||||||
isError: Boolean,
|
|
||||||
placeholder: String?,
|
|
||||||
isTextEmpty: Boolean,
|
|
||||||
supportingText: String?,
|
|
||||||
leadingIcon: @Composable (() -> Unit)?,
|
|
||||||
trailingIcon: @Composable (() -> Unit)?,
|
|
||||||
innerTextField: @Composable () -> Unit,
|
|
||||||
) {
|
|
||||||
Column {
|
|
||||||
if (label != null) {
|
|
||||||
Text(
|
|
||||||
text = label,
|
|
||||||
color = ElementTheme.colors.textPrimary,
|
|
||||||
style = ElementTheme.typography.fontBodyMdRegular,
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
}
|
|
||||||
TextFieldContainer(
|
|
||||||
enabled = enabled,
|
|
||||||
readOnly = readOnly,
|
|
||||||
isFocused = isFocused,
|
|
||||||
isError = isError
|
|
||||||
) {
|
|
||||||
Row(modifier = Modifier.padding(16.dp)) {
|
|
||||||
if (leadingIcon != null) {
|
|
||||||
CompositionLocalProvider(LocalContentColor provides ElementTheme.colors.iconSecondary) {
|
|
||||||
leadingIcon()
|
|
||||||
}
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
}
|
|
||||||
Box(modifier = Modifier.weight(1f)) {
|
|
||||||
if (placeholder != null && isTextEmpty) {
|
|
||||||
Text(
|
|
||||||
text = placeholder,
|
|
||||||
color = ElementTheme.colors.textPlaceholder,
|
|
||||||
style = ElementTheme.typography.fontBodyLgRegular,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
innerTextField()
|
|
||||||
}
|
|
||||||
if (trailingIcon != null) {
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
CompositionLocalProvider(LocalContentColor provides ElementTheme.colors.iconSecondary) {
|
|
||||||
trailingIcon()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (supportingText != null) {
|
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
|
||||||
SupportingTextLayout(isError, supportingText)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun TextFieldContainer(
|
|
||||||
enabled: Boolean,
|
|
||||||
readOnly: Boolean,
|
|
||||||
isFocused: Boolean,
|
|
||||||
isError: Boolean,
|
|
||||||
content: @Composable () -> Unit
|
|
||||||
) {
|
|
||||||
Surface(
|
|
||||||
shape = RoundedCornerShape(4.dp),
|
|
||||||
border = if (readOnly) {
|
|
||||||
null
|
|
||||||
} else {
|
|
||||||
BorderStroke(
|
|
||||||
width = if (isFocused) 2.dp else 1.dp,
|
|
||||||
color = when {
|
|
||||||
!enabled -> ElementTheme.colors.borderDisabled
|
|
||||||
isError -> ElementTheme.colors.borderCriticalPrimary
|
|
||||||
isFocused -> ElementTheme.colors.borderInteractiveHovered
|
|
||||||
else -> ElementTheme.colors.borderInteractiveSecondary
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
color = when {
|
|
||||||
readOnly -> ElementTheme.colors.bgSubtleSecondary
|
|
||||||
!enabled -> ElementTheme.colors.bgCanvasDisabled
|
|
||||||
else -> ElementTheme.colors.bgCanvasDefault
|
|
||||||
},
|
|
||||||
content = content
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun SupportingTextLayout(isError: Boolean, supportingText: String) {
|
|
||||||
Row(horizontalArrangement = spacedBy(4.dp)) {
|
|
||||||
if (isError) {
|
|
||||||
Icon(
|
|
||||||
imageVector = CompoundIcons.Error(),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(16.dp),
|
|
||||||
tint = ElementTheme.colors.iconCriticalPrimary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Text(
|
|
||||||
text = supportingText,
|
|
||||||
color = if (isError) ElementTheme.colors.textCriticalPrimary else ElementTheme.colors.textSecondary,
|
|
||||||
style = ElementTheme.typography.fontBodySmRegular,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun textFieldStyle(enabled: Boolean): TextStyle {
|
|
||||||
return ElementTheme.typography.fontBodyLgRegular.copy(
|
|
||||||
color = if (enabled) {
|
|
||||||
ElementTheme.colors.textPrimary
|
|
||||||
} else {
|
|
||||||
ElementTheme.colors.textSecondary
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Preview(group = PreviewGroup.TextFields)
|
|
||||||
@Composable
|
|
||||||
internal fun TextFields2LightPreview() = ElementPreviewLight { ContentToPreview() }
|
|
||||||
|
|
||||||
@Preview(group = PreviewGroup.TextFields)
|
|
||||||
@Composable
|
|
||||||
internal fun TextFields2DarkPreview() = ElementPreviewDark { ContentToPreview() }
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
@ExcludeFromCoverage
|
|
||||||
private fun ContentToPreview() {
|
|
||||||
Column(modifier = Modifier.padding(4.dp)) {
|
|
||||||
allBooleans.forEach { isError ->
|
|
||||||
allBooleans.forEach { enabled ->
|
|
||||||
allBooleans.forEach { readonly ->
|
|
||||||
TextField2(
|
|
||||||
onValueChange = {},
|
|
||||||
label = "Label",
|
|
||||||
value = "Hello er=${isError.asInt()}, en=${enabled.asInt()}, ro=${readonly.asInt()}",
|
|
||||||
supportingText = "Supporting text",
|
|
||||||
isError = isError,
|
|
||||||
enabled = enabled,
|
|
||||||
readOnly = readonly,
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(2.dp))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue