Skip to content

Instantly share code, notes, and snippets.

@daehli
Last active December 15, 2017 19:59
Show Gist options
  • Save daehli/c3a56ca37491642f8d833af673bccf35 to your computer and use it in GitHub Desktop.
Save daehli/c3a56ca37491642f8d833af673bccf35 to your computer and use it in GitHub Desktop.
Testing RawGit with svg Icon

Testing with a Icon

I was testing svg background in our Application and I was woundering if it was possible to USE RawGit to render our Background. In our case it's possible to render a SVG background with RawGit.

Exemple

// Api to catch out Config File 
fetchConfig() {
  return this.props.bp.axios.get('/api/config').then(({ data }) => {
    let rawGitUrl = data.backgroundImage
    let datas = data
    this.props.bp.axios.get(rawGitUrl).then(({ data }) => {
      let svg = data
      datas.backgroundImage = svg
      this.setState({
        config: datas
      })
    })
  })
}

And the second part is our with render SVG

// Convert our Image in base64
const backgroundImageEncodeBase64 = this.props.config.backgroundImage
  ? btoa(this.props.config.backgroundImage)
  : null
  /* Code */
       <div
        className={classNames}
        style={{
          backgroundColor: this.props.config.backgroundColor,
          color: this.props.config.textColorOnBackgound,
          background: 'fixed center;',
          backgroundImage: `url('data:image/svg+xml;base64,${backgroundImageEncodeBase64}')`
        }}
      >
     /* Code */
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment