| 1 | <script lang="ts"> |
| 2 | import { getTime } from "../../config/config"; |
| 3 | import { closeNotification, updateReadStatus } from "./notifications"; |
| 4 | import Info from "carbon-icons-svelte/lib/Information.svelte"; |
| 5 | import Warning from "carbon-icons-svelte/lib/WarningAlt.svelte"; |
| 6 | import Error from "carbon-icons-svelte/lib/CloseOutline.svelte"; |
| 7 | |
| 8 | export let id; |
| 9 | export let type = ""; |
| 10 | export let title = ""; |
| 11 | export let message = ""; |
| 12 | export let read = false; |
| 13 | export let actions = []; |
| 14 | |
| 15 | let notification: HTMLElement | null; |
| 16 | </script> |
| 17 | |
| 18 | <div class="info"> |
| 19 | <span>{getTime()}</span> |
| 20 | <!-- svelte-ignore a11y-click-events-have-key-events --> |
| 21 | <span class="mark-read" on:click|preventDefault={() => { |
| 22 | read = !read |
| 23 | updateReadStatus(id, read); |
| 24 | } |
| 25 | }> |
| 26 | {#if read} |
| 27 | Mark as unread |
| 28 | {:else} |
| 29 | Mark as read |
| 30 | {/if} |
| 31 | </span> |
| 32 | </div> |
| 33 | <div bind:this={notification} class="notification" class:error={type === "Error"} class:warning={type === "Warning"} class:read> |
| 34 | <div class="notification-info"> |
| 35 | <div class="details"> |
| 36 | <div class="icon"> |
| 37 | {#if type === "Error"} |
| 38 | <Error /> |
| 39 | {:else if type === "Warning"} |
| 40 | <Warning /> |
| 41 | {:else} |
| 42 | <Info /> |
| 43 | {/if} |
| 44 | </div> |
| 45 | <div class="title">{type}: {title}</div> |
| 46 | </div> |
| 47 | <!-- svelte-ignore a11y-click-events-have-key-events --> |
| 48 | <span class="close-button" on:click={() => {closeNotification(id)}}></span> |
| 49 | </div> |
| 50 | |
| 51 | <div class="message">{message}</div> |
| 52 | |
| 53 | {#if actions.length > 0} |
| 54 | <div class="actions"> |
| 55 | {#each actions as action} |
| 56 | <!-- svelte-ignore a11y-click-events-have-key-events --> |
| 57 | <div class="action-button" on:click={action.action}>{action.label}</div> |
| 58 | {/each} |
| 59 | </div> |
| 60 | {/if} |
| 61 | </div> |
| 62 | |
| 63 | <style lang="scss"> |
| 64 | $notification-height: 3rem; |
| 65 | $notification-border-width: 1px; |
| 66 | $error-color: #c02b2b; |
| 67 | $warning-color: #ffeb10; |
| 68 | .info { |
| 69 | color: #6d6d6d; |
| 70 | font-weight: 200; |
| 71 | font-size: 0.7rem; |
| 72 | margin-bottom: 0.5rem; |
| 73 | margin-top: 0.2rem; |
| 74 | display: flex; |
| 75 | align-items: center; |
| 76 | span { |
| 77 | margin: 0 5px; |
| 78 | } |
| 79 | .mark-read { |
| 80 | text-decoration: underline; |
| 81 | cursor: pointer; |
| 82 | &:hover { |
| 83 | color: #939393; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | .notification { |
| 88 | display: flex; |
| 89 | min-height: $notification-height; |
| 90 | margin-bottom: 0.8rem; |
| 91 | position: relative; |
| 92 | flex-direction: column; |
| 93 | justify-content: center; |
| 94 | .icon { |
| 95 | display: flex; |
| 96 | align-items: center; |
| 97 | justify-content: center; |
| 98 | :global(svg) { |
| 99 | height: 22px; |
| 100 | width: 22px; |
| 101 | } |
| 102 | } |
| 103 | &.warning { |
| 104 | border-top: 3px solid $warning-color; |
| 105 | .icon { |
| 106 | color: $warning-color; |
| 107 | } |
| 108 | } |
| 109 | &.error { |
| 110 | border-top: 3px solid $error-color; |
| 111 | .icon { |
| 112 | color: $error-color; |
| 113 | } |
| 114 | } |
| 115 | &.read { |
| 116 | .action-button { |
| 117 | color: #bdd4ff75 !important; |
| 118 | } |
| 119 | :global(.bx--toast-notification__close-button .bx--toast-notification__close-icon) { |
| 120 | fill: #bdd4ff75 !important; |
| 121 | } |
| 122 | } |
| 123 | &::before { |
| 124 | position: absolute; |
| 125 | height: 100%; |
| 126 | width: 100%; |
| 127 | border-width: 0 $notification-border-width $notification-border-width $notification-border-width; |
| 128 | border-style: solid; |
| 129 | box-sizing: border-box; |
| 130 | content: ""; |
| 131 | } |
| 132 | .notification-info { |
| 133 | display: flex; |
| 134 | justify-content: space-between; |
| 135 | min-height: 3rem; |
| 136 | } |
| 137 | .details { |
| 138 | display: flex; |
| 139 | margin: 0 0.5rem; |
| 140 | position: relative; |
| 141 | top: -1px; |
| 142 | align-items: center; |
| 143 | .icon { |
| 144 | border-radius: 50%; |
| 145 | min-width: 20px; |
| 146 | min-height: 20px; |
| 147 | margin-right: 10px; |
| 148 | } |
| 149 | } |
| 150 | .message { |
| 151 | font-size: 15px; |
| 152 | color: #6d6d6d; |
| 153 | margin: 0.5rem 0; |
| 154 | margin-left: 2.4rem; |
| 155 | margin-top: -0.5rem; |
| 156 | } |
| 157 | .actions { |
| 158 | display: flex; |
| 159 | margin: 0 0.5rem; |
| 160 | position: relative; |
| 161 | top: -1px; |
| 162 | align-items: center; |
| 163 | margin-left: 2.4rem; |
| 164 | margin-bottom: 0.5rem; |
| 165 | .action-button { |
| 166 | display: flex; |
| 167 | justify-content: center; |
| 168 | align-items: center; |
| 169 | cursor: pointer; |
| 170 | &:nth-child(2) { |
| 171 | margin: 0 0.6rem; |
| 172 | } |
| 173 | &:hover { |
| 174 | text-decoration: underline; |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | .close-button { |
| 179 | font-size: 12px; |
| 180 | padding: 0 7px; |
| 181 | display: flex; |
| 182 | align-items: center; |
| 183 | justify-content: center; |
| 184 | border-radius: 3px; |
| 185 | margin: 0 0.5rem; |
| 186 | cursor: pointer; |
| 187 | &::before { |
| 188 | content: "\2715"; |
| 189 | } |
| 190 | z-index: 10; |
| 191 | } |
| 192 | } |
| 193 | </style> |