Add reusable radio button (#3973)

This commit is contained in:
David Perez 2024-09-26 10:59:17 -05:00 committed by GitHub
parent 9213b4843f
commit 21e1d8b5bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 3 deletions

View file

@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -14,6 +13,7 @@ import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.x8bit.bitwarden.ui.platform.base.util.Text import com.x8bit.bitwarden.ui.platform.base.util.Text
import com.x8bit.bitwarden.ui.platform.components.radio.BitwardenRadioButton
/** /**
* A clickable item that displays a radio button and text. * A clickable item that displays a radio button and text.
@ -38,9 +38,9 @@ fun BitwardenSelectionRow(
}, },
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {
RadioButton( BitwardenRadioButton(
modifier = Modifier.padding(16.dp), modifier = Modifier.padding(16.dp),
selected = isSelected, isSelected = isSelected,
onClick = null, onClick = null,
) )
Text( Text(

View file

@ -0,0 +1,27 @@
package com.x8bit.bitwarden.ui.platform.components.radio
import androidx.compose.material3.RadioButton
import androidx.compose.material3.RadioButtonDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
/**
* A custom Bitwarden-themed radio button.
*
* @param isSelected Whether this radio button is selected or not.
* @param onClick The lambda to be invoked when the item is clicked.
* @param modifier The [Modifier] to be applied to this radio button.
*/
@Composable
fun BitwardenRadioButton(
isSelected: Boolean,
onClick: (() -> Unit)?,
modifier: Modifier = Modifier,
) {
RadioButton(
modifier = modifier,
selected = isSelected,
onClick = onClick,
colors = RadioButtonDefaults.colors(),
)
}