Card
A container that groups related content together.
Card
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import com.composables.icons.lucide.Lucide
import com.composables.icons.lucide.Sun
import com.composables.uikit.components.Card
import com.composables.uikit.components.Icon
import com.composables.uikit.components.OutlinedButton
import com.composables.uikit.components.PrimaryButton
import com.composables.uikit.components.Text
import com.composables.uikit.styling.accent
import com.composables.uikit.styling.colors
import com.composables.uikit.styling.onAccent
import com.composables.uikit.styling.textStyles
import com.composables.uikit.styling.title
import com.composeunstyled.theme.Theme
import composables.uikit_examples.generated.resources.Res
import composables.uikit_examples.generated.resources.dish_1
import org.jetbrains.compose.resources.painterResource
@Composable
fun CardExample() {
Card(onClick = { /*TODO*/ }) {
Row {
Icon(
imageVector = Lucide.Sun,
contentDescription = "Sunny",
tint = Theme[colors][onAccent],
modifier = Modifier.background(Theme[colors][accent], CircleShape).padding(12.dp)
)
Spacer(Modifier.width(16.dp))
Column(verticalArrangement = Arrangement.Center) {
Text("33°C in California")
Spacer(Modifier.height(4.dp))
Text("Tap to learn more", modifier = Modifier.alpha(0.5f))
}
}
}
}
Card With Image
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import com.composables.uikit.components.Card
import com.composables.uikit.components.OutlinedButton
import com.composables.uikit.components.PrimaryButton
import com.composables.uikit.components.Text
import com.composables.uikit.styling.textStyles
import com.composables.uikit.styling.title
import com.composeunstyled.theme.Theme
import composables.uikit_examples.generated.resources.Res
import composables.uikit_examples.generated.resources.dish_1
import org.jetbrains.compose.resources.painterResource
@Composable
fun CardWithImageExample() {
Card(
contentPadding = PaddingValues(0.dp),
modifier = Modifier.width(380.dp)
) {
Image(
painter = painterResource(Res.drawable.dish_1),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.fillMaxWidth().aspectRatio(16 / 9f)
)
Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {
Text("Smoky BBQ Classic Burger", style = Theme[textStyles][title])
Text("Juicy beef, cheese, and smoky barbecue sauce on a toasted bun.")
Text("$12.99 • 950 cals")
Spacer(modifier = Modifier.height(8.dp))
Row(horizontalArrangement = Arrangement.spacedBy(24.dp)) {
OutlinedButton(onClick = {}, modifier = Modifier.weight(1f)) {
Text("Customize")
}
PrimaryButton(onClick = {}, modifier = Modifier.weight(1f)) {
Text("Add to Bag")
}
}
}
}
}
Card With Title
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.composables.uikit.components.Card
import com.composables.uikit.components.OutlinedButton
import com.composables.uikit.components.Text
@Composable
fun CardWithTitleExample() {
Card(
title = { Text("Explore the Mountains") },
modifier = Modifier.width(380.dp)
) {
Text("Discover breathtaking trails and scenic views for your next adventure.")
Spacer(modifier = Modifier.height(24.dp))
OutlinedButton(onClick = {}) {
Text("Learn More")
}
}
}