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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <template id="main">
  <v-ons-page>
    <p style="text-align: center">
      <custom-button>slot</custom-button>
      <custom-button text="props"></custom-button>
      <custom-button text="props">slot</custom-button>
      <custom-button icon="cog"></custom-button>
      <custom-button icon="cog">slot</custom-button>
      <custom-button icon="cog" text="text"></custom-button>
      <custom-button icon="cog" text="text">slot</custom-button>
    </p>

    <p style="text-align: center">
      <custom-button disabled>hello</custom-button>
      <custom-button :disabled="false">hello</custom-button>
      <custom-button :disabled="true">hello</custom-button>
    </p>

    <p style="text-align: center">
      <custom-button
        icon="smile-o"
        @click="clickHandler"
        button-class="bigButton"
      >
      </custom-button>
      <custom-button
        icon="smile-o"
        @click="clickHandler"
        button-class="smallButton"
      >
      </custom-button>
      <custom-button
        icon="smile-o"
        @click="clickHandler"
        button-class="redButton"
      >
      </custom-button>
      <custom-button
        icon="smile-o"
        @click="clickHandler"
        button-class="greenButton"
      >
      </custom-button>
    </p>
    
    <p style="text-align: center">
      <custom-button
        :text="['グー', 'チョキ', 'パー']"
        @click="clickHandler"
        button-class="sample01"
      >
      </custom-button>
      <custom-button
        :icon="['hand-rock-o', 'hand-peace-o', 'hand-paper-o']"
        @click="clickHandler"
        button-class="sample02"
      >
      </custom-button>
      <custom-button
        :text="['グー', 'チョキ', 'パー']"
        icon="smile-o"
        @click="clickHandler"
        button-class="sample03 align-left"
      >
      </custom-button>  
      <custom-button
        text="じゃんけん"
        :icon="['hand-rock-o', 'hand-peace-o', 'hand-paper-o']"
        @click="clickHandler"
        button-class="sample04 align-right"
      >
      </custom-button>
      <custom-button
        :text="['グー', 'チョキ', 'パー']"
        :icon="['hand-rock-o', 'hand-peace-o', 'hand-paper-o']"
        @click="clickHandler"
        button-class="sample03 align-left"
      >
      </custom-button>
    </p>
  </v-ons-page>
</template>

<div id="app"></div>
              
            
!

CSS

              
                .bigButton {
  padding: 0;
  width: 60px;
  height: 60px;
  line-height: 60px;
  font-size: 32px;
  color: yellow;
  padding-top: 2px;
}
.smallButton {
  padding: 0;
  width: 28px;
  height: 28px;
  min-height: 28px;
  line-height: 28px;
  font-size: 14px;
  color: yellow;
  padding-top: 1px;
}
.sample01 {
  width: 70px;
  padding: 0;
}
.sample02 {
  width: 46px;
}
.sample03 {
  width: 90px;
  padding: 0;
}
.sample04 {
  width: 120px;
  padding: 0;
}
.align-right {
  text-align: right;
  padding-right: 16px;
}
.align-left {
  text-align: left;
  padding-left: 16px;
}

.greenButton,
.greenButton:active {
  background-color: green;
}
.redButton,
.redButton:active {
  background-color: red;
}

p {
  text-align: center;
  line-height: 2.6em;
}
              
            
!

JS

              
                var CustomButton = {
  template: `
  <v-ons-button
    :class="buttonClass"
    :disabled="disabled"
    @click="clickHandler"
  >
    <i
      v-if="icon"
      class="fa"
      :class="iconClass"
    >
    </i>
    <slot>{{ buttonText }}</slot>
  </v-ons-button>
`,
  
  data () {
    return {
      index: 0,
    }
  },
  
  props: {
    text: {
      type: [String, Array],
      default: ''
    },
    icon: {
      type: [String, Array],
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    },
    buttonClass: {
      type: String,
      default: ''
    }
  },
  
  computed: {
    toggle () {
      console.log('toggle')
      var num = 0
      var icon = (this.icon instanceof Array) ? this.icon.length : 0
      var text = (this.text instanceof Array) ? this.text.length : 0
      if (icon) {
        if (text) {
          num = icon < text ? icon : text
        } else {
          num = icon
        }
      } else if (text) {
        num = text
      }
      console.log(icon, text, num)
      return { icon, text, num }
    },
    iconClass () {    // memo: iconが空の配列の場合、暗黙的にjoin()により""になる
      console.log('iconClass')
      return this.toggle.icon ? 'fa-' + this.icon[this.index] : 'fa-' + this.icon
    },
    buttonText () {
      console.log('buttonText')
      return this.toggle.text ? this.text[this.index] : this.text
    }
  },

  methods: {
    // ・indexを更新することでiconClass,buttonText算出プロパティにより
    // 自動的にアイコンとテキストが更新される
    // ・配列でない場合はindexは使われない(更新されない)
    clickHandler (event) {
      var index = this.index;
      if (this.toggle.num) {
        this.index = (index >= this.toggle.num - 1) ? 0 : index + 1
      }
      var arg = {
        event,
        oldIdx: index,
        newIdx: this.index
      }
      this.$emit('click', arg)
    }
  }
}

new Vue({
  el: '#app',
  template: '#main',
  components: {
    CustomButton
  },
  created () {
    this.$ons.platform.select('android')
  },
  methods: {
    clickHandler (param) {
      console.log(param)
    }
  }
})
              
            
!
999px

Console