Skip to content

Commit 9596dd8

Browse files
committed
Refactor the TextField composable to use modifiers
1 parent 3b02b6d commit 9596dd8

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

compose-multiplatform-material/src/androidxCommonMain/kotlin/com/huanshankeji/compose/material/TextField.androidxCommon.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package com.huanshankeji.compose.material
22

33
import androidx.compose.runtime.Composable
4-
import com.huanshankeji.compose.ui.Element
5-
import com.huanshankeji.compose.ui.ModifierOrAttrs
6-
import com.huanshankeji.compose.ui.toModifier
7-
8-
actual abstract class TextFieldElement : Element()
4+
import com.huanshankeji.compose.ui.Modifier
95

106
@Composable
117
actual fun TextField(
128
value: String,
139
onValueChange: (String) -> Unit,
14-
modifierOrAttrs: ModifierOrAttrs<TextFieldElement>,
10+
modifier: Modifier,
1511
enabled: Boolean,
1612
label: String?,
1713
leadingIcon: @Composable (() -> Unit)?,
@@ -20,7 +16,7 @@ actual fun TextField(
2016
androidx.compose.material.TextField(
2117
value,
2218
onValueChange,
23-
modifierOrAttrs.toModifier(),
19+
modifier.platformModifier,
2420
enabled = enabled,
2521
label = label?.let { { Text(it) } },
2622
leadingIcon = leadingIcon,
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
package com.huanshankeji.compose.material
22

33
import androidx.compose.runtime.Composable
4-
import com.huanshankeji.compose.ui.Element
5-
import com.huanshankeji.compose.ui.ModifierOrAttrs
6-
7-
expect abstract class TextFieldElement : Element
4+
import com.huanshankeji.compose.ui.Modifier
85

96
@Composable
107
expect fun TextField(
118
value: String,
129
onValueChange: (String) -> Unit,
13-
modifierOrAttrs: ModifierOrAttrs<TextFieldElement> = null,
10+
modifier: Modifier = Modifier,
1411
enabled: Boolean = true,
1512
label: String? = null,
1613
/*
14+
// These 2 are not the same thing.
1715
placeholder: String? = null,
1816
helperText: String? = null,
1917
*/
2018
leadingIcon: @Composable (() -> Unit)? = null,
21-
trailingIcon: @Composable (() -> Unit)? = null,
19+
trailingIcon: @Composable (() -> Unit)? = null
2220
)

compose-multiplatform-material/src/jsMain/kotlin/com/huanshankeji/compose/material/TextField.js.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
package com.huanshankeji.compose.material
22

33
import androidx.compose.runtime.Composable
4-
import com.huanshankeji.compose.ui.ModifierOrAttrs
5-
import com.huanshankeji.compose.ui.toAttrs
4+
import com.huanshankeji.compose.ui.Modifier
5+
import com.varabyte.kobweb.compose.ui.toAttrs
66
import dev.petuska.kmdc.textfield.MDCTextField
7-
import org.w3c.dom.HTMLInputElement
8-
9-
actual typealias TextFieldElement = HTMLInputElement
107

118
@Composable
129
actual fun TextField(
1310
value: String,
1411
onValueChange: (String) -> Unit,
15-
modifierOrAttrs: ModifierOrAttrs<TextFieldElement>,
12+
modifier: Modifier,
1613
enabled: Boolean,
1714
label: String?,
1815
leadingIcon: @Composable (() -> Unit)?,
1916
trailingIcon: @Composable (() -> Unit)?,
2017
) =
2118
MDCTextField(value,
22-
attrs = {
19+
attrs = modifier.platformModifier.toAttrs {
2320
onInput { onValueChange(it.value) }
24-
modifierOrAttrs.toAttrs()?.let { it() }
2521
},
2622
disabled = !enabled,
2723
label = label,

0 commit comments

Comments
 (0)