|
| 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