Skip to content

Commit 414a42d

Browse files
committed
Add the MdNavigationBar and MdNavigationTab composables
1 parent 4905737 commit 414a42d

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ fun AttrsScope<*>.attrIfNotNull(attr: String, value: String?) {
2626
value?.let { attr(attr, it) }
2727
}
2828

29-
fun AttrsScope<*>.attrIfNotNull(attr: String, isPresent: Boolean?) {
30-
isPresent?.let { attr(attr, it) }
29+
fun AttrsScope<*>.attrIfNotNull(attr: String, value: Boolean?) {
30+
value?.let { attr(attr, it) }
3131
}
3232

3333
fun AttrsScope<*>.attrIfNotNull(attr: String, value: Int?) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.attrIfNotNull
6+
import org.jetbrains.compose.web.dom.ElementScope
7+
import org.jetbrains.compose.web.dom.TagElement
8+
import org.w3c.dom.HTMLElement
9+
10+
/*
11+
https://github.com/material-components/material-web/blob/main/labs/navigationbar/internal/navigation-bar.ts
12+
https://github.com/material-components/material-web/blob/main/labs/navigationbar/demo/stories.ts
13+
*/
14+
15+
@MaterialWebLabsApi
16+
@Composable
17+
fun MdNavigationBar(
18+
activeIndex: Int? = null,
19+
hideInactiveLabels: Boolean? = null,
20+
attrs: Attrs<HTMLElement>? = null,
21+
content: @Composable (ElementScope<HTMLElement>.() -> Unit)?
22+
) {
23+
require("@material/web/labs/navigationbar/navigation-bar.js")
24+
25+
TagElement("md-navigation-bar", {
26+
attrIfNotNull("active-index", activeIndex)
27+
attrIfNotNull("hide-inactive-labels", hideInactiveLabels)
28+
29+
attrs?.invoke(this)
30+
}, content)
31+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.attrIfNotNull
6+
import com.huanshankeji.compose.web.attributes.ext.disabled
7+
import com.huanshankeji.compose.web.attributes.ext.label
8+
import com.huanshankeji.compose.web.attributes.slot
9+
import org.jetbrains.compose.web.attributes.AttrsScope
10+
import org.jetbrains.compose.web.dom.ElementScope
11+
import org.jetbrains.compose.web.dom.TagElement
12+
import org.w3c.dom.HTMLElement
13+
14+
/*
15+
https://github.com/material-components/material-web/blob/main/labs/navigationtab/internal/navigation-tab.ts
16+
https://github.com/material-components/material-web/blob/main/labs/navigationbar/demo/stories.ts (navigation bar storybook)
17+
*/
18+
19+
@MaterialWebLabsApi
20+
@Composable
21+
fun MdNavigationTab(
22+
disabled: Boolean? = null,
23+
active: Boolean? = null,
24+
hideInactiveLabel: Boolean? = null,
25+
label: String? = null,
26+
badgeValue: String? = null,
27+
showBadge: Boolean? = null,
28+
attrs: Attrs<HTMLElement>? = null,
29+
content: @Composable (MdNavigationTabScope.() -> Unit)?
30+
) {
31+
require("@material/web/labs/navigationtab/navigation-tab.js")
32+
33+
TagElement("md-navigation-tab", {
34+
disabled(disabled)
35+
attrIfNotNull("active", active)
36+
attrIfNotNull("hide-inactive-label", hideInactiveLabel)
37+
label(label)
38+
attrIfNotNull("badge-value", badgeValue)
39+
attrIfNotNull("show-badge", showBadge)
40+
41+
attrs?.invoke(this)
42+
}, content?.let { { MdNavigationTabScope(this).it() } })
43+
}
44+
45+
class MdNavigationTabScope(val elementScope: ElementScope<HTMLElement>) {
46+
enum class Slot(val stringValue: String) {
47+
ActiveIcon("active-icon"), InactiveIcon("inactive-icon")
48+
}
49+
50+
fun AttrsScope<*>.slot(value: Slot) =
51+
slot(value.stringValue)
52+
}

0 commit comments

Comments
 (0)