biotope / biotope-build

Biotope Build Framework
https://build.biotope.sh
MIT License
24 stars 10 forks source link

Add possibility to import SVGs #149

Closed SheepFromHeaven closed 5 years ago

SheepFromHeaven commented 5 years ago

In the new template strings I would like to have the possibility to import SVG icons so they get rendered in the html. Please add this possibility

jurekbarth commented 5 years ago

You can have a look at here: https://github.com/biotope/biotope-build/tree/webpack-svg-loader and here for implementation details: https://github.com/biotope/experimental-biotope-components/tree/wip-inline-svg

Still i'm having problems using bio element to not escape my SVG stuff. Maybe we could switch to a "normal" Web Component here without any sugar to make it easier to deal with SVG's. What do you think?

timomayer commented 5 years ago

what do you mean by normal web component?

jurekbarth commented 5 years ago

We are using BioElement on top of hyperHTML Element which extends HTMLElement. We could use a normal webcomponent like so

import mySvg from './mySvg'

class Icon extends HTMLElement {
  constructor() {
    super();
    this.innerHTML = mySVG;
  }
}

This way my svg is not sanitized. Tradeoffs are ok for me, because the icon won't have child nodes.

timomayer commented 5 years ago

thanks for the explanation. i agree it is ok since svg has no child nodes. Whats the reason behind? Is it an hyperHTML bug?

jurekbarth commented 5 years ago

Not a bug a feature. It sanitizes input by default. That's a good thing 99% of the time, but there's no way around it, at least none i'm aware of. Would be handy to have something like react's dangerouslySetInnerHTML method.

timomayer commented 5 years ago

can you open a ticket in hyperHTML repo with this exact usecase. for the time there is no other solution we should add the workaround for svgs to our documentation.

jurekbarth commented 5 years ago

@timomayer will do so 👍

SheepFromHeaven commented 5 years ago

@jurekbarth are you still working on that? 🙏 also have a look at #157

jurekbarth commented 5 years ago

@SheepFromHeaven yes :) it's basically done i would like to publish that stuff we merge https://github.com/biotope/biotope-build/pull/159

jurekbarth commented 5 years ago

178