File size: 2,204 Bytes
e71d24a
 
 
eb29a95
e71d24a
 
 
 
 
b1a4d81
e71d24a
 
 
 
 
 
 
b1a4d81
 
e71d24a
 
 
 
 
 
 
 
c16a39b
 
 
 
 
 
 
 
 
e71d24a
eb29a95
 
 
e71d24a
eb29a95
 
 
 
 
 
e71d24a
eb29a95
 
 
e71d24a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a084673
 
 
e71d24a
 
 
 
 
 
c16a39b
 
 
 
 
e71d24a
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<script lang="ts">
import { goto } from '$app/navigation';
	import Icon from "@iconify/svelte";
	import Loading from './Loading.svelte';

  export let theme: "light" | "dark" | "blue" | "pink"  = "light";
  export let size: "md" | "lg" = "md";
  export let href: string | undefined = undefined;
  export let icon: string | undefined = undefined;
  export let target: "_blank" | "_self" | undefined = undefined;
  export let iconPosition: "left" | "right" = "left";
  export let disabled: boolean = false;
  export let loading: boolean = false;
  export let onClick: () => void = () => {};

  const handleClick = async () => {
    if (href) {
      if (target) window.open(href, target);
      else goto(href);
      return
    }
    if (disabled || loading) return;
    onClick();
  };

</script>

<button
  class="button {theme} {size} relative whitespace-nowrap {disabled ? 'disabled' : ''}"
  class:!bg-neutral-400={loading}
  class:!border-neutral-400={loading}
  class:!grayscale={disabled}
  class:!cursor-not-allowed={disabled}
  class:!text-neutral-700={disabled}
  on:click={handleClick}
  >
  {#if icon && iconPosition === "left"}
    <p class:opacity-0={loading}>
      <Icon icon={icon} class="w-[20px] h-[20px]" />
    </p>
  {/if}
  {#if loading}
    <Loading />
  {/if}
  <p class:opacity-0={loading}>
    <slot />
  </p>
  {#if icon && iconPosition === "right"}
    <p class:opacity-0={loading}>
      <Icon icon={icon} class="w-[20px] h-[20px]" />
    </p>
  {/if}
</button>

<style lang="scss">
  .button {
    @apply rounded-full outline-none border font-medium flex items-center justify-center gap-1.5 transition-all duration-200 cursor-pointer;
    &.lg {
      @apply px-6 py-3 text-base;
    }
    &.md {
      @apply px-5 py-2 text-sm;
    }
    &.light {
      @apply bg-white text-neutral-900 border-white;
    }
    &.pink {
      @apply bg-pink-500 text-white border-pink-500;
    }
    &.blue {
      @apply bg-blue-500 text-white border-blue-500;
    }
    &.dark {
      @apply bg-neutral-900 border-neutral-800 text-neutral-300;
    }
    &:hover {
      @apply brightness-125
    }
    &.disabled {
      &:hover {
        @apply brightness-100
      }
    }
  }
</style>