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
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 44.516 42.603"><path opacity=".98" d="M6.36 0L.296 5.7l15.953 15.548L0 36.515l5.955 5.805 16.248-15.268 15.953 15.551 6.064-5.7-15.952-15.548 16.248-15.27L38.561.283 22.313 15.548 6.36 0z" fill-rule="evenodd" fill="#BBBBB8"/></svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment