-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BpkTextArea widget for compose (#1700)
* initial commit for BpkTextArea * BpkTextArea for compose * return state for BpkTextArea * add state screenshots for BpkTextArea * Updated snapshots for 'rtl' * Updated snapshots for 'dm' * Updated snapshots for 'default' * fix TextAreaStory for BpkTextArea * fix screenshots for BpkTextArea --------- Co-authored-by: Anton Sobolev <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e16599a
commit 956604c
Showing
48 changed files
with
380 additions
and
1 deletion.
There are no files selected for viewing
Binary file added
BIN
+2.73 KB
...ug/default/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.29 KB
...g/default/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.95 KB
...et.skyscanner.backpack.compose.textarea.BpkTextAreaTest_disabledPlaceholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.58 KB
...ebug/default/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.83 KB
.../default/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_multiline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.51 KB
...t.skyscanner.backpack.compose.textarea.BpkTextAreaTest_multilinePlaceholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.95 KB
...efault/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.73 KB
...g/default/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_readOnly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.58 KB
.../default/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_validated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.77 KB
...s/debug/dm/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.42 KB
.../debug/dm/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.14 KB
...et.skyscanner.backpack.compose.textarea.BpkTextAreaTest_disabledPlaceholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.6 KB
...oss/debug/dm/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.14 KB
...bug/dm/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.63 KB
...debug/dm/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_validated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.71 KB
.../debug/rtl/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.6 KB
...ss/debug/rtl/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.55 KB
...t.skyscanner.backpack.compose.textarea.BpkTextAreaTest_multilinePlaceholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.59 KB
...ebug/rtl/net.skyscanner.backpack.compose.textarea.BpkTextAreaTest_validated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
144 changes: 144 additions & 0 deletions
144
app/src/androidTest/java/net/skyscanner/backpack/compose/textarea/BpkTextAreaTest.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,144 @@ | ||
/** | ||
* Backpack for Android - Skyscanner's Design System | ||
* | ||
* Copyright 2018 Skyscanner Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.skyscanner.backpack.compose.textarea | ||
|
||
import androidx.compose.ui.unit.dp | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import net.skyscanner.backpack.BpkTestVariant | ||
import net.skyscanner.backpack.Variants | ||
import net.skyscanner.backpack.compose.BpkSnapshotTest | ||
import net.skyscanner.backpack.compose.fieldset.BpkFieldStatus | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class BpkTextAreaTest : BpkSnapshotTest() { | ||
|
||
@Test | ||
fun default() = snap { | ||
BpkTextArea( | ||
value = "Value", | ||
onValueChange = {}, | ||
placeholder = "Placeholder", | ||
status = BpkFieldStatus.Default, | ||
) | ||
} | ||
|
||
@Test | ||
@Variants(BpkTestVariant.Default) | ||
fun readOnly() { | ||
snap { | ||
BpkTextArea( | ||
value = "Value", | ||
onValueChange = {}, | ||
placeholder = "Placeholder", | ||
readOnly = true, | ||
status = BpkFieldStatus.Default, | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
@Variants(BpkTestVariant.Default, BpkTestVariant.DarkMode) | ||
fun placeholder() { | ||
snap { | ||
BpkTextArea( | ||
value = "", | ||
onValueChange = {}, | ||
placeholder = "Placeholder", | ||
status = BpkFieldStatus.Default, | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
@Variants(BpkTestVariant.Default) | ||
fun multiline() { | ||
snap(width = 200.dp) { | ||
BpkTextArea( | ||
value = "Value ".repeat(20), | ||
onValueChange = {}, | ||
placeholder = "Placeholder ".repeat(20), | ||
status = BpkFieldStatus.Default, | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
@Variants(BpkTestVariant.Default, BpkTestVariant.Rtl) | ||
fun multilinePlaceholder() { | ||
snap(width = 200.dp) { | ||
BpkTextArea( | ||
value = "", | ||
onValueChange = {}, | ||
placeholder = "Placeholder ".repeat(20), | ||
status = BpkFieldStatus.Default, | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
@Variants(BpkTestVariant.Default, BpkTestVariant.DarkMode) | ||
fun disabled() { | ||
snap { | ||
BpkTextArea( | ||
value = "Value", | ||
onValueChange = {}, | ||
placeholder = "Placeholder", | ||
status = BpkFieldStatus.Disabled, | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
@Variants(BpkTestVariant.Default, BpkTestVariant.DarkMode) | ||
fun disabledPlaceholder() { | ||
snap { | ||
BpkTextArea( | ||
value = "", | ||
onValueChange = {}, | ||
placeholder = "Placeholder", | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun validated() { | ||
snap { | ||
BpkTextArea( | ||
value = "Value", | ||
onValueChange = {}, | ||
placeholder = "Placeholder", | ||
status = BpkFieldStatus.Validated, | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun error() { | ||
snap { | ||
BpkTextArea( | ||
value = "Value", | ||
onValueChange = {}, | ||
placeholder = "Placeholder", | ||
status = BpkFieldStatus.Error("Error text"), | ||
) | ||
} | ||
} | ||
} |
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
91 changes: 91 additions & 0 deletions
91
backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/textarea/BpkTextArea.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,91 @@ | ||
/** | ||
* Backpack for Android - Skyscanner's Design System | ||
* | ||
* Copyright 2018 Skyscanner Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.skyscanner.backpack.compose.textarea | ||
|
||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.text.KeyboardActions | ||
import androidx.compose.foundation.text.KeyboardOptions | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.input.TextFieldValue | ||
import androidx.compose.ui.text.input.VisualTransformation | ||
import net.skyscanner.backpack.compose.fieldset.BpkFieldStatus | ||
import net.skyscanner.backpack.compose.fieldset.LocalFieldStatus | ||
import net.skyscanner.backpack.compose.textfield.internal.BpkTextFieldImpl | ||
|
||
private const val LINES_COUNT = 3 | ||
|
||
@Composable | ||
fun BpkTextArea( | ||
value: String, | ||
onValueChange: (String) -> Unit, | ||
modifier: Modifier = Modifier, | ||
readOnly: Boolean = false, | ||
status: BpkFieldStatus = LocalFieldStatus.current, | ||
placeholder: String? = null, | ||
visualTransformation: VisualTransformation = VisualTransformation.None, | ||
keyboardOptions: KeyboardOptions = KeyboardOptions.Default, | ||
keyboardActions: KeyboardActions = KeyboardActions(), | ||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, | ||
) { | ||
BpkTextFieldImpl( | ||
value = value, | ||
onValueChange = onValueChange, | ||
modifier = modifier, | ||
readOnly = readOnly, | ||
status = status, | ||
placeholder = placeholder, | ||
visualTransformation = visualTransformation, | ||
keyboardOptions = keyboardOptions, | ||
keyboardActions = keyboardActions, | ||
minLines = LINES_COUNT, | ||
maxLines = LINES_COUNT, | ||
interactionSource = interactionSource, | ||
) | ||
} | ||
|
||
@Composable | ||
fun BpkTextArea( | ||
value: TextFieldValue, | ||
onValueChange: (TextFieldValue) -> Unit, | ||
modifier: Modifier = Modifier, | ||
readOnly: Boolean = false, | ||
status: BpkFieldStatus = LocalFieldStatus.current, | ||
placeholder: String? = null, | ||
visualTransformation: VisualTransformation = VisualTransformation.None, | ||
keyboardOptions: KeyboardOptions = KeyboardOptions.Default, | ||
keyboardActions: KeyboardActions = KeyboardActions(), | ||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, | ||
) { | ||
BpkTextFieldImpl( | ||
value = value, | ||
onValueChange = onValueChange, | ||
modifier = modifier, | ||
readOnly = readOnly, | ||
status = status, | ||
placeholder = placeholder, | ||
visualTransformation = visualTransformation, | ||
keyboardOptions = keyboardOptions, | ||
keyboardActions = keyboardActions, | ||
minLines = LINES_COUNT, | ||
maxLines = LINES_COUNT, | ||
interactionSource = interactionSource, | ||
) | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Oops, something went wrong.
Oops, something went wrong.