jdelaney
09/23/2019, 2:59 PMkotlinx.html
, is there a way to apply a class to all children of a tag? e.g. if I have
fun BODY.card(block: DIV.() -> Unit = {}) {
div("card") {
// I want to apply the "section" class to
// the top-level tags here
block()
}
}
https://github.com/kotlin/kotlinx.html/wiki/Interceptors mentions the ability to transform some HTML but doesn't actually say how.
(I know this isn't best practice for CSS but I'm trying to make some generic functions for a CSS framework I'm using)Soren Valle
09/23/2019, 3:22 PMjdelaney
09/23/2019, 3:28 PMSoren Valle
09/23/2019, 10:33 PMiimport kotlinx.html.DIV
import kotlinx.html.div
import kotlinx.html.dom.append
import kotlin.browser.document
import kotlin.browser.window
fun DIV.card(block: (DIV.(classes: String) -> Unit)? = null) {
div("card") {
+"Card"
block?.let { it("section") }
}
}
fun main() {
window.onload = {
document.getElementById("root")!!.append {
div {
+"Card Consumer"
card { classes ->
div(classes) {
+"Section 1"
}
div(classes) {
+"Section 2"
}
div(classes) {
+"Section 3"
}
}
}
}
}
}
jdelaney
09/24/2019, 1:25 AM