From 21e1d8b5bc67d27cbc8f2b5767db8ceda79a2801 Mon Sep 17 00:00:00 2001 From: David Perez Date: Thu, 26 Sep 2024 10:59:17 -0500 Subject: [PATCH] Add reusable radio button (#3973) --- .../dialog/row/BitwardenSelectionRow.kt | 6 ++--- .../components/radio/BitwardenRadioButton.kt | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/x8bit/bitwarden/ui/platform/components/radio/BitwardenRadioButton.kt diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/dialog/row/BitwardenSelectionRow.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/dialog/row/BitwardenSelectionRow.kt index 84a68b8bc..93e96b1b7 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/dialog/row/BitwardenSelectionRow.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/dialog/row/BitwardenSelectionRow.kt @@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.RadioButton import androidx.compose.material3.Text import androidx.compose.runtime.Composable 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.unit.dp 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. @@ -38,9 +38,9 @@ fun BitwardenSelectionRow( }, verticalAlignment = Alignment.CenterVertically, ) { - RadioButton( + BitwardenRadioButton( modifier = Modifier.padding(16.dp), - selected = isSelected, + isSelected = isSelected, onClick = null, ) Text( diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/radio/BitwardenRadioButton.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/radio/BitwardenRadioButton.kt new file mode 100644 index 000000000..f77759e8c --- /dev/null +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/radio/BitwardenRadioButton.kt @@ -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(), + ) +}