Skip to content

Commit 514528d

Browse files
committed
Simplify the code in "MdFab.kt" into a minimal example to reproduce the Kotlin 2.0 type inference issue
The issue seems not related to `Composable`.
1 parent c558d8e commit 514528d

File tree

1 file changed

+11
-57
lines changed
  • compose-html-material3/src/jsMain/kotlin/com/huanshankeji/compose/html/material3

1 file changed

+11
-57
lines changed
Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
package com.huanshankeji.compose.html.material3
22

3-
import androidx.compose.runtime.Composable
4-
import com.huanshankeji.compose.web.attributes.Attrs
5-
import com.huanshankeji.compose.web.attributes.attr
6-
import com.huanshankeji.compose.web.attributes.ext.label
7-
import com.huanshankeji.compose.web.attributes.slot
8-
import org.jetbrains.compose.web.attributes.AttrsScope
93
import org.jetbrains.compose.web.dom.ElementScope
10-
import org.jetbrains.compose.web.dom.TagElement
4+
import org.w3c.dom.Element
115
import org.w3c.dom.HTMLElement
126

137
/*
@@ -16,57 +10,17 @@ https://material-web.dev/components/fab/
1610
https://material-web.dev/components/fab/stories/
1711
*/
1812

19-
@Composable
20-
private fun CommonMdFab(
21-
tagName: String,
22-
variant: String?,
23-
size: String?,
24-
label: String?,
25-
lowered: Boolean?,
26-
attrs: Attrs<HTMLElement>?,
27-
content: @Composable (MdFabScope.() -> Unit)?
28-
) =
29-
TagElement(tagName, {
30-
variant?.let { attr("variant", it) }
31-
size?.let { attr("size", it) }
32-
label?.let { label(it) }
33-
lowered?.let { attr("lowered", it) }
34-
35-
attrs?.invoke(this)
36-
}, content?.let {
37-
{ MdFabScope(this).it() }
38-
})
39-
40-
@Composable
41-
fun MdFab(
42-
variant: String? = null,
43-
size: String? = null,
44-
label: String? = null,
45-
lowered: Boolean? = null,
46-
attrs: Attrs<HTMLElement>? = null,
47-
content: @Composable (MdFabScope.() -> Unit)?
48-
) {
49-
require("@material/web/fab/fab.js")
50-
51-
CommonMdFab("md-fab", variant, size, label, lowered, attrs, content)
52-
}
53-
54-
@Composable
55-
fun MdBrandedFab(
56-
variant: String? = null,
57-
size: String? = null,
58-
label: String? = null,
59-
lowered: Boolean? = null,
60-
attrs: Attrs<HTMLElement>? = null,
61-
content: @Composable (MdFabScope.() -> Unit)?
13+
fun <TElement : Element> SimplifiedTagElement(
14+
content: (ElementScope<TElement>.() -> Unit)?
6215
) {
63-
require("@material/web/fab/branded-fab.js")
64-
65-
CommonMdFab("md-branded-fab", variant, size, label, lowered, attrs, content)
16+
TODO()
6617
}
6718

19+
class MdFabScope(val elementScope: ElementScope<HTMLElement>)
6820

69-
class MdFabScope(val elementScope: ElementScope<HTMLElement>) {
70-
fun AttrsScope<*>.slotEqIcon() =
71-
slot("icon")
72-
}
21+
private fun SimplifiedMdFab(
22+
content: (MdFabScope.() -> Unit)?
23+
) =
24+
SimplifiedTagElement(content?.let {
25+
{ MdFabScope(this).it() }
26+
})

0 commit comments

Comments
 (0)