-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e2da4b
commit 8c3a0f2
Showing
15 changed files
with
318 additions
and
43 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,48 @@ | ||
<template> | ||
<!-- Global notification live region, render this permanently at the end of the document --> | ||
<div | ||
aria-live="assertive" | ||
class="pointer-events-none fixed inset-0 flex items-end px-4 py-6 sm:items-start sm:p-6 z-50" | ||
> | ||
<div class="flex w-full flex-col items-center space-y-4 sm:items-end"> | ||
<!-- Notification panel, dynamically insert this into the live region when it needs to be displayed --> | ||
<transition | ||
enter-active-class="transform ease-out duration-300 transition" | ||
enter-from-class="translate-y-2 opacity-0 sm:translate-y-0 sm:translate-x-2" | ||
enter-to-class="translate-y-0 opacity-100 sm:translate-x-0" | ||
leave-active-class="transition ease-in duration-100" | ||
leave-from-class="opacity-100" | ||
leave-to-class="opacity-0" | ||
v-for="(notification, index) in state.notifications" | ||
> | ||
<NotificationComponent | ||
v-if="notification.visible" | ||
:type="notification.type" | ||
:title="notification.title" | ||
:details="notification.details" | ||
@close="closeNotification(index)" | ||
/> | ||
</transition> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { type Action } from 'redux'; | ||
import { injectStore, mapState } from 'redux-vuex'; | ||
import { actions, selectors } from '../../store'; | ||
import { type Notification } from '../../types/notification.types'; | ||
import NotificationComponent from './components/Notification.vue'; | ||
const store = injectStore(); | ||
const state = mapState<{ | ||
notifications: Notification[] | ||
}>({ | ||
notifications: selectors.notifications | ||
}); | ||
const closeNotification = (index: number) => { | ||
store.dispatch(actions.notifications.hide(index) as Action); | ||
}; | ||
</script> |
74 changes: 74 additions & 0 deletions
74
client/src/features/notifications/components/Notification.vue
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,74 @@ | ||
<template> | ||
<div | ||
class="pointer-events-auto w-full max-w-sm overflow-hidden rounded-lg bg-white shadow-lg ring-1 ring-black ring-opacity-5" | ||
> | ||
<div class="p-4"> | ||
<div class="flex items-start"> | ||
<div class="flex-shrink-0"> | ||
<InformationCircleIcon | ||
v-if="type === 'info'" | ||
class="h-6 w-6" | ||
:class="textColor" | ||
aria-hidden="true" | ||
/> | ||
<ExclamationCircleIcon | ||
v-if="type === 'error'" | ||
class="h-6 w-6" | ||
:class="textColor" | ||
aria-hidden="true" | ||
/> | ||
<ExclamationCircleIcon | ||
v-if="type === 'warning'" | ||
class="h-6 w-6" | ||
:class="textColor" | ||
aria-hidden="true" | ||
/> | ||
<CheckCircleIcon | ||
v-if="type === 'success'" | ||
class="h-6 w-6" | ||
:class="textColor" | ||
aria-hidden="true" | ||
/> | ||
</div> | ||
<div class="ml-3 w-0 flex-1 pt-0.5"> | ||
<p class="text-sm font-medium" :class="textColor">{{ title }}</p> | ||
<p class="mt-1 text-sm text-gray-500" v-if="details"> | ||
{{ details }} | ||
</p> | ||
</div> | ||
<div class="ml-4 flex flex-shrink-0"> | ||
<button | ||
type="button" | ||
@click="emit('close')" | ||
class="inline-flex rounded-md bg-white text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2" | ||
> | ||
<span class="sr-only">Close</span> | ||
<XMarkIcon class="h-5 w-5" aria-hidden="true" /> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { InformationCircleIcon, ExclamationCircleIcon, CheckCircleIcon } from '@heroicons/vue/24/outline'; | ||
import { XMarkIcon } from '@heroicons/vue/20/solid'; | ||
import { type Notification } from '../../../types/notification.types'; | ||
import { computed } from 'vue'; | ||
const props = defineProps<{ type: Notification['type']; title: string; details?: string }>(); | ||
const emit = defineEmits(['close']); | ||
const textColor = computed(() => { | ||
switch (props.type) { | ||
case 'info': | ||
return 'text-gray-900'; | ||
case 'error': | ||
return 'text-red-600'; | ||
case 'warning': | ||
return 'text-yellow-600'; | ||
case 'success': | ||
return 'text-green-600'; | ||
} | ||
}); | ||
</script> |
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
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.