-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(TextField): Revert change that made addons not centered (#1248)
Co-authored-by: Simon Marquis <[email protected]> Co-authored-by: spark-ui-bot <[email protected]>
- Loading branch information
1 parent
a17541c
commit cd0da1a
Showing
21 changed files
with
286 additions
and
53 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
222 changes: 222 additions & 0 deletions
222
.../main/kotlin/com/adevinta/spark/catalog/examples/samples/textfields/TextfieldsExamples.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,222 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Adevinta | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package com.adevinta.spark.catalog.examples.samples.textfields | ||
|
||
import androidx.compose.foundation.Canvas | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.ColumnScope | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.window.PopupProperties | ||
import com.adevinta.spark.SparkTheme | ||
import com.adevinta.spark.catalog.model.Example | ||
import com.adevinta.spark.catalog.util.SampleSourceUrl | ||
import com.adevinta.spark.components.menu.DropdownMenuItem | ||
import com.adevinta.spark.components.text.Text | ||
import com.adevinta.spark.components.textfields.SparkSelectTrailingIcon | ||
import com.adevinta.spark.components.textfields.TextField | ||
import com.adevinta.spark.icons.Booster | ||
import com.adevinta.spark.icons.EyeFill | ||
import com.adevinta.spark.icons.EyeOffFill | ||
import com.adevinta.spark.icons.QuestionOutline | ||
import com.adevinta.spark.icons.SparkIcons | ||
import kotlin.random.Random | ||
|
||
private const val TextFieldsExampleSourceUrl = "$SampleSourceUrl/DropdownExamples.kt" | ||
|
||
public val TextFieldsExamples: List<Example> = listOf( | ||
Example( | ||
name = "Default Addons", | ||
description = "Sample of addons provided by Spark through the AddonScope api", | ||
sourceUrl = TextFieldsExampleSourceUrl, | ||
) { | ||
Addons() | ||
}, | ||
) | ||
|
||
@Composable | ||
private fun ColumnScope.Addons() { | ||
Column( | ||
verticalArrangement = Arrangement.spacedBy(16.dp), | ||
) { | ||
TextFieldWithDropdown() | ||
TextFieldWithButton() | ||
TextFieldWithIcon() | ||
TextFieldWithIconButton() | ||
TextFieldWithIconToggleButton() | ||
TextFieldWithPrefixSuffixButton() | ||
} | ||
} | ||
|
||
@Composable | ||
private fun TextFieldWithDropdown() { | ||
var expanded by remember { mutableStateOf(false) } | ||
TextField( | ||
modifier = Modifier.fillMaxWidth(), | ||
value = "+33 0123456789", | ||
label = "Phone number - Dropdown addon", | ||
onValueChange = {}, | ||
leadingContent = { | ||
Dropdown( | ||
modifier = Modifier, | ||
expanded = expanded, | ||
onExpandedChange = { | ||
expanded = !expanded | ||
}, | ||
onDismissRequest = { | ||
expanded = false | ||
}, | ||
properties = PopupProperties(), | ||
dropdownLabel = { | ||
Canvas( | ||
modifier = Modifier.size(width = 24.dp, height = 14.dp), | ||
) { | ||
drawRect(color = Color.Blue) | ||
drawRect(color = Color.White, topLeft = Offset(24.dp.toPx() / 3, 0f)) | ||
drawRect(color = Color.Red, topLeft = Offset(24.dp.toPx() / 3 * 2, 0f)) | ||
} | ||
Text(text = "FR", style = SparkTheme.typography.body1) | ||
SparkSelectTrailingIcon(expanded = expanded) | ||
}, | ||
) { | ||
repeat(4) { | ||
DropdownMenuItem( | ||
onClick = { | ||
expanded = false | ||
}, | ||
text = { Text(text = "Dropdown") }, | ||
) | ||
} | ||
} | ||
}, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun TextFieldWithButton() { | ||
var isLoading by remember { mutableStateOf(false) } | ||
TextField( | ||
modifier = Modifier.fillMaxWidth(), | ||
value = "AA-123-BB", | ||
label = "Button addon", | ||
onValueChange = {}, | ||
trailingContent = { | ||
Button( | ||
text = "Validate", | ||
modifier = Modifier, | ||
onClick = { isLoading = !isLoading }, | ||
isLoading = isLoading, | ||
) | ||
}, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun TextFieldWithIcon() { | ||
TextField( | ||
modifier = Modifier.fillMaxWidth(), | ||
value = "AA-123-BB", | ||
label = "Icon addon", | ||
onValueChange = {}, | ||
trailingContent = { | ||
TextFieldIcon( | ||
icon = SparkIcons.QuestionOutline, | ||
modifier = Modifier, | ||
contentDescription = "", | ||
) | ||
}, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun TextFieldWithIconButton() { | ||
var value by remember { | ||
mutableStateOf("AA-123-BB") | ||
} | ||
TextField( | ||
modifier = Modifier.fillMaxWidth(), | ||
value = value, | ||
label = "Icon button addon", | ||
onValueChange = {}, | ||
trailingContent = { | ||
TextFieldIconButton( | ||
modifier = Modifier, | ||
icon = SparkIcons.Booster, | ||
contentDescription = "", | ||
onClick = { value = Random.nextInt(0, 8000).toString() }, | ||
) | ||
}, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun TextFieldWithIconToggleButton() { | ||
var checked by remember { | ||
mutableStateOf(false) | ||
} | ||
TextField( | ||
modifier = Modifier.fillMaxWidth(), | ||
value = "AA-123-BB", | ||
label = "Icon toggle button addon", | ||
onValueChange = {}, | ||
trailingContent = { | ||
TextFieldIconToggleButton( | ||
modifier = Modifier, | ||
checked = checked, | ||
checkedIcon = SparkIcons.EyeFill, | ||
unCheckedIcon = SparkIcons.EyeOffFill, | ||
contentDescription = "", | ||
onCheckedChange = { checked = it }, | ||
) | ||
}, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun TextFieldWithPrefixSuffixButton() { | ||
TextField( | ||
modifier = Modifier.fillMaxWidth(), | ||
value = "www.adevinta.com", | ||
label = "Url - Prefix/Suffix addon", | ||
onValueChange = {}, | ||
leadingContent = { | ||
TextFieldText( | ||
text = "https://", | ||
) | ||
}, | ||
trailingContent = { | ||
TextFieldText( | ||
text = ".com", | ||
) | ||
}, | ||
) | ||
} |
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
4 changes: 2 additions & 2 deletions
4
.../images/com.adevinta.spark.textfields_MultilineTextFieldScreenshot_bigValue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...s/com.adevinta.spark.textfields_MultilineTextFieldScreenshot_showcase__dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
.../com.adevinta.spark.textfields_MultilineTextFieldScreenshot_showcase__light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...mages/com.adevinta.spark.textfields_MultilineTextFieldScreenshot_smallValue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...ta.spark.textfields_TextFieldDocScreenshot_multilineTextFieldShowcase__dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...a.spark.textfields_TextFieldDocScreenshot_multilineTextFieldShowcase__light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...vinta.spark.textfields_TextFieldDocScreenshot_selectTextFieldShowcase__dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...inta.spark.textfields_TextFieldDocScreenshot_selectTextFieldShowcase__light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...om.adevinta.spark.textfields_TextFieldDocScreenshot_textFieldShowcase__dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...m.adevinta.spark.textfields_TextFieldDocScreenshot_textFieldShowcase__light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...snapshots/images/com.adevinta.spark.textfields_TextFieldScreenshot_bigValue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...snapshots/images/com.adevinta.spark.textfields_TextFieldScreenshot_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.