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

Support for CSS custom properties #129

Closed
johanalkstal opened this issue Apr 20, 2017 · 5 comments · May be fixed by elm/virtual-dom#127
Closed

Support for CSS custom properties #129

johanalkstal opened this issue Apr 20, 2017 · 5 comments · May be fixed by elm/virtual-dom#127

Comments

@johanalkstal
Copy link

johanalkstal commented Apr 20, 2017

CSS has Custom Properties which can be used both in a CSS file as well as an inline style.
A custom property has the following signature: --*.

This does not appear to be supported by Html.Attributes.style?

I'm using the following code,

applyTheme theme =
    style
        [ ( "--theme-primary-color", theme.primaryColor )
        , ( "--theme-secondary-color", theme.secondaryColor )
        ]

applied like div [ applyTheme theme ] [].

This produces no style attribute on the element. Other CSS properties do.

Would it be possible to add support for this?

https://www.w3.org/TR/css-variables/

@process-bot
Copy link

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@johanalkstal johanalkstal changed the title Support for custom properties Support for CSS custom properties Apr 20, 2017
@evancz
Copy link
Member

evancz commented Jul 7, 2017

I'm not sure the exact purpose of CSS variables when you are working in a language that has variables. It seems like this is a 2nd way to do things we can already do differently, except now without any compiler help for types and typos.

I'm not against doing this particularly, but so far I have not seen any cases that definitively show that this is a good thing to have. I prefer to use GitHub for bugs, not feature requests, so I will close.

@johanalkstal
Copy link
Author

@evancz This isn´t a feature request, this is a bug report. Though I might be too polite to describe it as such.

This library is missing a feature that is a part of the CSS standard. I´m not familiar with the mindset behind the library, but my initial expectation is that it supports the standard that exists.

@waj
Copy link

waj commented Apr 11, 2018

@evancz I found this bug while trying to pass an --indent variable to specify how many "spaces" a piece of HTML has to be indented. The exact amount of pixels is calculated in the CSS using a calc(). But I don't wont to make this calculation in pixels in my Elm code, because I prefer to have all the style details in my CSS file, so I don't see this as 2nd way of doing the same thing.

@harrysarson
Copy link

I believe that in the virtual dom source at line 509 (https://github.com/elm-lang/virtual-dom/blob/master/src/Elm/Kernel/VirtualDom.js#L509), if

domNodeStyle[key] = styles[key]

was replaced with

domNodeStyle.setProperty(key, styles[key])

then custom variables would work.

CSS custom properites are designed to be used in JavaScript (see https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables#Values_in_JavaScript) and I think it would be really useful if elm allowed custom properties to be set.

Many thanks for the great libary :)

harrysarson referenced this issue in harrysarson/virtual-dom May 17, 2018
When using custom css properties the syntax `style.property = 'value'`
does not work for custom css properties. Using `style.setProperty()`
instead allows custom css properties to be used.

Fixes elm-lang/html/issues/129
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants