ollie-stevenson of Six
3/21/2019 - 10:33 AM

SemanticBtn (Nuxt)

Always renders the correct tag based on the action needed. Now passes ES Lint.

<template>
  <nuxt-link
    v-if="type === 'nuxt'"
    :to="link"
    :class="['c-Btn', modifier]"
  >
    {{ label }}
  </nuxt-link>
  <a
    v-else-if="type === 'external'"
    :href="link"
    target="_blank"
    :class="['c-Btn', modifier]"
  >
    {{ label }}
  </a>
  <button
    v-else-if="type === 'button'"
    :class="['c-Btn', modifier]"
  >
    {{ label }}
  </button>
</template>

<script>
export default {
  name: 'Button',
  props: {
    label: {
      type: String,
      required: true
    },
    modifier: {
      type: String,
      default: null
    },
    link: {
      type: String,
      required: false,
      default: null
    },
    type: {
      type: String, // Expects one of ['nuxt', 'external', 'button']
      required: true,
      default: 'nuxt'
    }
  }
}
</script>

<style lang="scss" scoped>
  .Button {
  }
</style>