50 lines
1.1 KiB
Kotlin
50 lines
1.1 KiB
Kotlin
package de.pheerai.buzzer.alpine
|
|
|
|
import kotlinx.html.HTMLTag
|
|
|
|
fun HTMLTag.xData(data: String) {
|
|
attributes["x-data"] = data
|
|
}
|
|
|
|
fun HTMLTag.xInit(init: String) {
|
|
attributes["x-init"] = init
|
|
}
|
|
|
|
fun HTMLTag.xOn(event: String, handler: String, debounce: Boolean = false, debounceMs: Int = 0) {
|
|
val debounceString = if (debounce && debounceMs > 0) {
|
|
".debounce.${debounceMs}ms"
|
|
} else if (debounce) {
|
|
".debounce"
|
|
} else {
|
|
""
|
|
}
|
|
attributes["x-on:${event}$debounceString"] = handler
|
|
}
|
|
|
|
fun HTMLTag.xModel(model: String, debounce: Boolean = false, debounceMs: Int = 0) {
|
|
val debounceString = if (debounce && debounceMs > 0) {
|
|
".debounce.${debounceMs}ms"
|
|
} else if (debounce) {
|
|
".debounce"
|
|
} else {
|
|
""
|
|
}
|
|
attributes["x-model$debounceString"] = model
|
|
}
|
|
|
|
fun HTMLTag.xShow(data: String) {
|
|
attributes["x-show"] = data
|
|
}
|
|
|
|
fun HTMLTag.xText(text: String) {
|
|
attributes["x-text"] = text
|
|
}
|
|
|
|
fun HTMLTag.xBind(type: String, data: String) {
|
|
attributes["x-bind:$type"] = data
|
|
}
|
|
|
|
fun HTMLTag.xEffect(effect: String) {
|
|
attributes["x-effect"] = effect
|
|
}
|