Skip to content

Commit fbd6fd4

Browse files
DBFabianWenzelStefan Ankele
andauthored
Feature/ds card component (#5)
* Added DSCard Component * [ADDED] DSCard elevation and spacing parameter * added: preview libs * rework: pullrequest comments --------- Co-authored-by: Stefan Ankele <[email protected]>
1 parent 29d3dd8 commit fbd6fd4

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

components/build.gradle.kts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,21 @@ android {
3737
}
3838

3939
dependencies {
40+
implementation(project(":foundation"))
41+
42+
// Android Studio Preview support
43+
implementation(libs.androidx.ui.graphics)
44+
implementation(libs.androidx.ui.tooling.preview)
45+
debugImplementation(libs.androidx.ui.tooling)
46+
4047
implementation(libs.androidx.core.ktx)
4148
implementation(libs.androidx.appcompat)
4249
implementation(libs.material)
4350
implementation(platform(libs.androidx.compose.bom))
4451
implementation(libs.androidx.ui)
4552
implementation(libs.androidx.material3)
46-
implementation(project(":foundation"))
53+
4754
testImplementation(libs.junit)
4855
androidTestImplementation(libs.androidx.junit)
4956
androidTestImplementation(libs.androidx.espresso.core)
50-
}
57+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.dbsystel.designsystem.components.card
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.border
5+
import androidx.compose.foundation.layout.padding
6+
import androidx.compose.foundation.shape.RoundedCornerShape
7+
import androidx.compose.material3.Surface
8+
import androidx.compose.material3.Text
9+
import androidx.compose.runtime.Composable
10+
import androidx.compose.ui.Modifier
11+
import androidx.compose.ui.graphics.Color
12+
import androidx.compose.ui.tooling.preview.PreviewLightDark
13+
import androidx.compose.ui.tooling.preview.PreviewParameter
14+
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
15+
import androidx.compose.ui.unit.Dp
16+
import androidx.compose.ui.unit.dp
17+
import com.dbsystel.designsystem.foundation.theme.DesignSystemTheme
18+
19+
/**
20+
* The card components are shaded and rounded areas that give the interface depth.
21+
* Whether static or interactive - the cards are the basis for further components and modules and can display content and actions.
22+
*
23+
* @param modifier - custom modifier of the card
24+
* @param elevation - set the background color elevation
25+
* @param spacing - padding of the card
26+
* @param content - content composable
27+
*/
28+
@Composable
29+
fun DSCard(
30+
modifier: Modifier = Modifier,
31+
elevation: DSCardElevation = DSCardElevation.LEVEL_1,
32+
spacing: DSCardSpacing = DSCardSpacing.SMALL,
33+
content: @Composable () -> Unit,
34+
) {
35+
val shape = RoundedCornerShape(DesignSystemTheme.dimensions.border.radiusSm)
36+
37+
Surface(
38+
color = elevation.value(),
39+
tonalElevation = 0.dp,
40+
modifier = Modifier
41+
.background(color = elevation.value(), shape = shape)
42+
.border(
43+
DesignSystemTheme.dimensions.border.height3xs,
44+
color = DesignSystemTheme.activeColor.Basic.Border.Default.Default,
45+
shape = shape
46+
)
47+
.padding(spacing.value())
48+
.then(modifier),
49+
content = content
50+
)
51+
}
52+
53+
enum class DSCardSpacing(val value: @Composable () -> Dp) {
54+
SMALL({ DesignSystemTheme.dimensions.spacing.fixedSm }),
55+
MEDIUM({ DesignSystemTheme.dimensions.spacing.fixedMd }),
56+
LARGE({ DesignSystemTheme.dimensions.spacing.fixedLg })
57+
}
58+
59+
enum class DSCardElevation(val value: @Composable () -> Color) {
60+
LEVEL_1({ DesignSystemTheme.activeColor.bgBasicLevel1Default }),
61+
LEVEL_2({ DesignSystemTheme.activeColor.bgBasicLevel2Default }),
62+
LEVEL_3({ DesignSystemTheme.activeColor.bgBasicLevel3Default })
63+
}
64+
65+
private class DSCardPreviewProvider : PreviewParameterProvider<DSCardPreviewParameterType> {
66+
override val values = DSCardElevation.entries.flatMap { elevation ->
67+
DSCardSpacing.entries.map { spacing ->
68+
DSCardPreviewParameterType(spacing = spacing, elevation = elevation)
69+
}
70+
}.asSequence()
71+
}
72+
73+
private class DSCardPreviewParameterType(val spacing: DSCardSpacing, val elevation: DSCardElevation)
74+
75+
@Composable
76+
@PreviewLightDark
77+
private fun DSCardPreview(
78+
@PreviewParameter(DSCardPreviewProvider::class) previewType: DSCardPreviewParameterType,
79+
) {
80+
DesignSystemTheme {
81+
DSCard(spacing = previewType.spacing, elevation = previewType.elevation) {
82+
Text("Card content")
83+
}
84+
}
85+
}

gradle/libs.versions.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ espressoCore = "3.6.1"
88
appcompat = "1.7.0"
99
composeBom = "2024.10.01"
1010
material = "1.12.0"
11+
uiTooling = "1.7.5"
1112

1213
[libraries]
1314
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@@ -20,6 +21,10 @@ androidx-material3 = { group = "androidx.compose.material3", name = "material3"
2021
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
2122
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
2223

24+
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
25+
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
26+
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "uiTooling" }
27+
2328
[plugins]
2429
com-android-library = { id = "com.android.library", version.ref = "agp" }
2530
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

0 commit comments

Comments
 (0)