|
1 | 1 | <script lang="ts">
|
2 | 2 | import type { FlyParams } from 'svelte/transition'
|
3 |
| - import { fly } from 'svelte/transition' |
4 |
| - import { goto } from '$app/navigation' |
5 |
| -
|
6 | 3 | import type { NotificationType } from '$lib/types'
|
7 |
| - import { Notify } from '$lib/stores/notification' |
| 4 | + import { goto } from '$app/navigation' |
| 5 | + import { fly } from 'svelte/transition' |
8 | 6 | import { InfoIcon, CheckCircleIcon, AlertTriangleIcon, XCircleIcon, XIcon } from 'svelte-feather-icons'
|
| 7 | + import notification from '$lib/stores/notification' |
9 | 8 |
|
10 | 9 | export let item: NotificationType = undefined
|
11 |
| - export let closable: boolean = false |
12 | 10 |
|
13 | 11 | export let flyInParams: FlyParams = { x: -50 }
|
14 | 12 | export let flyOutParams: FlyParams = { x: -50 }
|
15 | 13 |
|
16 |
| -
|
| 14 | + $: item.type = item.type === undefined ? 'info' : item.type |
17 | 15 | </script>
|
18 | 16 |
|
19 | 17 | <div
|
|
25 | 23 | aria-live="polite"
|
26 | 24 | {...$$restProps}
|
27 | 25 | on:click
|
28 |
| - on:click={() => { |
29 |
| - if (item?.href) { |
30 |
| - goto(item.href) |
31 |
| - } |
32 |
| - }} |
| 26 | + |
33 | 27 | on:mouseenter
|
34 | 28 | on:mouseleave
|
35 | 29 | >
|
36 |
| - <header class="heading"> |
37 |
| - <div class="icon"> |
38 |
| - {#if item?.type} |
39 |
| - {#if item?.type === 'info'}<InfoIcon size="24" />{/if} |
40 |
| - {#if item?.type === 'success'}<CheckCircleIcon size="24" />{/if} |
41 |
| - {#if item?.type === 'warning'}<AlertTriangleIcon size="24" />{/if} |
42 |
| - {#if item?.type === 'error'}<XCircleIcon size="24" />{/if} |
43 |
| - {/if} |
44 |
| - </div> |
45 |
| - <h4 class="title">{item?.title}</h4> |
46 |
| - </header> |
47 |
| - {#if item?.description} |
48 |
| - <div class="description"> |
49 |
| - {item?.description} |
50 |
| - </div> |
51 |
| - {/if} |
52 |
| - {#if closable && !item?.href} |
| 30 | + <div |
| 31 | + class="inner" |
| 32 | + on:click={() => { |
| 33 | + if (item?.href) { |
| 34 | + item.href.startsWith('http') ? window.open(item.href, '_blank') : goto(item.href) |
| 35 | + notification.close(item) |
| 36 | + } |
| 37 | + }} |
| 38 | + > |
| 39 | + <header class="heading"> |
| 40 | + <div class="icon"> |
| 41 | + {#if item?.type} |
| 42 | + {#if item?.type === 'info'}<InfoIcon size="24" />{/if} |
| 43 | + {#if item?.type === 'success'}<CheckCircleIcon size="24" />{/if} |
| 44 | + {#if item?.type === 'warning'}<AlertTriangleIcon size="24" />{/if} |
| 45 | + {#if item?.type === 'error'}<XCircleIcon size="24" />{/if} |
| 46 | + {/if} |
| 47 | + </div> |
| 48 | + <h4 class="title">{item?.title}</h4> |
| 49 | + </header> |
| 50 | + {#if item?.description} |
| 51 | + <div class="description"> |
| 52 | + {item?.description} |
| 53 | + </div> |
| 54 | + {/if} |
| 55 | + </div> |
| 56 | + {#if item?.closable} |
53 | 57 | <button
|
54 | 58 | type="button"
|
55 | 59 | class="close"
|
56 | 60 | aria-label="close notification"
|
57 | 61 | on:click={() => {
|
58 |
| - Notify.close(item) |
| 62 | + notification.close(item) |
59 | 63 | }}
|
60 | 64 | >
|
61 | 65 | <XIcon size="16" />
|
|
0 commit comments