-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add EmailAddressTextField (#258)
- Loading branch information
Showing
14 changed files
with
554 additions
and
114 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
67 changes: 0 additions & 67 deletions
67
app/src/main/java/com/infomaniak/swisstransfer/ui/components/EmailAddressChip.kt
This file was deleted.
Oops, something went wrong.
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
124 changes: 124 additions & 0 deletions
124
app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferChips.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,124 @@ | ||
/* | ||
* Infomaniak SwissTransfer - Android | ||
* Copyright (C) 2024 Infomaniak Network SA | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.swisstransfer.ui.components | ||
|
||
import android.content.res.Configuration | ||
import androidx.compose.foundation.horizontalScroll | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.tooling.preview.datasource.LoremIpsum | ||
import com.infomaniak.swisstransfer.R | ||
import com.infomaniak.swisstransfer.ui.images.AppImages | ||
import com.infomaniak.swisstransfer.ui.images.icons.CrossThick | ||
import com.infomaniak.swisstransfer.ui.theme.CustomShapes | ||
import com.infomaniak.swisstransfer.ui.theme.Dimens | ||
import com.infomaniak.swisstransfer.ui.theme.Margin | ||
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme | ||
|
||
@Composable | ||
fun SwissTransferSuggestionChip(text: String, modifier: Modifier = Modifier) { | ||
SuggestionChip( | ||
modifier = modifier, | ||
onClick = {}, | ||
label = { ChipLabel(text) }, | ||
enabled = false, | ||
shape = CustomShapes.ROUNDED, | ||
colors = SuggestionChipDefaults.suggestionChipColors( | ||
disabledContainerColor = SwissTransferTheme.colors.emailAddressChipColor, | ||
disabledLabelColor = SwissTransferTheme.colors.onEmailAddressChipColor, | ||
), | ||
border = null, | ||
) | ||
} | ||
|
||
@Composable | ||
fun SwissTransferInputChip( | ||
modifier: Modifier = Modifier, | ||
text: String, | ||
isSelected: () -> Boolean, | ||
onClick: () -> Unit, | ||
onDismiss: () -> Unit, | ||
) { | ||
InputChip( | ||
modifier = modifier.widthIn(min = Dimens.InputChipMinWidth), | ||
selected = isSelected(), | ||
onClick = onClick, | ||
label = { ChipLabel(text) }, | ||
shape = CustomShapes.ROUNDED, | ||
colors = InputChipDefaults.inputChipColors( | ||
containerColor = SwissTransferTheme.colors.emailAddressChipColor, | ||
labelColor = SwissTransferTheme.colors.onEmailAddressChipColor, | ||
selectedLabelColor = SwissTransferTheme.colors.emailAddressChipColor, | ||
selectedContainerColor = SwissTransferTheme.colors.onEmailAddressChipColor, | ||
selectedTrailingIconColor = SwissTransferTheme.colors.emailAddressChipColor, | ||
trailingIconColor = SwissTransferTheme.colors.onEmailAddressChipColor, | ||
), | ||
border = null, | ||
trailingIcon = { | ||
IconButton(modifier = Modifier.size(Dimens.IconSize), onClick = onDismiss) { | ||
Icon( | ||
modifier = Modifier.size(Dimens.MicroIconSize), | ||
imageVector = AppImages.AppIcons.CrossThick, | ||
contentDescription = stringResource(R.string.contentDescriptionButtonRemoveRecipient, text), | ||
) | ||
} | ||
}, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun ChipLabel(text: String) { | ||
Text( | ||
text = text, | ||
style = SwissTransferTheme.typography.bodyRegular, | ||
maxLines = 1, | ||
overflow = TextOverflow.MiddleEllipsis, | ||
) | ||
} | ||
|
||
@Preview(name = "Light mode") | ||
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL) | ||
@Composable | ||
private fun EmailAddressChipPreview() { | ||
|
||
fun getLoremText(words: Int) = LoremIpsum(words).values.joinToString(separator = " ") | ||
|
||
SwissTransferTheme { | ||
Surface { | ||
Column(Modifier.padding(Margin.Small)) { | ||
SwissTransferSuggestionChip(text = LoremIpsum(2).values.joinToString(separator = " ")) | ||
|
||
Row( | ||
modifier = Modifier.horizontalScroll(rememberScrollState()), | ||
horizontalArrangement = Arrangement.spacedBy(Margin.Mini), | ||
) { | ||
SwissTransferInputChip(text = getLoremText(2), isSelected = { true }, onClick = {}, onDismiss = { }) | ||
SwissTransferInputChip(text = getLoremText(1), isSelected = { false }, onClick = {}, onDismiss = { }) | ||
SwissTransferInputChip(text = getLoremText(4), isSelected = { false }, onClick = {}, onDismiss = { }) | ||
SwissTransferInputChip(text = getLoremText(1), isSelected = { false }, onClick = {}, onDismiss = { }) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.