|
1 | 1 | <script lang="ts"> |
2 | 2 | import { createEventDispatcher } from 'svelte' |
3 | | - import { Loading } from '.' |
| 3 | + import { Icon, Loading } from '.' |
4 | 4 | import { slide } from 'svelte/transition' |
5 | 5 | import { quadOut } from 'svelte/easing' |
6 | | - const dispatch = createEventDispatcher() |
| 6 | + import { router } from '@inertiajs/svelte' |
| 7 | +
|
| 8 | + const dispatch = createEventDispatcher<{ click: void }>() |
7 | 9 |
|
8 | 10 | type ButtonSize = 'normal' | 'sm' | 'lg' |
9 | | - type ButtonColor = 'primary' | 'secondary' | 'tertiary' | 'ghost' |
| 11 | + type ButtonColor = 'primary' | 'secondary' | 'tertiary' | 'danger' | 'ghost' | 'light' |
10 | 12 |
|
11 | 13 | export let size: ButtonSize = 'normal' |
12 | 14 | export let color: ButtonColor = 'primary' |
13 | 15 | export let block: string | boolean | undefined = undefined |
14 | 16 | export let loading: boolean = false |
| 17 | + export let icon: string | undefined = undefined |
| 18 | + export let text: string | undefined = 'Click me' |
| 19 | +
|
| 20 | + export let route: string | undefined = undefined |
| 21 | +
|
| 22 | + function handleClick() { |
| 23 | + if (route !== undefined) { |
| 24 | + router.visit(route) |
| 25 | + return |
| 26 | + } |
| 27 | + dispatch('click') |
| 28 | + } |
15 | 29 | </script> |
16 | 30 |
|
17 | 31 | <button |
18 | | - class={`py-2 lg:py-3 px-4 lg:px-5 mx-1 flex gap-4 justify-center items-center text-sm lg:text-md ${color} btn-${size} ${ |
| 32 | + class={`py-2 lg:py-3 px-4 lg:px-5 mx-1 flex gap-2 justify-center items-center text-sm lg:text-md ${color} btn-${size} ${ |
19 | 33 | block !== undefined ? 'w-full' : '' |
20 | 34 | }`} |
21 | 35 | {...$$restProps} |
22 | | - on:click={() => dispatch('click')} |
| 36 | + on:click={handleClick} |
23 | 37 | > |
24 | | - <slot /> |
| 38 | + {#if icon} |
| 39 | + <Icon name={icon} size="lg" /> |
| 40 | + {/if} |
| 41 | + |
| 42 | + <slot> |
| 43 | + {text} |
| 44 | + </slot> |
25 | 45 |
|
26 | 46 | {#if loading} |
27 | 47 | <div transition:slide={{ axis: 'x', duration: 300, easing: quadOut }}> |
|
54 | 74 | button.tertiary { |
55 | 75 | @apply bg-gradient-to-r from-tertiary-500 via-tertiary-600 to-tertiary-700 hover:opacity-70; |
56 | 76 | } |
| 77 | + button.danger { |
| 78 | + @apply border border-red-500 dark:border-red-500 shadow-sm font-medium rounded-md text-white dark:text-red-100 bg-red-500 dark:bg-red-800 hover:bg-red-900 dark:hover:bg-red-900 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500; |
| 79 | + } |
57 | 80 | button.ghost { |
58 | | - @apply border border-primary-700 dark:border-primary-300 text-primary-800 dark:text-primary-200; |
| 81 | + @apply border border-primary-700 dark:border-primary-300 text-primary-800 dark:text-primary-200 hover:bg-primary-100 dark:hover:bg-primary-700; |
| 82 | + } |
| 83 | + button.light { |
| 84 | + @apply border border-gray-300 dark:border-gray-600 shadow-sm font-medium rounded-md text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-900 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500; |
59 | 85 | } |
60 | 86 | button.btn-sm { |
61 | 87 | @apply py-1 lg:py-2 px-2 lg:px-3; |
62 | 88 | } |
| 89 | + button.btn-lg { |
| 90 | + @apply py-2.5 lg:py-3 px-3 lg:px-5; |
| 91 | + } |
63 | 92 | </style> |
0 commit comments