Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type safe inline css #31

Open
StokeMasterJack opened this issue Feb 28, 2017 · 11 comments
Open

type safe inline css #31

StokeMasterJack opened this issue Feb 28, 2017 · 11 comments
Assignees

Comments

@StokeMasterJack
Copy link

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
Copy link
Author

I would suggest looking at the jsxstyle project for inspiration.

@cy6erGn0m
Copy link
Contributor

most likely we need to integrate one of existing css libraries

@AfraidKnot
Copy link

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.

@Miha-x64
Copy link

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.

@StokeMasterJack
Copy link
Author

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

@cy6erGn0m
Copy link
Contributor

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

@marshallpierce
Copy link

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

@ScottPierce
Copy link

Having this would dramatically increase the usability of kotlinx.html

@ScottPierce
Copy link

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.

@quickstep24
Copy link

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

@mgroth0
Copy link

mgroth0 commented Jun 11, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants