feat: Add login stuff

This commit is contained in:
Xyphyn committed 2023-07-04 13:08:58 -07:00
1 parent f71ad4be8e
commit f0523b0c3f
18 files changed
+288 -56

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
<script lang="ts">
import {
ToastType,
type Toast,
toasts,
} from '$lib/components/ui/toasts/toasts'
import {
InformationCircle,
ExclamationTriangle,
ExclamationCircle,
CheckCircle,
Icon,
XMark,
} from 'svelte-hero-icons'
import { expoInOut } from 'svelte/easing'
import { scale } from 'svelte/transition'
export let toast: Toast
</script>
<div
class="relative w-80 min-h-[4rem] dark:bg-zinc-900 bg-white shadow-lg rounded-md overflow-hidden flex flex-row items-center"
transition:scale={{
duration: 500,
start: 0.8,
easing: expoInOut,
}}
>
<div
class="h-full w-[2px] absolute left-0 top-0 bg-gradient-to-b {toast.type}"
/>
<Icon
size="20"
solid
class="relative m-2 ml-4 flex-shrink-0 {toast.type}"
src={toast.type == ToastType.info
? InformationCircle
: toast.type == ToastType.success
? CheckCircle
: toast.type == ToastType.warning
? ExclamationTriangle
: toast.type == ToastType.error
? ExclamationCircle
: ExclamationCircle}
/>
<div class="flex flex-col p-4 pl-0">
<h1 class="text-base font-bold">{toast.title}</h1>
<p class="text-sm">{toast.content}</p>
</div>
<button
on:click={() => {
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
}}
class="absolute top-0 right-0 p-2 m-2 rounded-lg transition-colors hover:bg-slate-100 hover:dark:bg-zinc-700"
>
<Icon src={XMark} size="20" />
</button>
</div>
@@ -0,0 +1,19 @@
<script lang="ts">
import Toast from '$lib/components/ui/toasts/Toast.svelte'
import { flip } from 'svelte/animate'
import { expoInOut } from 'svelte/easing'
import { toasts } from '$lib/components/ui/toasts/toasts'
</script>
<div
class="fixed right-0 top-0 flex flex-col gap-4 z-50 p-4 overflow-hidden h-screen min-w-[24rem] items-end pointer-events-none"
>
{#each $toasts as toast (toast.id)}
<div
animate:flip={{ duration: 500, easing: expoInOut }}
class="pointer-events-auto"
>
<Toast {toast} />
</div>
{/each}
</div>
+39
View File
@@ -0,0 +1,39 @@
import { writable } from 'svelte/store'
export enum ToastType {
'error' = 'from-red-400 to-red-400 text-red-400',
'warning' = 'from-yellow-300 to-yellow-300 text-yellow-300',
'success' = 'from-green-400 to-green-400 text-green-400',
'info' = '',
}
export interface Toast {
id: number
title: string
content: string
type: ToastType
}
export const toasts = writable<Toast[]>([])
export function addToast(title: string, content: string, type: ToastType) {
let id = 0
toasts.update((toasts) => {
id = Math.floor(Math.random() * 10000)
return [
{
id: id,
content: content,
title: title,
type: type,
},
...toasts,
]
})
setTimeout(() => {
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
}, 5000)
}