Skip to content

Commit 8f3692e

Browse files
committed
Add the FAB composables
1 parent 5b47847 commit 8f3692e

File tree

2 files changed

+73
-0
lines changed
  • compose-html-common/src/jsMain/kotlin/com/huanshankeji/compose/web/attributes/ext
  • compose-html-material3/src/jsMain/kotlin/com/huanshankeji/compose/html/material3

2 files changed

+73
-0
lines changed

compose-html-common/src/jsMain/kotlin/com/huanshankeji/compose/web/attributes/ext/Attrs.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ fun AttrsScope<*>.required(value: Boolean?) =
6969
attrIfNotNull("required", value)
7070

7171
// https://www.geeksforgeeks.org/html-label-attribute/
72+
// https://www.w3schools.com/tags/att_label.asp
7273
fun AttrsScope<*>.label(value: String?) =
7374
attrIfNotNull("label", value)
7475

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.huanshankeji.compose.html.material3
2+
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
9+
import org.jetbrains.compose.web.dom.ElementScope
10+
import org.jetbrains.compose.web.dom.TagElement
11+
import org.w3c.dom.HTMLElement
12+
13+
/*
14+
https://github.com/material-components/material-web/blob/main/docs/components/fab.md
15+
https://material-web.dev/components/fab/
16+
https://material-web.dev/components/fab/stories/
17+
*/
18+
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)?
62+
) {
63+
require("@material/web/fab/branded-fab.js")
64+
65+
CommonMdFab("md-branded-fab", variant, size, label, lowered, attrs, content)
66+
}
67+
68+
69+
class MdFabScope(val elementScope: ElementScope<HTMLElement>) {
70+
fun AttrsScope<*>.slotEqIcon() =
71+
slot("icon")
72+
}

0 commit comments

Comments
 (0)