-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TSK-212: add notification on issue created (#2325)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
- Loading branch information
1 parent
bfcbb73
commit 15c2aa8
Showing
19 changed files
with
406 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script lang="ts"> | ||
export let size: 'small' | 'medium' | 'large' | ||
export let fill: string = 'currentColor' | ||
</script> | ||
|
||
<svg class="svg-{size}" viewBox="0 0 16 16" {fill} xmlns="http://www.w3.org/2000/svg"> | ||
<path | ||
fill-rule="evenodd" | ||
clip-rule="evenodd" | ||
d="M8 15C11.866 15 15 11.866 15 8C15 4.13401 11.866 1 8 1C4.13401 1 1 4.13401 1 8C1 11.866 4.13401 15 8 15ZM11.7836 6.42901C12.0858 6.08709 12.0695 5.55006 11.7472 5.22952C11.4248 4.90897 10.9186 4.9263 10.6164 5.26821L7.14921 9.19122L5.3315 7.4773C5.00127 7.16593 4.49561 7.19748 4.20208 7.54777C3.90855 7.89806 3.93829 8.43445 4.26852 8.74581L6.28032 10.6427C6.82041 11.152 7.64463 11.1122 8.13886 10.553L11.7836 6.42901Z" | ||
/> | ||
</svg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/ui/src/components/notifications/Notification.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script lang="ts"> | ||
import { onDestroy } from 'svelte' | ||
import { Notification } from './Notification' | ||
import store from './store' | ||
export let notification: Notification | ||
const { id, closeTimeout } = notification | ||
const removeNotificationHandler = () => store.removeNotification(id) | ||
let timeout: number | null = null | ||
if (closeTimeout) { | ||
timeout = setTimeout(removeNotificationHandler, closeTimeout) | ||
} | ||
onDestroy(() => { | ||
if (closeTimeout && timeout) { | ||
clearTimeout(timeout) | ||
} | ||
}) | ||
</script> | ||
|
||
<svelte:component this={notification.component} {notification} onRemove={removeNotificationHandler} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NotificationPosition } from './NotificationPosition' | ||
import { NotificationSeverity } from './NotificationSeverity' | ||
import { AnyComponent } from '../../types' | ||
|
||
export interface Notification { | ||
id: string | ||
title: string | ||
component: AnyComponent | ||
subTitle?: string | ||
subTitlePostfix?: string | ||
position: NotificationPosition | ||
severity?: NotificationSeverity | ||
params?: { [key: string]: any } | ||
closeTimeout?: number | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/ui/src/components/notifications/NotificationPosition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum NotificationPosition { | ||
BottomLeft, | ||
BottomRight, | ||
TopLeft, | ||
TopRight | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/ui/src/components/notifications/NotificationSeverity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum NotificationSeverity { | ||
Info, | ||
Success, | ||
Warning, | ||
Error | ||
} |
51 changes: 51 additions & 0 deletions
51
packages/ui/src/components/notifications/Notifications.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<script lang="ts"> | ||
import Notification from './Notification.svelte' | ||
import { NotificationPosition } from './NotificationPosition' | ||
import store from './store' | ||
const positionByClassName = { | ||
'bottom-left': NotificationPosition.BottomLeft, | ||
'bottom-right': NotificationPosition.BottomRight, | ||
'top-left': NotificationPosition.TopLeft, | ||
'top-right': NotificationPosition.TopRight | ||
} | ||
</script> | ||
|
||
<slot /> | ||
<div class="notifications"> | ||
{#each Object.entries(positionByClassName) as [className, position]} | ||
<div class={className} style:z-index={9999}> | ||
{#each $store as notification (notification.id)} | ||
{#if notification.position === position} | ||
<Notification {notification} /> | ||
{/if} | ||
{/each} | ||
</div> | ||
{/each} | ||
</div> | ||
|
||
<style lang="scss"> | ||
.top-left { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
} | ||
.top-right { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
} | ||
.bottom-left { | ||
position: fixed; | ||
bottom: 0; | ||
left: 0; | ||
} | ||
.bottom-right { | ||
position: fixed; | ||
bottom: 0; | ||
right: 0; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Writable } from 'svelte/store' | ||
import { generateId } from '@hcengineering/core' | ||
|
||
import { Notification } from './Notification' | ||
import { NotificationPosition } from './NotificationPosition' | ||
import { NotificationSeverity } from './NotificationSeverity' | ||
|
||
export const addNotification = (notification: Notification, store: Writable<Notification[]>): void => { | ||
if (notification === undefined || notification === null) { | ||
return | ||
} | ||
|
||
const { update } = store | ||
|
||
const newNotification = { | ||
severity: NotificationSeverity.Info, | ||
...notification, | ||
id: generateId() | ||
} | ||
|
||
update((notifications: Notification[]) => | ||
[NotificationPosition.TopRight, NotificationPosition.TopLeft].includes(newNotification.position) | ||
? [newNotification, ...notifications] | ||
: [...notifications, newNotification] | ||
) | ||
} | ||
|
||
export const removeNotification = (notificationId: string, { update }: Writable<Notification[]>): void => { | ||
if (notificationId === '') { | ||
return | ||
} | ||
|
||
update((notifications) => notifications.filter(({ id }) => id !== notificationId)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { writable } from 'svelte/store' | ||
|
||
import { Notification } from './Notification' | ||
import { addNotification, removeNotification } from './actions' | ||
|
||
const store = writable<Notification[]>([]) | ||
|
||
export default { | ||
subscribe: store.subscribe, | ||
addNotification: (notification: Notification) => addNotification(notification, store), | ||
removeNotification: (notificationId: string) => removeNotification(notificationId, store) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.