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: css custom properties #165

Open
manzonif opened this issue May 21, 2020 · 4 comments
Open

support: css custom properties #165

manzonif opened this issue May 21, 2020 · 4 comments

Comments

@manzonif
Copy link

manzonif commented May 21, 2020

There is a way to set css custom properties?

import { style } from '@angular/animations';
const domino = require('domino');

const win = domino.createWindow('<h1>Hello world</h1>', 'http://example.com');
const doc = win.document;

const h1 = doc.querySelector('h1');
h1.style.setProperty('--somekeyword', `10px`);
console.log(h1.style['--somekeyword']);
@intellix
Copy link

intellix commented Jun 9, 2020

Having issues trying to do this myself with Angular Universal. Basically doing this:

elementRef.nativeElement.style.setProperty(k, v);

With a CSS var like:

{
  "key": "--grid-gap",
  "value": "1rem"
}

And getting a bucket of errors:

TypeError: Cannot read property 'type' of undefined
    at TokenStream.LA (/Projects/site/node_modules/domino/lib/cssparser.js:810:30)
    at TokenStream.advance (/Projects/site/node_modules/domino/lib/cssparser.js:683:20)
    at Parser._readDeclarations (/Projects/site/node_modules/domino/lib/cssparser.js:3402:42)
    at Parser.parseStyleAttribute (/Projects/site/node_modules/domino/lib/cssparser.js:3581:22)
    at parseStyles (/Projects/site/node_modules/domino/lib/CSSStyleDeclaration.js:23:10)
    at CSSStyleDeclaration.value (/Projects/site/node_modules/domino/lib/CSSStyleDeclaration.js:142:22)
    at CssPropsDirective.ngOnChanges (/Projects/site/dist/apps/whitelabel/server/main.js:32563:23)

@manzonif
Copy link
Author

manzonif commented Jun 11, 2020

@intellix, try this:

constructor(
    el: ElementRef,
    private renderer: Renderer2,) {
  this.renderer.setStyle(el.nativeElement, '--grid-gap', `1rem`, RendererStyleFlags2.DashCase);```

@cscott
Copy link
Collaborator

cscott commented Jul 16, 2020

Domino uses the CSSLint css parser; see ccc98fe. Ideally that support would be added upstream and then brought into domino.

@Burgov
Copy link

Burgov commented Feb 2, 2021

i'm having issues with this too. I'm using [style.--color]="item.color", and it fails with the same error @intellix mentioned.

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

4 participants