diff --git a/CHANGELOG.md b/CHANGELOG.md index c528755..09565f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.0.38 +* Add support of `Toggle` + ## 0.0.37 * `Dialog` now do not add auto margin by default diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitAnimation.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitAnimation.kt index 96216e6..0153b4a 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitAnimation.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitAnimation.kt @@ -62,4 +62,7 @@ sealed class UIKitAnimation (name: String) : UIKitModifier, AttributeValue(name) object KenBurns : UIKitAnimation("kenburns") + override fun toString(): String { + return classes.joinToString(" ") + } } diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitToggle.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitToggle.kt new file mode 100644 index 0000000..e91be23 --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitToggle.kt @@ -0,0 +1,64 @@ +package dev.inmo.jsuikit.modifiers + +import dev.inmo.jsuikit.utils.Milliseconds +import dev.inmo.jsuikit.utils.buildAttribute + +sealed class UIKitToggle( + vararg classnames: String, + override val otherAttrs: Map +) : UIKitModifier { + @Suppress("UNCHECKED_CAST") + override val classes: Array = classnames as Array + + sealed class Mode { + abstract val mode: String + + object Click : Mode() { + override val mode: String + get() = "click" + } + + object Hover : Mode() { + override val mode: String + get() = "hover" + } + + object ClickAndHover : Mode() { + override val mode: String + get() = "${Click.mode}, ${Hover.mode}" + } + + object Media : Mode() { + override val mode: String + get() = "media" + } + + override fun toString(): String = mode + } + + class Custom internal constructor(otherAttrs: Map) : UIKitToggle(otherAttrs = otherAttrs) + + companion object { + operator fun invoke( + target: String? = null, + mode: Mode? = null, + classesToApplyOnToggle: String? = null, + media: String? = null, + animation: UIKitAnimation? = null, + duration: Milliseconds? = null, + queued: Boolean? = null + ) = Custom( + mapOf( + buildAttribute("uk-toggle") { + "target" to target + "mode" to mode + "cls" to classesToApplyOnToggle + "media" to media + "animation" to animation + "duration" to duration + "queued" to queued + } + ) + ) + } +}