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

type safe inline css

Open StokeMasterJack opened this issue 8 years ago • 11 comments

When I use inline css in an html or jsp file, IntelliJ gives me nice syntax coloring and autocompletion: css-ide

Is there a type safe way to do inline css using kotlinx.html other than using a string? Or at least a way to get autocompletion and syntax coloring?

body {
    div {
        style = "background: yellow;border: solid thin blue"
    }
}

StokeMasterJack avatar Feb 28 '17 23:02 StokeMasterJack

I would suggest looking at the jsxstyle project for inspiration.

StokeMasterJack avatar Mar 02 '17 14:03 StokeMasterJack

most likely we need to integrate one of existing css libraries

cy6erGn0m avatar Apr 06 '17 08:04 cy6erGn0m

For the short term, IntelliJ has a built in "Inject Language or Reference" feature (https://www.jetbrains.com/help/idea/using-language-injections.html) that is helpful in this situation. In short, Press ALT-ENTER, select "Inject language or reference" then select CSS.

AfraidKnot avatar Jul 26 '17 14:07 AfraidKnot

It would be cool for CSS classes to be real things on the level of Kotlin language, so unused classes will be grey in IDE and may be stripped, and used classes may be automatically renamed to have names consisting of 1-2 chars. I mean, DSL should not just repeat CSS itself, but add some extra safety, performance, etc.

Miha-x64 avatar Oct 30 '17 17:10 Miha-x64

Also, GWT had this. Might be worth looking into that.

StokeMasterJack avatar Oct 30 '17 17:10 StokeMasterJack

Perhaps I can annotate all classes and style parameters however it will add corresponding annotations dependency

cy6erGn0m avatar Nov 08 '17 11:11 cy6erGn0m

I'm using https://github.com/olegcherr/Aza-Kotlin-CSS (via an unsafe block) and it works fine for me so far.

marshallpierce avatar Aug 27 '18 17:08 marshallpierce

Having this would dramatically increase the usability of kotlinx.html

ScottPierce avatar Apr 28 '19 19:04 ScottPierce

I tried several alternatives, including the above suggestion of a secondary css library, but I found all of the approaches lacking - primarily that I wanted to use an html library to keep my html code maintainable, but all my html code was ugly and difficult to read.

Over the past several weeks, I've created an alternative library, kotlin-html to add css, provide first-class support for ids, classes, and styles, and provide a simpler architecture so it was easier for people to contribute.

ScottPierce avatar Jul 08 '19 16:07 ScottPierce

inline fun Unsafe.css(@Language("CSS")css: String) = raw(css.trimIndent())

quickstep24 avatar Apr 28 '20 15:04 quickstep24

@Language doesn't resolve for me. It does in jvm modules, but not in js modules.

mgroth0 avatar Jun 11 '22 01:06 mgroth0