How to use @tanem/svg-injector - 4 common examples

To help you get started, we’ve selected a few @tanem/svg-injector examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tanem / react-svg / src / ReactSVG.tsx View on Github external
// TODO: It'd be better to cleanly unsubscribe from SVGInjector
        // callbacks instead of tracking a property like this.
        if (this._isMounted) {
          this.setState(
            () => ({
              hasError: !!error,
              isLoading: false
            }),
            () => {
              afterInjection(error, svg)
            }
          )
        }
      }

      SVGInjector(this.svgWrapper.firstChild as WrapperType, {
        afterEach,
        beforeEach: beforeInjection,
        evalScripts,
        renumerateIRIElements
      })
    }
  }
github tanem / svg-injector / UNSAFE_examples / api-usage / index.js View on Github external
import { SVGInjector } from '@tanem/svg-injector'

SVGInjector(document.getElementsByClassName('inject-me'), {
  afterAll(elementsLoaded) {
    console.log(`injected ${elementsLoaded} elements`)
  },
  afterEach(err, svg) {
    if (err) {
      throw err
    }
    console.log(`injected ${svg.outerHTML}`)
  },
  beforeEach(svg) {
    svg.setAttribute('stroke', 'red')
  },
  evalScripts: 'once',
  renumerateIRIElements: 'false'
})
github tanem / svg-injector / examples / api-usage / index.ts View on Github external
import { SVGInjector } from '@tanem/svg-injector'

document.body.insertAdjacentHTML(
  'beforeend',
  `
  <div data-src="api-usage/icon-one.svg" class="api-usage"></div>
  <div data-src="api-usage/icon-two.svg" class="api-usage"></div>
  `
)

SVGInjector(document.getElementsByClassName('api-usage'), {
  afterAll(elementsLoaded) {
    console.log(`injected ${elementsLoaded} elements`)
  },
  afterEach(err, svg) {
    if (err) {
      throw err
    }
    console.log(`injected ${svg.outerHTML}`)
  },
  beforeEach(svg) {
    svg.setAttribute('stroke', 'red')
  },
  evalScripts: 'once',
  renumerateIRIElements: 'false'
})
github tanem / svg-injector / examples / basic-usage / index.ts View on Github external
import { SVGInjector } from '@tanem/svg-injector'

SVGInjector(document.getElementById('inject-me'))

@tanem/svg-injector

Fast, caching, dynamic inline SVG DOM injection library.

MIT
Latest version published 6 months ago

Package Health Score

77 / 100
Full package analysis

Popular @tanem/svg-injector functions