generated from mpetuska/template-kmp-library
-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMDCSwitch.kt
41 lines (38 loc) · 1.11 KB
/
MDCSwitch.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package showcases
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import dev.petuska.katalog.runtime.Showcase
import dev.petuska.katalog.runtime.layout.InteractiveShowcase
import dev.petuska.kmdc.form.field.MDCFormField
import dev.petuska.kmdc.switch.MDCSwitch
import org.jetbrains.compose.web.attributes.disabled
import sandbox.control.BooleanControl
import sandbox.control.TextControl
private class MDCSwitchVM {
var disabled by mutableStateOf(false)
var selected by mutableStateOf(false)
var label by mutableStateOf("on/off")
}
@Composable
@Showcase(id = "MDCSwitch")
fun MDCSwitch() = InteractiveShowcase(
viewModel = { MDCSwitchVM() },
controls = {
BooleanControl("Disabled", ::disabled)
BooleanControl("Selected", ::selected)
TextControl("Label", ::label)
},
) {
MDCFormField {
MDCSwitch(
selected = selected,
label = label.takeIf(String::isNotBlank),
attrs = {
if (disabled) disabled()
onClick { selected = !selected }
}
)
}
}