mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2024-12-22 08:37:24 +00:00
support of UIKitHeight, AttributesBuilder and Percents/Pixels abstractions
This commit is contained in:
parent
9dd486090a
commit
e10bbdeaa0
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## 0.0.32
|
## 0.0.32
|
||||||
|
|
||||||
|
* Support of `UIKitHeight`
|
||||||
|
* New builder `AttributesBuilder`
|
||||||
|
* New `Percents`/`Pixels` abstractions
|
||||||
|
|
||||||
## 0.0.31
|
## 0.0.31
|
||||||
|
|
||||||
* Support of `UIKitVisibility`
|
* Support of `UIKitVisibility`
|
||||||
|
80
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitHeight.kt
Normal file
80
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitHeight.kt
Normal file
@ -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<String, String> = emptyMap()
|
||||||
|
) : UIKitModifier {
|
||||||
|
override val classes: Array<String> = 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() }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package dev.inmo.jsuikit.modifiers
|
package dev.inmo.jsuikit.modifiers
|
||||||
|
|
||||||
|
import dev.inmo.jsuikit.utils.buildAttribute
|
||||||
|
|
||||||
class UIKitTooltipModifier(
|
class UIKitTooltipModifier(
|
||||||
text: String,
|
text: String,
|
||||||
align: Align? = null,
|
align: Align? = null,
|
||||||
@ -8,16 +10,15 @@ class UIKitTooltipModifier(
|
|||||||
duration: Int? = null,
|
duration: Int? = null,
|
||||||
animation: UIKitAnimation? = null
|
animation: UIKitAnimation? = null
|
||||||
) : UIKitModifier {
|
) : 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<String, String> = mapOf(
|
override val otherAttrs: Map<String, String> = 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) {
|
sealed class Align(name: String) {
|
||||||
|
21
src/jsMain/kotlin/dev/inmo/jsuikit/utils/AttributeBuilder.kt
Normal file
21
src/jsMain/kotlin/dev/inmo/jsuikit/utils/AttributeBuilder.kt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package dev.inmo.jsuikit.utils
|
||||||
|
|
||||||
|
class AttributeBuilder (
|
||||||
|
val attributeName: String,
|
||||||
|
private val parametersPreset: MutableMap<String, String?> = 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<String, String> = Pair(
|
||||||
|
attributeName, parametersPreset.toList().joinToString(";") {
|
||||||
|
"${it.first}${it.second ?.let { ": $it" } ?: ""}"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun buildAttribute(attributeName: String, block: AttributeBuilder.() -> Unit) = AttributeBuilder(
|
||||||
|
attributeName
|
||||||
|
).apply(block).build()
|
5
src/jsMain/kotlin/dev/inmo/jsuikit/utils/Percents.kt
Normal file
5
src/jsMain/kotlin/dev/inmo/jsuikit/utils/Percents.kt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package dev.inmo.jsuikit.utils
|
||||||
|
|
||||||
|
value class Percents(val int: Int) {
|
||||||
|
override fun toString(): String = "${int}%"
|
||||||
|
}
|
5
src/jsMain/kotlin/dev/inmo/jsuikit/utils/Pixels.kt
Normal file
5
src/jsMain/kotlin/dev/inmo/jsuikit/utils/Pixels.kt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package dev.inmo.jsuikit.utils
|
||||||
|
|
||||||
|
value class Pixels(val int: Int) {
|
||||||
|
override fun toString(): String = "${int}px"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user