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 variables in styles property #163

Closed
Dyljyn opened this issue Jan 8, 2021 · 5 comments
Closed

Support for CSS variables in styles property #163

Dyljyn opened this issue Jan 8, 2021 · 5 comments

Comments

@Dyljyn
Copy link

Dyljyn commented Jan 8, 2021

Expected behavior

When providing a CSS variable through the styles property. It is added to the style attribute of the tag.

h('div', {
  styles: {
    '--background-color': 'blue',
  }
}, [])

Should result in:

<div style="--background-color:blue;"></div>

Current behavior

CSS variables get ignored and are not rendered.

Demo

https://stackblitz.com/edit/maquette-starter-j1rjrw?file=main.ts

@johan-gorter
Copy link
Contributor

Very interesting...
It seems that this notation does work however (and is more typescript-friendly)

h('div', {
  styles: {
    backgroundColor: 'var(--background-color, gray)'
  }
}, [])

DEMO

https://stackblitz.com/edit/maquette-starter-b5kdg3?file=main.ts

@johan-gorter
Copy link
Contributor

A long time ago, we made a style-applyer hook to allow adding vendor prefixes. It turns out you can use to apply styles in a way that is compatible with CSS variables:

const projector = createProjector({
  styleApplyer: (domNode, stylename, value) => {
    domNode.style.setProperty(stylename, value);
  }
});

We should add this to maquette though, but this means you do not have to wait for a new release

Demo

https://stackblitz.com/edit/maquette-starter-b5kdg3?file=main.ts

johan-gorter added a commit that referenced this issue Jan 8, 2021
@johan-gorter
Copy link
Contributor

@Dyljyn can you confirm that the patch I just committed fixes your issue and CSS variables in general? I will make a new release if it does.

@Dyljyn
Copy link
Author

Dyljyn commented Jan 8, 2021

Excellent! I can confirm that your latest commit resolves it 🎉

@johan-gorter
Copy link
Contributor

Release 3.4.0 contains the fix.

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

No branches or pull requests

2 participants