-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
- Loading branch information
1 parent
30aa78f
commit ad8d60d
Showing
19 changed files
with
449 additions
and
28 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,10 @@ | ||
<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={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
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
<script lang="ts"> | ||
import { onDestroy } from 'svelte' | ||
import { Notification } from './Notification' | ||
import { getNotificationsContext } from './store' | ||
export let notification: Notification = {} | ||
const { removeNotification } = getNotificationsContext() | ||
const { | ||
id, | ||
closeTimeout | ||
} = notification | ||
const removeNotificationHandler = () => removeNotification(id) | ||
let timeout = 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= 'BottomLeft', | ||
BottomRight= 'BottomRight', | ||
TopLeft = 'TopLeft', | ||
TopRight = '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 { | ||
Success = 'Success', | ||
Warning = 'Warning', | ||
Error = 'Error', | ||
Info = 'Info', | ||
} |
62 changes: 62 additions & 0 deletions
62
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,62 @@ | ||
<script lang="ts"> | ||
import { setContext } from 'svelte' | ||
import Notification from './Notification.svelte' | ||
import store, { notificationsContextKey } from './store' | ||
import { NotificationPosition } from './NotificationPosition' | ||
const getClass = (position: NotificationPosition) => { | ||
switch (position) { | ||
case NotificationPosition.BottomLeft: | ||
return 'bottom-left' | ||
case NotificationPosition.BottomRight: | ||
return 'bottom-right' | ||
case NotificationPosition.TopLeft: | ||
return 'top-left' | ||
case NotificationPosition.TopRight: | ||
return 'top-right' | ||
} | ||
} | ||
setContext(notificationsContextKey, store) | ||
</script> | ||
|
||
<slot></slot> | ||
<div class="notifications"> | ||
{#each [NotificationPosition.TopRight, NotificationPosition.TopLeft, NotificationPosition.BottomRight, NotificationPosition.BottomLeft] as position} | ||
<div class={getClass(position)} | ||
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,32 @@ | ||
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,22 @@ | ||
import { writable } from 'svelte/store' | ||
import { getContext } from 'svelte' | ||
|
||
import { Notification } from './Notification' | ||
import { addNotification, removeNotification } from './actions' | ||
|
||
const store = writable<Notification[]>([]) | ||
|
||
interface NotificationsContext { | ||
subscribe: typeof store.subscribe | ||
addNotification: (notification: Notification) => void | ||
removeNotification: (notificationId: string) => void | ||
} | ||
|
||
export const notificationsContextKey = 'notifications-context' | ||
export const getNotificationsContext = (): NotificationsContext => getContext(notificationsContextKey) | ||
|
||
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.