kotlinx.html icon indicating copy to clipboard operation
kotlinx.html copied to clipboard

Add CSS DSL Support

Open mddanishansari opened this issue 5 years ago • 5 comments
trafficstars

We could add support for CSS DSL. Currently there is only one way to write CSS and that's to use hard coded raw strings which very quickly increase the chances of errors.

It would be used something like this.

Inline Style:

div {
    inlineStyle {
        property("margin", "4px")
        property("padding", "8px")
    }
}

Internal style (in header part):

head {
    style {
        rule("div") {
            property("margin", "4px")
            property("padding", "8px")
        }
        rule(".dropdown") {
            property("margin", "4px")
            property("padding", "8px")
        }
    }
}

May be with some brain storming we can add selection DSL also. Please provide your feedback and ideas.

mddanishansari avatar Aug 13 '20 05:08 mddanishansari

I guess this totally makes sence in case of statically-typed DSL. Before you that - string or small local function for converting map to style string is fine, as for me.

dector avatar Aug 13 '20 21:08 dector

Wouldn't this just duplicate what kotlinx-css library does?

mpetuska avatar Oct 04 '20 16:10 mpetuska

Wouldn't this just duplicate what kotlinx-css library does?

What? There is a kotlix-css library? Can you please give me a link to it?

mddanishansari avatar Oct 06 '20 06:10 mddanishansari

https://github.com/JetBrains/kotlin-wrappers/tree/master/kotlin-css

mpetuska avatar Oct 06 '20 07:10 mpetuska

I came across this issue while searching for a similar thing, but I specifically need inline CSS, since I'm using this library to compose HTML emails, and the best practice is to avoid

I don't know if it's more appropriate to request an inline style DSL for this library or for that one, but it would be really nice to have an ergonomic solution to building inline styles with a type-safe DSL.

ragnese avatar Apr 03 '24 14:04 ragnese