File tree Expand file tree Collapse file tree 5 files changed +87
-0
lines changed
compose-multiplatform-common/src/jsMain/kotlin/com/huanshankeji/compose/ui
compose-multiplatform-material/src
commonMain/kotlin/com/huanshankeji/compose/material
jsMain/kotlin/com/huanshankeji/compose/material
jvmMain/kotlin/com/huanshankeji/compose/material Expand file tree Collapse file tree 5 files changed +87
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ There is no plan to support Apple platforms until there is official support from
4141- ` IconButton `
4242- ` ScrollableList ` /` LazyColumn ` (visually inconsistent for now)
4343- ` Text ` /` MaterialText `
44+ - ` TextField `
4445- ` TopAppBarScaffold `
4546
4647### styles
Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ import org.jetbrains.compose.web.css.*
1313import org.jetbrains.compose.web.dom.AttrBuilderContext
1414import org.w3c.dom.HTMLElement
1515
16+ /*
17+ fun <TElement : Element, TAttrsScope : AttrsScope<TElement>> ModifierOrAttrs<TElement>.toAttrs2(): (TAttrsScope.() -> Unit)? =
18+ this?.let { { ModifierOrAttrsScope(this).it() } }
19+ */
20+
1621fun <TElement : Element > ModifierOrAttrs<TElement>.toAttrs (): AttrBuilderContext <TElement >? =
1722 this ?.let { { ModifierOrAttrsScope (this ).it() } }
1823
Original file line number Diff line number Diff line change 1+ package com.huanshankeji.compose.material
2+
3+ 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
8+
9+ @Composable
10+ expect fun TextField (
11+ value : String ,
12+ onValueChange : (String ) -> Unit ,
13+ modifierOrAttrs : ModifierOrAttrs <TextFieldElement > = null,
14+ enabled : Boolean = true,
15+ label : String? = null,
16+ placeholder : String? = null,
17+ leadingIcon : @Composable (() -> Unit )? = null,
18+ trailingIcon : @Composable (() -> Unit )? = null,
19+ )
Original file line number Diff line number Diff line change 1+ package com.huanshankeji.compose.material
2+
3+ import androidx.compose.runtime.Composable
4+ import com.huanshankeji.compose.ui.ModifierOrAttrs
5+ import com.huanshankeji.compose.ui.toAttrs
6+ import dev.petuska.kmdc.textfield.MDCTextField
7+ import org.w3c.dom.HTMLInputElement
8+
9+ actual typealias TextFieldElement = HTMLInputElement
10+
11+ @Composable
12+ actual fun TextField (
13+ value : String ,
14+ onValueChange : (String ) -> Unit ,
15+ modifierOrAttrs : ModifierOrAttrs <TextFieldElement >,
16+ enabled : Boolean ,
17+ label : String? ,
18+ placeholder : String? ,
19+ leadingIcon : @Composable (() -> Unit )? ,
20+ trailingIcon : @Composable (() -> Unit )? ,
21+ ) =
22+ MDCTextField (value,
23+ attrs = {
24+ onInput { onValueChange(it.value) }
25+ modifierOrAttrs.toAttrs()?.let { it() }
26+ },
27+ disabled = ! enabled,
28+ label = label,
29+ helperText = placeholder,
30+ leadingIcon = leadingIcon?.let { { it() } },
31+ trailingIcon = trailingIcon?.let { { it() } }
32+ )
Original file line number Diff line number Diff line change 1+ package com.huanshankeji.compose.material
2+
3+ 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 ()
9+
10+ @Composable
11+ actual fun TextField (
12+ value : String ,
13+ onValueChange : (String ) -> Unit ,
14+ modifierOrAttrs : ModifierOrAttrs <TextFieldElement >,
15+ enabled : Boolean ,
16+ label : String? ,
17+ placeholder : String? ,
18+ leadingIcon : @Composable (() -> Unit )? ,
19+ trailingIcon : @Composable (() -> Unit )? ,
20+ ) =
21+ androidx.compose.material.TextField (
22+ value,
23+ onValueChange,
24+ modifierOrAttrs.toModifier(),
25+ enabled = enabled,
26+ label = label?.let { { Text (it) } },
27+ placeholder = placeholder?.let { { Text (it) } },
28+ leadingIcon = leadingIcon,
29+ trailingIcon = trailingIcon
30+ )
You can’t perform that action at this time.
0 commit comments