Skip to content
Snippets Groups Projects
IconButton.vue 1.24 KiB
Newer Older
Gilgard's avatar
Gilgard committed
<template>
  <!-- Button -->
Gilgard's avatar
Gilgard committed
  <button
    class="flex items-center px-2 py-2 font-medium tracking-wide capitalize text-white transition-colors duration-200 transform rounded-md focus:outline-none focus:ring focus:ring-opacity-80"
    :class="color"
Gilgard's avatar
Gilgard committed
  >
    <div class="w-5 h-5 mx-1">
      <!-- Slot for icon (Default BanIcon) -->
      <slot><BanIcon /></slot>
Gilgard's avatar
Gilgard committed
    </div>
    <span class="mx-1">{{ text }}</span>
Gilgard's avatar
Gilgard committed
  </button>
</template>

<script>
import { BanIcon } from "@heroicons/vue/outline";

/**
 * IconButton component that can be customized with text, color and a slot for passing an icon.
 * Colors:
 * blue (default),
 * red,
 * green
 */
Gilgard's avatar
Gilgard committed
export default {
  name: "IconButton",
  props: {
    text: String,
Gilgard's avatar
Gilgard committed
  },
  components: {
    BanIcon,
  },
    /**
     * Formats the tailwind css tags based on the color passed from parent
     */
    color() {
      if (this.buttonColor === "red") {
        return "bg-error-medium hover:bg-error-dark focus:ring-error-light";
      }
      if (this.buttonColor === "green") {
        return "bg-success-medium hover:bg-success-dark focus:ring-success-light";
      }
      return "bg-primary-medium hover:bg-primary-dark focus:ring-primary-light";
    },
  },
Gilgard's avatar
Gilgard committed
};
</script>