domino icon indicating copy to clipboard operation
domino copied to clipboard

support: css custom properties

Open manzonif opened this issue 5 years ago • 4 comments
trafficstars

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']);

manzonif avatar May 21 '20 14:05 manzonif

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)

intellix avatar Jun 09 '20 12:06 intellix

@intellix, try this:

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

manzonif avatar Jun 11 '20 07:06 manzonif

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

cscott avatar Jul 16 '20 16:07 cscott

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

Burgov avatar Feb 02 '21 09:02 Burgov