From 528f6652e0878cf1630d69924111bd7069eeaf61 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 23 Feb 2022 20:25:13 +0600 Subject: [PATCH 1/4] start 0.0.37 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 646ea91..de7ef7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.0.37 + ## 0.0.36 * Reorder arguments in `DefaultComment` fun diff --git a/gradle.properties b/gradle.properties index 5e98a7e..27f8c41 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,4 +9,4 @@ android.enableJetifier=true # Project data group=dev.inmo -version=0.0.36 +version=0.0.37 From 6f913c0a837b0efe8464ae7ba4db471186ac9a20 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 23 Feb 2022 20:25:27 +0600 Subject: [PATCH 2/4] Accordion --- CHANGELOG.md | 2 + .../dev/inmo/jsuikit/elements/Accordion.kt | 89 +++++++++++++++++++ .../inmo/jsuikit/modifiers/UIKitAccordion.kt | 51 +++++++++++ .../inmo/jsuikit/modifiers/UIKitUtility.kt | 2 + 4 files changed, 144 insertions(+) create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/elements/Accordion.kt create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitAccordion.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index de7ef7b..6ad064e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.0.37 +* Support of `Accordion` element + ## 0.0.36 * Reorder arguments in `DefaultComment` fun diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Accordion.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Accordion.kt new file mode 100644 index 0000000..36eb804 --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Accordion.kt @@ -0,0 +1,89 @@ +package dev.inmo.jsuikit.elements + +import androidx.compose.runtime.Composable +import dev.inmo.jsuikit.modifiers.UIKitAccordion +import dev.inmo.jsuikit.modifiers.include +import dev.inmo.jsuikit.utils.Attrs +import org.jetbrains.compose.web.attributes.AttrsBuilder +import org.jetbrains.compose.web.dom.* +import org.w3c.dom.* + +@Composable +fun Accordion( + data: Iterable, + attrs: Attrs = Attrs.empty(), + itemAttrsBuilder: AttrsBuilder.(Int, T) -> Unit = { _, _ -> }, + itemContentBuilder: @Composable ElementScope.(Int, T) -> Unit +) { + Ul( + { + include() + attrs.builder(this) + } + ) { + data.forEachIndexed { i, t -> + Li({ itemAttrsBuilder(i, t) }) { + itemContentBuilder(i, t) + } + } + } +} + +@Composable +fun DefaultAccordion( + data: Iterable, + attrs: Attrs = Attrs.empty(), + itemAttrsBuilder: AttrsBuilder.(Int, T) -> Unit = { _, _ -> }, + titleAttrsBuilder: AttrsBuilder.(Int, T) -> Unit = { _, _ -> }, + titleContentBuilder: @Composable ElementScope.(Int, T) -> Unit = { _, _ -> }, + beforeTitleContentBuilder: @Composable ElementScope.(Int, T) -> Unit = { _, _ -> }, + afterTitleContentBuilder: @Composable ElementScope.(Int, T) -> Unit = { _, _ -> }, + afterContentContentBuilder: @Composable ElementScope.(Int, T) -> Unit = { _, _ -> }, + contentAttrsBuilder: AttrsBuilder.(Int, T) -> Unit = { _, _ -> }, + contentContentBuilder: @Composable ElementScope.(Int, T) -> Unit +) = Accordion( + data, + attrs, + itemAttrsBuilder +) { i, t -> + beforeTitleContentBuilder(i, t) + A( + attrs = { + include(UIKitAccordion.Title) + titleAttrsBuilder(i, t) + } + ) { + titleContentBuilder(i, t) + } + afterTitleContentBuilder(i, t) + Div( + { + include(UIKitAccordion.Content) + contentAttrsBuilder(i, t) + } + ) { + contentContentBuilder(i, t) + } + afterContentContentBuilder(i, t) +} + +@Composable +fun DefaultAccordion( + data: Iterable, + titleResolver: (Int, T) -> String, + attrs: Attrs = Attrs.empty(), + itemAttrsBuilder: AttrsBuilder.(Int, T) -> Unit = { _, _ -> }, + titleAttrsBuilder: AttrsBuilder.(Int, T) -> Unit = { _, _ -> }, + contentAttrsBuilder: AttrsBuilder.(Int, T) -> Unit = { _, _ -> }, + contentContentBuilder: @Composable ElementScope.(Int, T) -> Unit +) = DefaultAccordion( + data, + attrs, + itemAttrsBuilder, + titleAttrsBuilder, + { i, t -> + org.jetbrains.compose.web.dom.Text(titleResolver(i, t)) + }, + contentAttrsBuilder = contentAttrsBuilder, + contentContentBuilder = contentContentBuilder +) diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitAccordion.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitAccordion.kt new file mode 100644 index 0000000..85554ea --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitAccordion.kt @@ -0,0 +1,51 @@ +package dev.inmo.jsuikit.modifiers + +import dev.inmo.jsuikit.utils.* +import org.w3c.dom.PageTransitionEvent + +sealed class UIKitAccordion( + vararg classnames: String, + override val otherAttrs: Map = emptyMap() +) : UIKitModifier { + @Suppress("UNCHECKED_CAST") + override val classes: Array = classnames as Array + + object Title : UIKitAccordion("uk-accordion-title") + object Content : UIKitAccordion("uk-accordion-content") + + class Custom internal constructor( + otherAttrs: Map = emptyMap() + ) : UIKitAccordion (otherAttrs = otherAttrs) + + companion object : UIKitAccordion("uk-accordion") { + val Open = UIKitUtility.Open + + operator fun invoke( + activeItemIndex: Int? = null, + animation: Boolean? = null, + collapsible: Boolean? = null, + contentSelector: String? = null, + animationDuration: Milliseconds? = null, + multiple: Boolean? = null, + targetsSelector: String? = null, + toggleSelector: String? = null, + transition: PageTransitionEvent? = null, + offsetTopPixels: Int? = null, + ) = Custom( + mapOf( + buildAttribute("uk-accordion") { + "active" to activeItemIndex + "animation" to animation + "collapsible" to collapsible + "content" to contentSelector + "duration" to animationDuration + "multiple" to multiple + "targets" to targetsSelector + "toggle" to toggleSelector + "transition" to transition + "offset" to offsetTopPixels + } + ) + ) + } +} diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitUtility.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitUtility.kt index 7833989..97f5249 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitUtility.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitUtility.kt @@ -109,4 +109,6 @@ sealed class UIKitUtility(classname: String) : UIKitModifier { object Disabled : UIKitUtility("uk-disabled") object Drag : UIKitUtility("uk-drag") object Active : UIKitUtility("uk-active") + + object Open : UIKitUtility("uk-open") } From ebbfac67638e1c26b84508989beb082048a7eee7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 23 Feb 2022 23:10:19 +0600 Subject: [PATCH 3/4] fix in Accordion and UIKitAccordion.Companion --- src/jsMain/kotlin/dev/inmo/jsuikit/elements/Accordion.kt | 2 +- src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitAccordion.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Accordion.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Accordion.kt index 36eb804..9d91b34 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Accordion.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Accordion.kt @@ -17,7 +17,7 @@ fun Accordion( ) { Ul( { - include() + include(UIKitAccordion) attrs.builder(this) } ) { diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitAccordion.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitAccordion.kt index 85554ea..abecd54 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitAccordion.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitAccordion.kt @@ -17,7 +17,7 @@ sealed class UIKitAccordion( otherAttrs: Map = emptyMap() ) : UIKitAccordion (otherAttrs = otherAttrs) - companion object : UIKitAccordion("uk-accordion") { + companion object : UIKitAccordion("uk-accordion", otherAttrs = mapOf("uk-accordion" to "")) { val Open = UIKitUtility.Open operator fun invoke( From 0b40c3acf089bfa8379cd29ae6d7c9e596c884b9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 24 Feb 2022 14:42:45 +0600 Subject: [PATCH 4/4] remove auto margin from dialog --- CHANGELOG.md | 1 + src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ad064e..9b09de4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 0.0.37 +* `Dialog` now do not add auto margin by default * Support of `Accordion` element ## 0.0.36 diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt index 2771ac2..f6df0e2 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt @@ -44,7 +44,7 @@ fun Dialog( include(UIKitModal) } id("dialog${Random.nextUInt()}") - include(*modifiers, UIKitFlex.Alignment.Vertical.Top) + include(*modifiers) attributesCustomizer() } ) {