Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TextLink): Add TextLink component #843

Merged
merged 49 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
927ad89
Add TextLink component
Dec 7, 2023
6a1c145
Add TextLink documentation
Dec 7, 2023
8735c80
Added Examples
Dec 11, 2023
d0379cb
Add TextLink Examples
Dec 11, 2023
8e6a8fb
Merge remote-tracking branch 'origin/TextLink' into TextLink
Dec 11, 2023
5d51cd0
Add screenshot testing
Dec 11, 2023
3f5267c
Fix lint issue
Dec 11, 2023
a6a8324
Fix examples build error
Dec 11, 2023
8077533
Merge branch 'main' into TextLink
Dec 12, 2023
981bad9
Fix screenshot test error
Dec 12, 2023
b9f2f10
Fix paparazzi
Dec 12, 2023
1a457e6
πŸ“Έ Update Paparazzi golden images
spark-ui-bot Dec 12, 2023
f2c865a
Update spark/src/main/kotlin/com/adevinta/spark/components/text/TextL…
Dec 13, 2023
aab79ab
Fix simon comments
Dec 13, 2023
5ddf741
Merge remote-tracking branch 'origin/TextLink' into TextLink
Dec 13, 2023
fd84096
Replace Textlink icon
Dec 13, 2023
99fe4ab
Merge branch 'main' into TextLink
Dec 13, 2023
da66d2b
Add preview to textlink component
Dec 18, 2023
a9398b7
Add configurator to text link
Dec 18, 2023
8cefcd2
Fix spotless
Dec 18, 2023
47acc7d
Fix spotless
Dec 18, 2023
ee2372a
Fix spotless
Dec 18, 2023
358b9bd
Fix releaseRuntimeClasspath.txt
Dec 19, 2023
003b728
Reimplement Textlink to match with Specs
Jan 5, 2024
321d723
Fix Text Link Configurator
Jan 5, 2024
189366b
Fix Screenshot testing
Jan 5, 2024
6d00a94
Fix Text Link Examples
Jan 5, 2024
5b0c466
Fix Text Link Examples
Jan 5, 2024
d687bcb
Merge remote-tracking branch 'origin/main' into TextLink
Jan 5, 2024
b4662b1
Merge branch 'main' into TextLink
Jan 5, 2024
172e463
Merge remote-tracking branch 'origin/main' into TextLink
Jan 11, 2024
735710f
feat: Add variant TextLinkButton (#897)
Jan 23, 2024
c2bafb1
Fix configurator
Jan 24, 2024
a428b79
Merge branch 'main' into TextLink
Jan 24, 2024
205e401
Fix configurator
Jan 24, 2024
65c7cbb
Fix configurator & Examples
Jan 24, 2024
06fc270
Fix configurator & Examples
Jan 24, 2024
dab217a
Add annotations res support to Text Link
Jan 24, 2024
8f3a874
Fix component & Documentation
Jan 24, 2024
c9129da
Update screenshots
Jan 24, 2024
aea9ba8
Fix spotless
Jan 24, 2024
a18705f
Removed un-necessary additions
Jan 25, 2024
231346a
Merge branch 'main' into TextLink
Jan 25, 2024
bde3691
πŸ“Έ Update Paparazzi golden images
spark-ui-bot Jan 25, 2024
9a61c26
Fix locale FR String resources
Jan 25, 2024
e0248b4
Fix locale FR String resources
Jan 25, 2024
c76639a
Fix lint in String resources
Jan 25, 2024
716796d
Fix Simon comments
Jan 25, 2024
8f0c311
Fix spotless
Jan 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions catalog/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ dependencies {
implementation(projects.spark)

implementation(libs.kotlin.reflect)
implementation(libs.kotlinx.collections.immutable)

implementation(libs.airbnb.showkase)

implementation(libs.accompanist.testharness)
implementation(libs.accompanist.drawablepainter)
implementation(libs.colorpicker)

implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.ui)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private fun ProgressbarSample() {
isRounded = isRounded,
)

Text(text = "ProgressbarIndeterminate")
Text(text = "Progressbar Indeterminate")
kazaky marked this conversation as resolved.
Show resolved Hide resolved

ProgressbarIndeterminate(
intent = intent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* Copyright (c) 2023 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.configurator.samples.text

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.SnackbarDuration
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.adevinta.spark.SparkTheme
import com.adevinta.spark.catalog.R
import com.adevinta.spark.catalog.model.Configurator
import com.adevinta.spark.catalog.themes.SegmentedButton
import com.adevinta.spark.catalog.util.SampleSourceUrl
import com.adevinta.spark.components.buttons.ButtonIntent
import com.adevinta.spark.components.buttons.IconSide
import com.adevinta.spark.components.menu.DropdownMenuItem
import com.adevinta.spark.components.scaffold.Scaffold
import com.adevinta.spark.components.snackbars.SnackbarHost
import com.adevinta.spark.components.snackbars.SnackbarHostState
import com.adevinta.spark.components.spacer.VerticalSpacer
import com.adevinta.spark.components.text.Text
import com.adevinta.spark.components.text.TextLink
import com.adevinta.spark.components.text.TextLinkButton
import com.adevinta.spark.components.textfields.SelectTextField
import com.adevinta.spark.components.toggles.SwitchLabelled
import com.adevinta.spark.icons.LikeFill
import com.adevinta.spark.icons.SparkIcons
import kotlinx.coroutines.launch

public val TextLinksConfigurator: Configurator = Configurator(
name = "TextLink",
description = "TextLink configuration",
sourceUrl = "$SampleSourceUrl/TextLinkSamples.kt",
) {
TextLinkSample()
}

@Preview(showBackground = true)
@Composable
private fun TextLinkSample() {
val scrollState = rememberScrollState()
var isIconAdded by remember { mutableStateOf(true) }
var isLoading by remember { mutableStateOf(false) }
var iconSide by remember { mutableStateOf(IconSide.START) }
val coroutineScope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
var intent by remember { mutableStateOf(ButtonIntent.Main) }
val intents = ButtonIntent.entries
var expanded by remember { mutableStateOf(false) }

Scaffold(
snackbarHost = {
SnackbarHost(snackbarHostState)
},
) {
Column(
verticalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier.verticalScroll(scrollState),
) {
Text(text = "Text Link Component", style = SparkTheme.typography.headline1)

TextLink(
text = R.string.spark_text_link_paragraph_example,
style = SparkTheme.typography.subhead,
onClickLabel = "Privacy & Policy",
onClick = {
coroutineScope.launch {
snackbarHostState.showSnackbar(
message = "Privacy & Policy Clicked",
actionLabel = "Action",
duration = SnackbarDuration.Short,
)
}
},
)
VerticalSpacer(8.dp)
Text(text = "Text Link Button Component", style = SparkTheme.typography.headline1)

TextLinkButton(
text = "Click me",
intent = intent,
icon = if (isIconAdded) SparkIcons.LikeFill else null,
iconSide = iconSide,
isLoading = isLoading,
onClick = {
isLoading = !isLoading

coroutineScope.launch {
snackbarHostState.showSnackbar(
message = "Privacy & Policy Clicked",
actionLabel = "Action",
duration = SnackbarDuration.Short,
)
}
},
)

SwitchLabelled(
checked = isIconAdded,
onCheckedChange = { isIconAdded = it },
) {
Text(
text = "Enable Icon",
modifier = Modifier.fillMaxWidth(),
)
}

Column {
Text(
text = "Icon Alignment",
modifier = Modifier.padding(bottom = 8.dp),
style = SparkTheme.typography.body2.copy(fontWeight = FontWeight.Bold),
)
val iconSides = IconSide.entries.toTypedArray()
val iconSideLabel = iconSides.map { it.name }
SegmentedButton(
options = iconSideLabel,
selectedOption = iconSide.name,
onOptionSelect = { iconSide = IconSide.valueOf(it) },
modifier = Modifier
.fillMaxWidth()
.height(48.dp),
)
}

SelectTextField(
modifier = Modifier.fillMaxWidth(),
value = intent.name,
onValueChange = {},
readOnly = true,
label = stringResource(id = R.string.configurator_component_screen_intent_label),
expanded = expanded,
onExpandedChange = { expanded = !expanded },
onDismissRequest = { expanded = false },
dropdownContent = {
intents.forEach {
DropdownMenuItem(
text = { Text(it.name) },
onClick = {
intent = it
expanded = false
},
)
}
},
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*
* Copyright (c) 2023 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.text

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.SnackbarDuration
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.sp
import com.adevinta.spark.SparkTheme
import com.adevinta.spark.catalog.R
import com.adevinta.spark.catalog.model.Example
import com.adevinta.spark.catalog.util.SampleSourceUrl
import com.adevinta.spark.components.scaffold.Scaffold
import com.adevinta.spark.components.snackbars.SnackbarHost
import com.adevinta.spark.components.snackbars.SnackbarHostState
import com.adevinta.spark.components.text.TextLink
import com.adevinta.spark.components.text.TextLinkButton
import com.adevinta.spark.icons.Link
import com.adevinta.spark.icons.SparkIcons
import kotlinx.coroutines.launch

private const val TextLinksExampleSourceUrl = "$SampleSourceUrl/TextLinkExamples.kt"

public val TextLinksExamples: List<Example> = listOf(
Example(
name = "Link inside title",
description = "Link inside title no icon",
sourceUrl = TextLinksExampleSourceUrl,
) {
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
Scaffold(
modifier = Modifier.fillMaxSize(),
snackbarHost = {
SnackbarHost(snackbarHostState)
},
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize(),
) {

TextLink(
style = SparkTheme.typography.subhead,
text = R.string.spark_text_link_short_example,
lineHeight = 40.sp,
onClickLabel = "https://kotlinlang.org",
onClick = {
scope.launch {
snackbarHostState.showSnackbar(
message = "https://kotlinlang.org",
actionLabel = "Action",
duration = SnackbarDuration.Short,
)
}
},
)
}
}
},
Example(
name = "Link inside paragraph",
description = "Link inside paragraph no icon",
sourceUrl = TextLinksExampleSourceUrl,
) {
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
Scaffold(
modifier = Modifier.fillMaxSize(),
snackbarHost = {
SnackbarHost(snackbarHostState)
},
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize(),
) {

TextLink(
style = SparkTheme.typography.subhead,
text = R.string.spark_text_link_paragraph_example,
onClickLabel = "textLink",
onClick = {
scope.launch {
snackbarHostState.showSnackbar(
message = "Link Clicked",
actionLabel = "Action",
duration = SnackbarDuration.Short,
)
}
},
)
}
}
},
Example(
name = "Entire text as link no icon",
description = "Entire text as link no icon using Text Link Button",
sourceUrl = TextLinksExampleSourceUrl,
) {
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
Scaffold(
modifier = Modifier.fillMaxSize(),
snackbarHost = {
SnackbarHost(snackbarHostState)
},
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize(),
) {

TextLinkButton(
text = "Try out Android Development",
onClick = {
scope.launch {
snackbarHostState.showSnackbar(
message = "Try out Android Development Clicked",
actionLabel = "Action",
duration = SnackbarDuration.Short,
)
}
},
)
}
}
},
Example(
name = "Entire text as link with icon",
description = "Entire text as link with icon using Text Link Button",
sourceUrl = TextLinksExampleSourceUrl,
) {
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
Scaffold(
modifier = Modifier.fillMaxSize(),
snackbarHost = {
SnackbarHost(snackbarHostState)
},
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize(),
) {

TextLinkButton(
text = "Try out Android Development",
icon = SparkIcons.Link,
onClick = {
scope.launch {
snackbarHostState.showSnackbar(
message = "Try out Android Development Clicked",
actionLabel = "Action",
duration = SnackbarDuration.Short,
)
}
},
)
}
}
},
)
Loading
Loading