-
Notifications
You must be signed in to change notification settings - Fork 0
added DSLink #8
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
Merged
Merged
added DSLink #8
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
170 changes: 170 additions & 0 deletions
170
components/src/main/java/com/dbsystel/designsystem/components/link/DSLink.kt
This file contains hidden or 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,170 @@ | ||
| package com.dbsystel.designsystem.components.link | ||
|
|
||
| import androidx.annotation.DrawableRes | ||
| import androidx.compose.foundation.Image | ||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.material.ripple.RippleAlpha | ||
| import androidx.compose.material3.ExperimentalMaterial3Api | ||
| import androidx.compose.material3.LocalRippleConfiguration | ||
| import androidx.compose.material3.RippleConfiguration | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.CompositionLocalProvider | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.alpha | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.graphics.ColorFilter | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.text.style.TextDecoration | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.tooling.preview.PreviewParameter | ||
| import androidx.compose.ui.tooling.preview.PreviewParameterProvider | ||
| import androidx.compose.ui.unit.Dp | ||
| import androidx.compose.ui.unit.TextUnit | ||
| import androidx.compose.ui.unit.dp | ||
| import com.dbsystel.designsystem.foundation.R | ||
| import com.dbsystel.designsystem.foundation.theme.DesignSystemTheme | ||
|
|
||
| /** | ||
| * Basic DesignSystem-Link | ||
| * | ||
| * @param modifier - custom modifier of the link | ||
| * @param enabled - enable state | ||
| * @param callback - callback when link is clicked | ||
| * @param text - text of link | ||
| * @param variant - variant of the link | ||
| * @param size - size of the link (medium or small) | ||
| * @param content - content type of the link (external or internal link) | ||
| */ | ||
| @OptIn(ExperimentalMaterial3Api::class) | ||
| @Composable | ||
| fun DSLink( | ||
| modifier: Modifier = Modifier, | ||
| enabled: Boolean = true, | ||
| callback: () -> Unit, | ||
tkoecher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| text: String, | ||
| variant: DSLinkVariant = DSLinkVariant.ADAPTIVE, | ||
| size: DSLinkSize = DSLinkSize.MEDIUM, | ||
| content: DSLinkContent = DSLinkContent.INTERNAL, | ||
tkoecher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) { | ||
| val backgroundRippleTheme = RippleConfiguration( | ||
| color = variant.pressedColor(), | ||
| rippleAlpha = RippleAlpha(1.0f, 1.0f, 1.0f, 1.0f) | ||
| ) | ||
| CompositionLocalProvider(LocalRippleConfiguration provides backgroundRippleTheme) { | ||
tkoecher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Row( | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| modifier = Modifier | ||
| .run { if (enabled) alpha(1.0f) else alpha(0.4f) } | ||
| .clickable(enabled = enabled) { callback() } | ||
tkoecher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .then(modifier) | ||
| ) { | ||
| Text( | ||
| text = text, | ||
| textDecoration = TextDecoration.Underline, | ||
| modifier = Modifier.padding(end = size.paddingH()), | ||
tkoecher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fontSize = size.textSize(), | ||
| color = variant.color() | ||
tkoecher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| Box(modifier = Modifier.size(size.iconSize())) { | ||
| Image( | ||
| painter = painterResource(content.iconRes), | ||
| contentDescription = "Arrow", | ||
| modifier = Modifier.align(Alignment.Center), | ||
| colorFilter = ColorFilter.tint(variant.color()) | ||
| ) | ||
| } | ||
tkoecher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| enum class DSLinkVariant( | ||
| val color: @Composable () -> Color, | ||
| val pressedColor: @Composable () -> Color | ||
| ) { | ||
| ADAPTIVE( | ||
| color = { DesignSystemTheme.activeColor.Basic.Text.Emphasis100.Default }, | ||
| pressedColor = { DesignSystemTheme.activeColor.onBgBasicEmphasis100Pressed }, | ||
tkoecher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ), | ||
| BRAND( | ||
| color = { DesignSystemTheme.colors.brand.Origin.Default }, | ||
| pressedColor = { DesignSystemTheme.colors.brand.onBgBasicEmphasis100Pressed }, | ||
tkoecher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ), | ||
| } | ||
|
|
||
| enum class DSLinkSize( | ||
| val paddingH: @Composable () -> Dp, | ||
| val iconSize: @Composable () -> Dp, | ||
| val textSize: @Composable () -> TextUnit, | ||
tkoecher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) { | ||
| MEDIUM( | ||
| paddingH = { DesignSystemTheme.dimensions.spacing.fixed2xs }, | ||
| iconSize = { 24.dp }, | ||
| textSize = { DesignSystemTheme.typography.bodyMd.fontSize }, | ||
| ), | ||
| SMALL( | ||
| paddingH = { DesignSystemTheme.dimensions.spacing.fixed3xs }, | ||
| iconSize = { 20.dp }, | ||
| textSize = { DesignSystemTheme.typography.bodySm.fontSize }, | ||
| ) | ||
| } | ||
|
|
||
| enum class DSLinkContent(@DrawableRes val iconRes: Int) { | ||
| INTERNAL(iconRes = R.drawable.arrow_right), | ||
| EXTERNAL(iconRes = R.drawable.arrow_right_up), | ||
tkoecher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private class DSLinkPreviewProvider : PreviewParameterProvider<DSLinkPreviewParameterType> { | ||
| override val values = DSLinkVariant.entries.flatMap { variant -> | ||
| DSLinkSize.entries.flatMap { size -> | ||
| DSLinkContent.entries.flatMap { content -> | ||
| listOf(true, false).map { enabled -> | ||
| DSLinkPreviewParameterType( | ||
| variant = variant, | ||
| size = size, | ||
| content = content, | ||
| enabled = enabled | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| }.asSequence() | ||
| } | ||
|
|
||
| private class DSLinkPreviewParameterType( | ||
| val size: DSLinkSize, | ||
| val variant: DSLinkVariant, | ||
| val content: DSLinkContent, | ||
| val enabled: Boolean | ||
| ) | ||
|
|
||
| @Composable | ||
| @Preview | ||
tkoecher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private fun DSButtonPreview( | ||
| @PreviewParameter(DSLinkPreviewProvider::class) previewType: DSLinkPreviewParameterType | ||
| ) { | ||
| DesignSystemTheme { | ||
| Box( | ||
| modifier = Modifier | ||
| .width(150.dp) | ||
| .background(Color.White) | ||
| .padding(5.dp) | ||
tkoecher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) { | ||
| DSLink( | ||
| callback = {}, | ||
| text = previewType.variant.name, | ||
| size = previewType.size, | ||
| content = previewType.content, | ||
| variant = previewType.variant, | ||
| enabled = previewType.enabled | ||
| ) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,10 @@ | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:width="16dp" | ||
| android:height="14dp" | ||
| android:viewportWidth="16" | ||
| android:viewportHeight="14"> | ||
| <path | ||
| android:pathData="M-0.003,7C-0.003,7.563 0.435,8 0.997,8H12.591L8.309,12.281C8.212,12.374 8.133,12.485 8.08,12.609C8.026,12.732 7.998,12.865 7.997,13C7.997,13.438 8.372,14 9.028,14C9.278,14 9.528,13.906 9.716,13.719L15.716,7.719C15.809,7.624 15.881,7.511 15.929,7.388C15.977,7.264 16,7.132 15.997,7C16.028,6.75 15.919,6.485 15.716,6.281L9.716,0.281C9.53,0.104 9.284,0.004 9.027,0C8.467,0 7.997,0.469 7.997,1C7.997,1.281 8.106,1.515 8.31,1.719L12.59,6H0.997C0.434,6 -0.003,6.438 -0.003,7Z" | ||
| android:fillColor="#2E3036" | ||
| android:fillType="evenOdd"/> | ||
| </vector> |
This file contains hidden or 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,10 @@ | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:width="12dp" | ||
| android:height="12dp" | ||
| android:viewportWidth="12" | ||
| android:viewportHeight="12"> | ||
| <path | ||
| android:pathData="M1.031,12C1.278,11.995 1.514,11.894 1.688,11.719L10,3.406V9C10,9.594 10.469,10.031 11,10.031C11.531,10.031 12,9.563 12,9V0.906C12,0.375 11.531,0 11,0H3C2.406,0 2,0.469 2,1C2,1.5 2.469,2 3,2H8.594L0.219,10.375C0.062,10.531 0,10.781 0,10.969C0,11.562 0.438,12 1.031,12Z" | ||
| android:fillColor="#1A1C1F" | ||
| android:fillType="evenOdd"/> | ||
| </vector> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.