Skip to content
Snippets Groups Projects
Button.vue 2.83 KiB
Newer Older
<script setup lang="ts">
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
import { computed } from 'vue';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
  label?: string;
  iconPos?: 'left' | 'top' | 'right' | 'bottom';
  textStyle?: 'bold' | 'italic';
  border?: 'white' | 'black';
  theme?:
    | 'white'
    | 'slate'
    | 'blue'
    | 'sky'
    | 'teal'
    | 'lime'
    | 'green'
    | 'yellow'
    | 'orange'
    | 'pink'
    | 'fuchsia'
    | 'purple'
    | 'indigo'
    | 'rose'
    | 'red'
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
    | 'black';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
const props = defineProps<Props>();
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
  if (!props?.theme) return '#0ea5e9';
  switch (props?.theme) {
    case 'white':
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#ffffff';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#64748b';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#3b82f6';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#0ea5e9';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#14b8a6';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#84cc16';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#22c55e';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#eab308';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#f97316';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#ec4899';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#d946ef';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#a855f7';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#6366f1';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#f43f5e';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#ef4444';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
      return '#000000';
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
  return '#ffffff';
});
const textColor = computed(() => {
Дмитрий Малюгин's avatar
Дмитрий Малюгин committed
  if (props.theme === 'white') return '#000000';
  return '#ffffff';
});
</script>

<template>
  <button
    :class="[
      'button',
      {
        'flex-column': iconPos === 'top' || iconPos === 'bottom',
        'border-black': theme === 'white' || border === 'black',
        'border-white': border === 'white'
      }
    ]"
  >
    <span :style="`background-color: ${themeColor}`" class="background"></span>
    <span
      :class="[
        'icon',
        {
          'order-2': iconPos === 'right' || iconPos === 'bottom'
        }
      ]"
    >
      <slot name="icon" />
    </span>
    <span
      :style="`color: ${textColor}`"
      :class="[
        'text',
        {
          bold: textStyle === 'bold',
          italic: textStyle === 'italic'
        }
      ]"
      >{{ label ?? 'Button' }}</span
    >
  </button>
</template>

<style scoped>
.button {
  position: relative;
  border-radius: 5px;
  display: flex;
  align-items: center;
  user-select: none;
}
.button:hover .background {
  filter: brightness(90%);
}
.background {
  width: 100%;
  height: 100%;
  position: absolute;
  z-index: -1;
  top: 0;
  left: 0;
  border-radius: 5px;
  transition: filter 0.2s ease-in-out;
}
.icon {
  display: flex;
  align-items: center;
  justify-content: center;
}
.text {
  padding: 0.75rem 0.5rem;
}
.flex-column {
  flex-direction: column;
}
.border-black {
  border: 1px solid black;
}
.border-white {
  border: 1px solid white;
}
.order-2 {
  order: 2;
}
.bold {
  font-weight: bold;
}
.italic {
  font-style: italic;
}
</style>