Has anyone here used the ktor html DSL to build a ...
# ktor
t
Has anyone here used the ktor html DSL to build a component library, like you would do with React or Vue? Reusable HTML components, represented by classes or functions. I was trying to do so, but with createHTML() I ended up always returning the html of the component as a string, which forces me to wrap it with unsafe{}. I'm sure theres a better solution to this, maybe someone has an idea?
b
Generally with the kotlinx-html DSL the approach is to just introduce extension functions on
FlowContent
or other contexts like:
Copy code
fun FlowContent.navigationLabel(
    inputId: String,
    navGroup: String,
    block: LABEL.() -> Unit
) = label {
    htmlFor = inputId
    tabIndex = if (navGroups.add(navGroup)) "0" else "-1"

    block()
}
There's also a #kotlinx-html channel for this topic
r
That's pretty much what I did as well ☝️
a
I have dumped the shadcn github repo and asked claude to transform some components in HTML DSL and that worked pretty well tbh