Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


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


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.


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.


                <div id="app">
 <div class="container">
    {{ debugMessage }}
    <button-with-confirm ref="btn" @once="onClickedOnce" @confirmed="onConfirmed" @timedout="onTimedOut"></button-with-confirm>
  <div class="author">
    <a rel="no-opener" target="_blank" href="">Author:</a>


                body {
  margin: 20px;
  .container {
    width: 250px;
    display: grid;
    grid-template-rows: 50px 50px auto;
    .btn {
      cursor: pointer;
      padding: 0;
      border: none;
      border-radius: 4px;
      outline: none;
      background-color: #42b883;
      padding: 5px;

      &.confirm {
        background-color: #F90;
        color: #fff;
        .countdown-bar {
          opacity: 0.7;
          transition-property: width;
          transition-timing-function: linear;
          width: 0;
      .btn-label {
        color: #FFF;
        text-transform: uppercase;
        font-weight: bold;
      .countdown-bar {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 10px;
        opacity: 0;
        background-color: white;
        transition: none;
  .author {
    position: fixed;
    bottom: 0;
    font-style: italic;



Vue.component('button-with-confirm', {
  template: `
    <button type="button" :class="computedCss" @click="onClick">
      <div class="countdown-bar" :style="countdownBarStyle"></div>
      <div class="ripple-container">
      <span class="btn-label">{{ computedLabel }}</span>
  props: {
    defaultLabel: {
      type: 'string',
      default: 'Confirm Button'
    confirmLabel: {
      type: 'string',
      default: 'Are you sure?'
    defaultCss: {
      type: 'string',
      default: 'btn'
    timeoutSecs: {
      type: 'number',
      default: 5
  data() {
    return {
      defaultLabel: '',
      clickedOnce: false, // flag we'll use to track if button has been clicked already once
      countdown: 0 // optional for displaying a countdown progress
  computed: {
      return this.clickedOnce ? `${ this.confirmLabel } ${ this.countdown }` : this.defaultLabel;
      return this.clickedOnce ? `${ this.defaultCss } confirm` : this.defaultCss;
    countdownBarStyle() {
      let transitionDuration = this.timeoutSecs;
      return `transition-duration: ${ transitionDuration }s`;
  created() {
    this.timeoutId = undefined;
    this.countdown = this.timeoutSecs;
    this.countdownIntervalId = undefined;
  methods: {
    onClick() {
      if (this.clickedOnce) {
			  // If clickedOnce is true, the user has already clicked once, so this is the 2nd click within the time specified by the timeouteSecs property
        // clear the timeoutId/countdownIntervalId
        // Here we emit 'confirmed'
			} else {
				// If clickedOnce is false, the user has clicked on the button for the first time
        // Here we set the clickedOnce flag to true and emit the 'once' event (usually you would not care about knowing it has been clicked the first time, but if you do you can respond to the @once event where you will consume this component)
				this.clickedOnce = true;
				this.countdown = this.timeoutSecs;
				this.$emit('once', this);
        // then we invoke setTimeout with the milliseconds parameter calculated from the timeoutSecs property value:
        const timeoutMs = (this.timeoutSecs * 1000); // convert secs to ms
			  const self = this;
			  this.timeoutId = setTimeout(function() {
            // after timeoutMs has passed, we clear timeoutId and reset clickedOnce to false
				    self.$emit('timedout', this);
					}, timeoutMs);
        // this is just additional fancy stuff to show the countdown progress if you want:
				this.countdownIntervalId = setInterval(() => {
						if (this.countdown <= 0) {
							// reset the countdown interval and value
					}, 1000);
    reset() {
			this.clickedOnce = false;

/* Vue app */
new Vue({
  el: '#app', 
  data: {
    debugMessage: 'Button with confirm'
  methods: {
    onClickedOnce() {
      this.debugMessage = 'Clicked once';
    onTimedOut() {
      this.debugMessage = 'Timed out';
    onConfirmed() {
      this.debugMessage = 'Clicked again within timeout';
      this.$refs.btn.reset(); // this is just so we can reset the btn state here in this demo