From 9dd486090afcda25ce06611d9c935f432c14bbb5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 8 Feb 2022 18:48:20 +0600 Subject: [PATCH 1/3] start 0.0.32 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c8704f..0dc46f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.0.32 + ## 0.0.31 * Support of `UIKitVisibility` diff --git a/gradle.properties b/gradle.properties index 0d2ba91..9cd45b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,4 +9,4 @@ android.enableJetifier=true # Project data group=dev.inmo -version=0.0.31 +version=0.0.32 From e10bbdeaa07db6441d1c2fa0a71ca92df6fbcf37 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 8 Feb 2022 18:48:49 +0600 Subject: [PATCH 2/3] support of UIKitHeight, AttributesBuilder and Percents/Pixels abstractions --- CHANGELOG.md | 4 + .../dev/inmo/jsuikit/modifiers/UIKitHeight.kt | 80 +++++++++++++++++++ .../jsuikit/modifiers/UIKitTooltipModifier.kt | 19 ++--- .../inmo/jsuikit/utils/AttributeBuilder.kt | 21 +++++ .../kotlin/dev/inmo/jsuikit/utils/Percents.kt | 5 ++ .../kotlin/dev/inmo/jsuikit/utils/Pixels.kt | 5 ++ 6 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitHeight.kt create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/utils/AttributeBuilder.kt create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/utils/Percents.kt create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/utils/Pixels.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dc46f5..8133ad1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.0.32 +* Support of `UIKitHeight` +* New builder `AttributesBuilder` +* New `Percents`/`Pixels` abstractions + ## 0.0.31 * Support of `UIKitVisibility` diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitHeight.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitHeight.kt new file mode 100644 index 0000000..8fe6513 --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitHeight.kt @@ -0,0 +1,80 @@ +package dev.inmo.jsuikit.modifiers + +import dev.inmo.jsuikit.utils.* +import org.jetbrains.compose.web.css.CSSKeyframe + +sealed class UIKitHeight( + classname: String?, + override val otherAttrs: Map = emptyMap() +) : UIKitModifier { + override val classes: Array = classname ?.let { arrayOf(it) } ?: emptyArray() + + object Full : UIKitHeight("uk-height-1-1") + + sealed class Size(classname: String) : UIKitHeight(classname) { + + sealed class Small(classname: String = "uk-height-small") : Size(classname) { + object Max : Small("uk-height-max-small") + + companion object : Small() + } + + sealed class Medium(classname: String = "uk-height-medium") : Size(classname) { + object Max : Medium("uk-height-max-medium") + + companion object : Medium() + } + + sealed class Large(classname: String = "uk-height-large") : Size(classname) { + object Max : Large("uk-height-max-large") + + companion object : Large() + } + + } + + class Viewport(offsetTop: Boolean? = null, offsetBottom: String? = null, expand: Boolean? = null, minHeight: Int? = null) : UIKitHeight( + null, + mapOf( + buildAttribute("uk-height-viewport") { + offsetTop ?.let { "offset-top" to it.toString() } + offsetBottom ?.let { "offset-bottom" to it } + expand ?.let { "expand" to it.toString() } + minHeight ?.let { "min-height" to it.toString() } + } + ) + ) + + fun Viewport( + offsetTop: Boolean? = null, + offsetBottom: Boolean, + expand: Boolean? = null, + minHeight: Int? = null + ) = Viewport(offsetTop, offsetBottom.toString(), expand, minHeight) + + fun Viewport( + offsetTop: Boolean? = null, + offsetBottom: Pixels, + expand: Boolean? = null, + minHeight: Int? = null + ) = Viewport(offsetTop, offsetBottom.toString(), expand, minHeight) + + fun Viewport( + offsetTop: Boolean? = null, + offsetBottom: Percents, + expand: Boolean? = null, + minHeight: Int? = null + ) = Viewport(offsetTop, offsetBottom.toString(), expand, minHeight) + + + class Match(target: String? = null, row: Boolean? = null) : UIKitHeight( + null, + mapOf( + buildAttribute("uk-height-match") { + target ?.let { "target" to it } + row ?.let { "row" to it.toString() } + } + ) + ) + +} diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitTooltipModifier.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitTooltipModifier.kt index 18ec8b2..da29f8c 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitTooltipModifier.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitTooltipModifier.kt @@ -1,5 +1,7 @@ package dev.inmo.jsuikit.modifiers +import dev.inmo.jsuikit.utils.buildAttribute + class UIKitTooltipModifier( text: String, align: Align? = null, @@ -8,16 +10,15 @@ class UIKitTooltipModifier( duration: Int? = null, animation: UIKitAnimation? = null ) : UIKitModifier { - private val parametersMap = listOfNotNull( - "title" to text, - align ?.let { it.k to it.v }, - delay ?.let { "delay" to it.toString() }, - offset ?.let { "offset" to it.toString() }, - duration ?.let { "duration" to it.toString() }, - animation ?.let { "animation" to it.name }, - ) override val otherAttrs: Map = mapOf( - "uk-tooltip" to parametersMap.joinToString(";") { (k, v) -> "$k: $v" } + buildAttribute("uk-tooltip") { + "title" to text + align ?.let { it.k to it.v } + delay ?.let { "delay" to it.toString() } + offset ?.let { "offset" to it.toString() } + duration ?.let { "duration" to it.toString() } + animation ?.let { "animation" to it.name } + } ) sealed class Align(name: String) { diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/utils/AttributeBuilder.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/utils/AttributeBuilder.kt new file mode 100644 index 0000000..0b6674a --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/utils/AttributeBuilder.kt @@ -0,0 +1,21 @@ +package dev.inmo.jsuikit.utils + +class AttributeBuilder ( + val attributeName: String, + private val parametersPreset: MutableMap = mutableMapOf() +) { + + fun add(k: String, v: String? = null) = parametersPreset.set(k, v) + infix fun String.to(value: String?) = add(this, value) + operator fun String.unaryPlus() = add(this, null) + + fun build(): Pair = Pair( + attributeName, parametersPreset.toList().joinToString(";") { + "${it.first}${it.second ?.let { ": $it" } ?: ""}" + } + ) +} + +inline fun buildAttribute(attributeName: String, block: AttributeBuilder.() -> Unit) = AttributeBuilder( + attributeName +).apply(block).build() diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/utils/Percents.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/utils/Percents.kt new file mode 100644 index 0000000..b5b2af1 --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/utils/Percents.kt @@ -0,0 +1,5 @@ +package dev.inmo.jsuikit.utils + +value class Percents(val int: Int) { + override fun toString(): String = "${int}%" +} diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/utils/Pixels.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/utils/Pixels.kt new file mode 100644 index 0000000..cc6cb0f --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/utils/Pixels.kt @@ -0,0 +1,5 @@ +package dev.inmo.jsuikit.utils + +value class Pixels(val int: Int) { + override fun toString(): String = "${int}px" +} From 6f4f1776c445543313b7a416223bd282f3c2bbf9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 8 Feb 2022 19:12:24 +0600 Subject: [PATCH 3/3] fix in UIKitWidth#Fixed --- CHANGELOG.md | 1 + src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitWidth.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8133ad1..4300c74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Support of `UIKitHeight` * New builder `AttributesBuilder` * New `Percents`/`Pixels` abstractions +* Fixes in `UIKitWidth#Fixed` classnames ## 0.0.31 diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitWidth.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitWidth.kt index e81a5fd..4340be5 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitWidth.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitWidth.kt @@ -57,7 +57,7 @@ sealed class UIKitWidth(classname: String) : UIKitModifier { } } - sealed class Fixed(suffix: String) : UIKitWidth("uk-width-fixed-$suffix") { + sealed class Fixed(suffix: String) : UIKitWidth("uk-width-$suffix") { object Small : Fixed("small") object Medium : Fixed("medium")