Skip to content

Commit be1cd15

Browse files
update RadioGroup docs
1 parent 8d391ab commit be1cd15

1 file changed

Lines changed: 45 additions & 2 deletions

File tree

docs/RadioGroup.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ RadioGroup composable displays a title and multiple RadioButtons, one for each o
44

55
![](assets/RadioGroupSample.gif)
66

7+
#### Features :
8+
- It's Generic
9+
- Add a title
10+
- Customize the layout as Row or Column
11+
712
There are two ways to use the RadioGroup :
813

914
### 1. Pass the MutableState directly
@@ -14,7 +19,8 @@ fun RadioGroup(
1419
modifier: Modifier = Modifier,
1520
title: String? = null,
1621
state: MutableState<String?>,
17-
options: List<String>
22+
options: List<String>,
23+
layout: Layout = Layout.Column
1824
)
1925
```
2026

@@ -30,7 +36,44 @@ RadioGroup(
3036
)
3137
```
3238

33-
### 2. Control the MutableState yourself
39+
### 2. Yo! It's Generic
40+
41+
```kotlin
42+
@Composable
43+
fun <T> RadioGroup(
44+
modifier: Modifier = Modifier,
45+
title: String? = null,
46+
state: MutableState<T?>,
47+
options: List<T>,
48+
labelExtractor: (T) -> String,
49+
enabled: Boolean = true,
50+
layout: Layout = Layout.Column
51+
)
52+
```
53+
54+
Example :
55+
56+
```kotlin
57+
data class TouristDestination(
58+
val id: String,
59+
val name: String,
60+
val duration: String,
61+
val cost: Int
62+
)
63+
64+
// User will directly select a TouristDestination only!
65+
val selection = remember {
66+
mutableStateOf<TouristDestination?>(null)
67+
}
68+
69+
RadioGroup(
70+
state = selection,
71+
options = listOf(/* your list of amazing destinations! */),
72+
labelExtractor = { "${it.name} ${it.duration}" }
73+
)
74+
```
75+
76+
### 3. Control the MutableState yourself
3477

3578
```kotlin
3679
@Composable

0 commit comments

Comments
 (0)