SelectionChip.kt (1709B)
1 /* 2 * This file is part of GNU Taler 3 * (C) 2023 Taler Systems S.A. 4 * 5 * GNU Taler is free software; you can redistribute it and/or modify it under the 6 * terms of the GNU General Public License as published by the Free Software 7 * Foundation; either version 3, or (at your option) any later version. 8 * 9 * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License along with 14 * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 package net.taler.wallet.compose 18 19 import androidx.compose.foundation.shape.CircleShape 20 import androidx.compose.material3.MaterialTheme 21 import androidx.compose.material3.SuggestionChip 22 import androidx.compose.material3.SuggestionChipDefaults 23 import androidx.compose.runtime.Composable 24 import androidx.compose.ui.Modifier 25 import androidx.compose.ui.graphics.Color 26 27 @Composable 28 fun <T> SelectionChip( 29 label: @Composable () -> Unit, 30 modifier: Modifier = Modifier, 31 selected: Boolean, 32 value: T, 33 onSelected: (T) -> Unit, 34 ) { 35 val theme = MaterialTheme.colorScheme 36 SuggestionChip( 37 label = label, 38 modifier = modifier, 39 shape = CircleShape, 40 onClick = { 41 onSelected(value) 42 }, 43 colors = SuggestionChipDefaults.suggestionChipColors( 44 containerColor = if (selected) theme.primaryContainer else Color.Transparent, 45 labelColor = if (selected) theme.onPrimaryContainer else theme.onSurface 46 ) 47 ) 48 }