|
| 1 | +<script> |
| 2 | +import { tweened } from 'svelte/motion' |
| 3 | +import { linear } from 'svelte/easing' |
| 4 | +import { toast } from './stores.js' |
| 5 | +
|
| 6 | +export let item |
| 7 | +
|
| 8 | +const progress = tweened(item.initial, { duration: item.duration, easing: linear }) |
| 9 | +
|
| 10 | +let prevProgress = item.initial |
| 11 | +
|
| 12 | +$: if (prevProgress !== item.progress) { |
| 13 | + if (item.progress === 1 || item.progress === 0) { |
| 14 | + progress.set(item.progress).then(() => toast.pop(item.id)) |
| 15 | + } else { |
| 16 | + progress.set(item.progress) |
| 17 | + } |
| 18 | + prevProgress = item.progress |
| 19 | +} |
| 20 | +
|
| 21 | +</script> |
| 22 | + |
| 23 | +<style> |
| 24 | +._toastItem { |
| 25 | + width: var(--toastWidth,16rem); |
| 26 | + height: var(--toastHeight,3.5rem); |
| 27 | + margin-bottom: var(--toastMarginBottom,0.5rem); |
| 28 | + background: var(--toastBackground,rgba(74,85,104,0.98)); |
| 29 | + color: var(--toastColor,#FFF); |
| 30 | + box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1),0 2px 4px -1px rgba(0,0,0,0.06); |
| 31 | + border-radius: 0.125rem; |
| 32 | + position: relative; |
| 33 | + display: flex; |
| 34 | + flex-direction: row; |
| 35 | + align-items: center; |
| 36 | + will-change: transform,opacity; |
| 37 | + -webkit-tap-highlight-color: transparent; |
| 38 | +} |
| 39 | +._toastMsg { |
| 40 | + font-size: var(--toastFontSize,1rem); |
| 41 | + flex: 1 1 0%; |
| 42 | + padding: 0 0.5rem; |
| 43 | +} |
| 44 | +._toastBtn { |
| 45 | + width: 2rem; |
| 46 | + height: 100%; |
| 47 | + font: 1rem sans-serif; |
| 48 | + display: flex; |
| 49 | + align-items: center; |
| 50 | + justify-content: center; |
| 51 | + cursor: pointer; |
| 52 | + outline: none; |
| 53 | + pointer-events: auto; |
| 54 | +} |
| 55 | +._toastBar { |
| 56 | + display: block; |
| 57 | + appearance: none; |
| 58 | + border: none; |
| 59 | + position: absolute; |
| 60 | + bottom: 0; |
| 61 | + width: 100%; |
| 62 | + height: 6px; |
| 63 | + background: transparent; |
| 64 | +} |
| 65 | +._toastBar::-webkit-progress-bar { |
| 66 | + background: transparent; |
| 67 | +} |
| 68 | +._toastBar::-webkit-progress-value { |
| 69 | + background: var(--toastProgressBackground,rgba(66,153,225,0.98)); |
| 70 | +} |
| 71 | +._toastBar::-moz-progress-bar { |
| 72 | + background: var(--toastProgressBackground,rgba(66,153,225,0.98)); |
| 73 | +} |
| 74 | +</style> |
| 75 | + |
| 76 | +<div class="_toastItem"> |
| 77 | + <div class="_toastMsg">{item.msg}</div> |
| 78 | + |
| 79 | + {#if item.dismissable} |
| 80 | + <div class="_toastBtn" role="button" tabindex="-1" on:click={() => toast.pop(item.id)}>✕</div> |
| 81 | + {/if} |
| 82 | + |
| 83 | + <progress class="_toastBar" value={$progress}></progress> |
| 84 | +</div> |
0 commit comments