Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="widget"></div>

<!-- templates section -->

<!-- step 1 select amount -->
<template id="stage-1-template">
  <div class="stage-1">
    <i><svg class="lnr lnr-gift hvr-buzz"><use xlink:href="#lnr-gift"></use></svg></i>
    <p>If you like this content, please consider supporting the team with a donation.</p>
    <button v-show="!showSelection" v-on:click="donate()" class="hvr-grow-shadow">Donate {{amount}} Eth</button>
      <select @change="triggerAmountChange()" v-model="amount" v-show="showSelection">
        <option>0.01</option>
        <option>0.05</option>
        <option>0.1</option>
        <option>0.15</option>
        <option>0.25</option>
      </select>
    <a href="#" v-on:click="selectAmount()">Select other amount</a>
  </div>
</template>

<!-- step 2, draw QR code -->
<template id="stage-2-template">
   <div class="stage-2">
     <i v-on:click="goBack()"><svg class="lnr lnr-cross"><use xlink:href="#lnr-cross"></use></svg></i>
     <p class="explanation"><strong>Thank you for your ETH {{amount}} donation!</strong><br>Here's the code that you can scan with you wallet app and a link below, that you can copy to your etherium client</p>
      <div id="qr-code-container"></div>
      <textarea @click="select">{{ethLink}}</textarea>
     <transition name="slide-fade">
     <p class="notification" v-if="showNotification">Link copied!</p>
        </transition>
  </div>
</template>
<!--  main app -->
<template id="eth-widget-template">
  <div class="eth-donation-widget">
    <transition name="slide-fade">
    <stage-two v-if="checkStage(2)" :amount="amount" v-on:changestage="changeStage"></stage-two>
       </transition>
 
    <stage-one v-if="checkStage(1)" :amount="amount" v-on:changestage="changeStage"/>
    
  </div>
</template>
              
            
!

CSS

              
                body {
  font-family: Roboto, Arial, sans-serif;
  margin: 30px;
}
.notification {
  color: green;
  margin-top: 5px;
}
.lnr {
  display: inline-block;
  fill: currentColor;
  width: 1em;
  height: 1em;
  vertical-align: -0.05em;
}

.stage-1 {
  height: 300px;
  text-align: center;
  .lnr-gift {
    color: #fc0;
    font-size: 120px;
  }
  p {
    color: #3F51B5;
    width: 90%;
    margin: 40px auto 20px auto;
  }
  a {
    margin-top: 10px;
    font-size: 12px;
    color: #7a7a7a;
    display: block;
  }
  i {
    margin: 20px 0px;
    display: block;
  }
  button {
    background: green;
    border-radius: 20px;
    color: #fff;
    border: none;
    padding: 10px 40px;
    font-size: 16px;
    cursor:pointer;
  }
  select {
    padding: 10px 70px;
    font-size: 16px;
    border-radius: 20px;
  }
}
.stage-2 {
  height: 300px;  text-align: center;
  .explanation {
    font-size: 12px;
    margin: 0px auto;
    width: 85%;
  }
  textarea {
     border-radius: 3px;
    padding: 5px;
    width:80%;
    font-size:12px;
  }
  i {
     float: right;
    cursor: pointer;
    padding: 1px 2px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 20px;
  }
}
.eth-donation-widget {
  max-width: 300px;
  border: 1px solid #ccc;
  background-color: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .15);
  margin: 0 auto;
  padding: 20px 10px;
}

/* Enter and leave animations can use different */
/* durations and timing functions.              */
.slide-fade-enter-active {
  transition: all .5s ease;
}
.slide-fade-leave-active {
  /*transition: all .1s cubic-bezier(1.0, 0.5, 0.8, 1.0);*/
}
.slide-fade-enter, .slide-fade-leave-to
/* .slide-fade-leave-active below version 2.1.8 */ {
  transform: translateX(10px);
  opacity: 0;
}

              
            
!

JS

              
                /**
the library used: https://github.com/jibrelnetwork/ethereum-qr-code

*/
const donationAdress = "0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8";

const getQrCode = value => {
  const qr = new EtheriumQRplugin.etheriumQRplugin();
  const codeDetails = {
    to: donationAdress,
    value,
    size: 180,
    gas: 21000,
    selector: "#qr-code-container",
    options: {
      margin: 1
    }
  };
  return qr.toCanvas(codeDetails);
};

const copyToClipboard = (eventTarget) => {
  eventTarget.select()
  document.execCommand('copy')
}

const StageOne = Vue.component("StageOne", {
  name: "StageOne",
  template: "#stage-1-template",
  props: {
    amount: Number
  },
  data: function() {
    return {
      showSelection: false
    };
  },
  methods: {
    donate: function() {
      this.$emit("changestage", [2, this.amount]);
    },
    selectAmount: function() {
      this.showSelection = true;
    },
    triggerAmountChange: function() {
      this.showSelection = false;
    }
  }
});

const StageTwo = Vue.component("StageTwo", {
  name: "StageTwo",
  template: "#stage-2-template",
  props: {
    amount: Number
  },
  data: function() {
    return {
      ethLink: "",
      showNotification: false
    };
  },
  methods: {
    goBack: function() {
      this.$emit("changestage", [1, this.amount]);
    },
    select : function(event){
     copyToClipboard(event.target);
     this.showNotification = true;
  }
  },
  mounted: function() {
    getQrCode(this.amount).then(result => {
      this.ethLink = result.value;
    });
  },
   updated: function() {
    document.getElementById('qr-code-container').innerHTML = '';
    getQrCode(this.amount).then(result => {
      this.ethLink = result.value;
    });
  }
});

new Vue({
  el: "#widget",
  template: "#eth-widget-template",
  components: { StageTwo, StageOne },
  data: function() {
    return {
      stage: 1,
      amount: 0.1
    };
  },
  methods: {
    checkStage: function(stage) {
      return stage === this.stage;
    },
    changeStage: function(data) {
      this.stage = data[0];
      this.amount = data[1];
    },
    changeAmount: function(amount) {
       this.amount = amount;
    },
  }
});


              
            
!
999px

Console