MVCoconut / coconut.vdom

Coconut rendering through virtual-dom.
The Unlicense
19 stars 8 forks source link

Basic svg attributes working, "className" correction #33

Closed cambiata closed 4 years ago

cambiata commented 4 years ago

Get basic svg attributes working (wievBox, width, height etc.). Correct that "class" attribute wrongly is named "className" in the generated output.

kevinresol commented 4 years ago

Thanks for the update! But I think it is better to preserve the white space (use space instead of tab) and not to alter if/else into ternary.

kevinresol commented 4 years ago

Thanks but there are still some tabs ^^"

cambiata commented 4 years ago

Sorry, I edit directly in Github, and it keeps popping back to Tabs every time..! :-|

kevinresol commented 4 years ago

Yeah and they still exist, lol

cambiata commented 4 years ago

Closing this - Found out that there's too much missing in tink_domspec https://github.com/haxetink/tink_domspec/blob/94fd4d03bf37f0ef822f1a44a18320c6529f8229/src/tink/domspec/Attributes.hx#L362.

AdrianV commented 2 years ago

@cambiata I have a similar problem, but your solution does not work for me. I tried with a different solution in setSvgProp with removeAttribute and setAttribute instead of removeAttributeNS and setAttributeNS . Can you remember why you chose the ...AttributeNS versions?

this works for me:

  static inline function setSvgProp(element:Element, name:String, newVal:Dynamic, ?oldVal:Dynamic)
    switch name {
      case 'className':
        if (newVal == null)
          element.removeAttribute('class');
        else
          element.setAttribute('class', newVal);
      case 'viewBox':
        if (newVal == null)
          element.removeAttributeNS(SVG, name);
        else
          element.setAttributeNS(SVG, name, newVal);
      case 'xmlns':
      case 'attributes':
        Elt.setAttributes(element, newVal, oldVal);
      case 'style':
        @:privateAccess Elt.updateStyle(element.style, newVal, oldVal);
      default:
        if (newVal == null)
          element.removeAttribute(name);
        else
          element.setAttribute(name, newVal);
    }