-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #199 from Klantinteractie-Servicesysteem/feature/R…
…-03_na_registreren_terug_startscherm Feature/R-03 na registreren terug startscherm
- Loading branch information
Showing
5 changed files
with
106 additions
and
38 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
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,60 @@ | ||
<template> | ||
<!-- https://web.dev/building-a-toast-component/ --> | ||
<transition-group name="toast" tag="section"> | ||
<output | ||
v-for="{ text, type, key } in messages" | ||
:key="key" | ||
role="status" | ||
:class="type" | ||
>{{ text }}</output | ||
> | ||
</transition-group> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { messages } from "@/stores/toast"; | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
section { | ||
position: fixed; | ||
z-index: 1; | ||
inset-block-end: 0; | ||
inset-inline: 0; | ||
padding-block-end: 5vh; | ||
display: grid; | ||
justify-items: center; | ||
justify-content: center; | ||
gap: 1vh; | ||
pointer-events: none; | ||
} | ||
output { | ||
max-inline-size: min(25ch, 90vw); | ||
padding: var(--spacing-default); | ||
border-radius: var(--radius-default); | ||
font-size: 1rem; | ||
color: white; | ||
} | ||
.confirm { | ||
background-color: var(--color-accent); | ||
} | ||
.toast-move, /* apply transition to moving elements */ | ||
.toast-enter-active, | ||
.toast-leave-active { | ||
transition: all 0.5s ease; | ||
} | ||
.toast-enter-from, | ||
.toast-leave-to { | ||
opacity: 0; | ||
} | ||
/* ensure leaving items are taken out of layout flow so that moving | ||
animations can be calculated correctly. */ | ||
.toast-leave-active { | ||
position: absolute; | ||
} | ||
</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
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,36 @@ | ||
import { reactive } from "vue"; | ||
|
||
type MessageType = "confirm" | "error"; | ||
|
||
interface ToastParams { | ||
text: string; | ||
type?: MessageType; | ||
timeout?: number; | ||
} | ||
|
||
interface Message { | ||
readonly text: string; | ||
readonly type: MessageType; | ||
readonly key: number; | ||
} | ||
|
||
let key = 0; | ||
|
||
const _messages = reactive<Message[]>([]); | ||
|
||
export const messages = _messages as readonly Message[]; | ||
|
||
export function toast(params: ToastParams) { | ||
const m = { | ||
text: params.text, | ||
type: params.type || "confirm", | ||
key: (key += 1), | ||
}; | ||
_messages.push(m); | ||
setTimeout(() => { | ||
const index = _messages.indexOf(m); | ||
if (index !== -1) { | ||
_messages.splice(index, 1); | ||
} | ||
}, params.timeout || 3000); | ||
} |
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