From e6b0ca580a7ac89d3dece519ca68ce5f2f9312d3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 30 Mar 2022 16:41:07 +0600 Subject: [PATCH] support of breadcrumb --- CHANGELOG.md | 2 + .../dev/inmo/jsuikit/elements/Breadcrumb.kt | 50 +++++++++++++++++++ .../inmo/jsuikit/modifiers/UIKitBreadcrumb.kt | 8 +++ 3 files changed, 60 insertions(+) create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/elements/Breadcrumb.kt create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitBreadcrumb.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index eba9c81..190de63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.0.48 +* Added support of `Breadcrumb` + ## 0.0.47 * Add support of `Close` element diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Breadcrumb.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Breadcrumb.kt new file mode 100644 index 0000000..ab2751d --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Breadcrumb.kt @@ -0,0 +1,50 @@ +package dev.inmo.jsuikit.elements + +import androidx.compose.runtime.Composable +import dev.inmo.jsuikit.modifiers.UIKitBreadcrumb +import dev.inmo.jsuikit.modifiers.include +import dev.inmo.jsuikit.utils.Attrs +import org.jetbrains.compose.web.dom.* +import org.w3c.dom.* + +@Composable +fun Breadcrumb( + data: Iterable, + rootAttrs: Attrs = Attrs.empty(), + elementAttrs: Attrs = Attrs.empty(), + elementContent: @Composable ElementScope.(T) -> Unit = {}, +) { + Ul( + { + include(UIKitBreadcrumb) + rootAttrs.builder(this) + } + ) { + data.forEach { + Li({ elementAttrs.builder(this) }) { + elementContent(it) + } + } + } +} + +@Composable +fun BreadcrumbActiveElement( + href: String? = "#", + elementAttrs: Attrs = Attrs.empty(), + elementContent: @Composable ElementScope.() -> Unit = {}, +) { + A(href, { elementAttrs.builder(this) }) { + elementContent() + } +} + +@Composable +fun BreadcrumbInactiveElement( + elementAttrs: Attrs = Attrs.empty(), + elementContent: @Composable ElementScope.() -> Unit = {}, +) { + Span({ elementAttrs.builder(this) }) { + elementContent() + } +} diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitBreadcrumb.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitBreadcrumb.kt new file mode 100644 index 0000000..42c9ad9 --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitBreadcrumb.kt @@ -0,0 +1,8 @@ +package dev.inmo.jsuikit.modifiers + +sealed class UIKitBreadcrumb( + override val classes: Array = emptyArray(), + override val otherAttrs: Map = emptyMap() +) : UIKitModifier { + companion object : UIKitBreadcrumb(arrayOf("uk-breadcrumb")) +}