Merge pull request #39 from InsanusMokrassar/0.0.38

0.0.38
This commit is contained in:
InsanusMokrassar 2022-02-25 00:36:19 +06:00 committed by GitHub
commit 7b6a8c81b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 1 deletions

View File

@ -1,5 +1,10 @@
# Changelog
## 0.0.38
* Add support of `Toggle`
* Attributes collection now can be concatenated
## 0.0.37
* `Dialog` now do not add auto margin by default

View File

@ -9,4 +9,4 @@ android.enableJetifier=true
# Project data
group=dev.inmo
version=0.0.37
version=0.0.38

View File

@ -62,4 +62,7 @@ sealed class UIKitAnimation (name: String) : UIKitModifier, AttributeValue(name)
object KenBurns : UIKitAnimation("kenburns")
override fun toString(): String {
return classes.joinToString(" ")
}
}

View File

@ -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<String, String>
) : UIKitModifier {
@Suppress("UNCHECKED_CAST")
override val classes: Array<String> = classnames as Array<String>
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<String, String>) : 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
}
)
)
}
}

View File

@ -15,6 +15,13 @@ class AttributesCollection<T : Element> (
attrs()
}
operator fun plus(other: AttributesCollection<T>) = AttributesCollection<T>(
*(modifiers + other.modifiers).distinct().toTypedArray()
) {
this@AttributesCollection.attrs.invoke(this)
other.attrs.invoke(this)
}
companion object {
val Empty = Attrs<Element>()