Composables
Docs Login
Tally

Plan Option

Jetpack Compose Component

Download
package com.composables.tally.components

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.selection.selectable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
import com.composables.compose.ripple.rememberRippleIndication
import com.composables.tally.theme.Check
import com.composables.tally.theme.Icons
import com.composables.tally.theme.Space
import com.composables.tally.theme.Theme

@Composable
fun PlanOption(
    name: String,
    price: String,
    detail: String,
    selected: Boolean,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    badge: String? = null,
) {
    Row(
        modifier
            .fillMaxWidth()
            .clip(Theme.shapes.medium)
            .background(Theme.colors.surface)
            .border(
                if (selected) 2.dp else 1.dp,
                if (selected) Theme.colors.primary else Theme.colors.border,
                Theme.shapes.medium,
            )
            .selectable(
                selected = selected,
                onClick = onClick,
                role = Role.RadioButton,
                interactionSource = remember { MutableInteractionSource() },
                indication = rememberRippleIndication(color = Theme.colors.onSurface),
            )
            .padding(Space * 4),
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.spacedBy(Space * 3),
    ) {
        Box(
            Modifier.size(22.dp)
                .clip(Theme.shapes.fullyRounded)
                .then(
                    if (selected) Modifier.background(Theme.colors.primary)
                    else Modifier.border(1.5.dp, Theme.colors.border, Theme.shapes.fullyRounded)
                ),
            contentAlignment = Alignment.Center,
        ) {
            if (selected)
                Icon(
                    Icons.Check,
                    contentDescription = null,
                    modifier = Modifier.size(14.dp),
                    tint = Theme.colors.onPrimary,
                )
        }
        Column(Modifier.weight(1f)) {
            Row(
                verticalAlignment = Alignment.CenterVertically,
                horizontalArrangement = Arrangement.spacedBy(Space * 2),
            ) {
                Text(name, style = Theme.typography.label, color = Theme.colors.onSurface)
                if (badge != null)
                    Text(
                        badge,
                        style = Theme.typography.caption,
                        color = Theme.colors.onPrimary,
                        modifier =
                            Modifier.clip(Theme.shapes.fullyRounded)
                                .background(Theme.colors.primary)
                                .padding(horizontal = Space * 2, vertical = 1.dp),
                    )
            }
            Text(detail, style = Theme.typography.caption, color = Theme.colors.onBackgroundMuted)
        }
        Text(price, style = Theme.typography.title, color = Theme.colors.onSurface)
    }
}

More components from Tally

by Alex Styl

Search screens and components

Screen flows

Screens

UI Elements

One Android lesson, every Wednesday

Building Android apps?

What Alex learned building Android apps for 14 years, so you don't have to. Reads in under a minute.

Join 3,500+ Android developers. Unsubscribe any time.

You're subscribed

The next lesson lands in on Wednesday.