-
Notifications
You must be signed in to change notification settings - Fork 8
Replace Native JS Code #14
Comments
I am a beginner in Elm but I have an idea... As far as I see the main problem is injecting the CSS in the HTML. I have done a small POC and works good: module App exposing (..)
import Html exposing (text)
import VirtualDom exposing (node)
main =
node "style"
[]
[ text
"""
body {
background:red;
}
@media (max-width: 600px) {
body {
background: green;
}
}
"""
] The only con of this is that style tag is inserted on the body instead of head, but browsers support this: I hope it helps, by the way thanks for the elm implementation of styled-components! |
Maybe instead of trying to shoehorn the benefits of |
https://github.com/elm-lang/virtual-css just got public and it may be good fit for replacing EDIT: This is unreleased yet and I guessing it will be part of the 0.19 release as well as https://github.com/elm-lang/browser |
I will take a closer look in the future but that looks very promising. Thank you for notifying me. |
Maybe look at this libarary as well to figure out how it does it: http://package.elm-lang.org/packages/mdgriffith/style-elements/latest |
@justgage last time I took a look at styled elements they used inline style attributes to add the styles. This is a problem because they don't support keyframe animation pseudo selectors / classes and media queries. |
I recently realized that only the
elm-lang/core
package is allowed to have native JS code. Currentlyelm-styled
is using native JS code to inject the CSS. The problem is that I can't publishelm-styled
to the official package manager and users would have to install this package directly from GitHub with tools likeelm-github-install
. The last couple of days I thought how to remove the native code fromelm-styled
to finally publish the package. My current solutions are:Monkey Patching
Element.prototype
This would work similar to https://github.com/gdotdesign/elm-html-styles. We would add a new attribute setter to the element prototype and everytime an element is created the styles would inject magically.
Usage
The user would have to inject a single script which monkey patches the elment.prototype.
Pros
Cons
Ports
Usage
styled
with an additional argument which is the Msg type to add styles to the model.Pros
Cons
elm-styled
I would love the get some feedback and suggestions for better solutions.
Maybe someone with more elm experience has a great solution for us.
The text was updated successfully, but these errors were encountered: