design: Change toast design

This commit is contained in:
Xyphyn committed 2023-07-19 14:17:29 -07:00
1 parent e243848e17
commit 4bacc2f0a1
6 files changed
+50 -41

No files matched your search

+9 -10
View File
@@ -1,6 +1,7 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte'
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
import { twMerge } from 'tailwind-merge'
type ButtonColor = keyof typeof buttonColor
type ButtonSize = keyof typeof buttonSize
@@ -48,16 +49,14 @@
const dispatch = createEventDispatcher()
export let href: string | undefined = undefined
let buttonClass = `
${buttonColor[color]}
${buttonSize[size]}
${buttonRoundness[rounded]}
${
loading ? (color == 'primary' ? '!bg-transparent !text-inherit' : '') : ''
}
text-sm transition-all disabled:opacity-70 disabled:pointer-events-none
${$$props.class}
`
let buttonClass = twMerge(
buttonColor[color],
buttonSize[size],
buttonRoundness[rounded],
loading ? (color == 'primary' ? '!bg-transparent !text-inherit' : '') : '',
'text-sm transition-all disabled:opacity-70 disabled:pointer-events-none',
$$props.class
)
</script>
{#if href}
+11
View File
@@ -6,6 +6,7 @@
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
import Menu from '$lib/components/ui/menu/Menu.svelte'
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
import { authData, getInstance, instance, user } from '$lib/lemmy.js'
import { Color } from '$lib/ui/colors.js'
import {
@@ -39,6 +40,16 @@
</a>
</div>
<div class="flex flex-row gap-2 py-2 px-3">
<Button
on:click={() =>
toast({
content: 'this is a test toast',
type: ToastType.error,
duration: 5000 * 5000,
})}
>
show toast
</Button>
<Button href="/communities" label="Communities">
<Icon src={GlobeAlt} width={16} slot="icon" />
<span class="hidden sm:inline">Explore</span>
+11 -14
View File
@@ -12,26 +12,23 @@
Icon,
XMark,
} from 'svelte-hero-icons'
import { expoInOut } from 'svelte/easing'
import { scale } from 'svelte/transition'
import { fly } 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,
class="{toast.type} relative w-80 rounded-md overflow-hidden flex flex-row items-center"
transition:fly={{
duration: 300,
y: 8,
opacity: 0,
}}
>
<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}"
class="relative m-2 ml-4 flex-shrink-0"
src={toast.type == ToastType.info
? InformationCircle
: toast.type == ToastType.success
@@ -42,7 +39,7 @@
? ExclamationCircle
: ExclamationCircle}
/>
<div class="flex flex-col p-4 pl-0 max-w-[90%]">
<div class="flex flex-col p-4 pl-0 mr-auto">
{#if toast.title}
<h1 class="text-base font-bold">{toast.title}</h1>
{/if}
@@ -52,8 +49,8 @@
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"
class="rounded-lg transition-colors hover:bg-slate-200 hover:dark:bg-zinc-800 p-2 m-2"
>
<Icon src={XMark} size="20" />
<Icon src={XMark} size="16" mini />
</button>
</div>
@@ -1,17 +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"
class="fixed right-0 bottom-0 flex flex-col items-end justify-end z-50 p-4
group
overflow-hidden h-screen min-w-[24rem] pointer-events-none"
>
{#each $toasts as toast (toast.id)}
{#each $toasts as toast, index (toast.id)}
<div
animate:flip={{ duration: 500, easing: expoInOut }}
class="pointer-events-auto"
animate:flip={{ duration: 300 }}
class="pointer-events-auto -mt-8 transition-all group-hover:pt-12
duration-300"
>
<Toast {toast} />
</div>
+9 -7
View File
@@ -1,10 +1,10 @@
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' = '',
'error' = 'bg-red-500 text-black border border-red-600',
'warning' = 'bg-yellow-400 text-black border border-yellow-500',
'success' = 'bg-green-400 text-black border border-green-500',
'info' = 'dark:bg-zinc-900 bg-white border border-slate-200 dark:border-zinc-800 shadow-lg',
}
export interface Toast {
@@ -20,10 +20,12 @@ export function toast({
title,
content,
type = ToastType.info,
duration = 5000,
}: {
title?: string
content: string
type: ToastType
type?: ToastType
duration?: number
}) {
let id = 0
@@ -31,19 +33,19 @@ export function toast({
id = Math.floor(Math.random() * 10000)
return [
...toasts,
{
id: id,
content: content,
title: title,
type: type,
},
...toasts,
]
})
setTimeout(() => {
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
}, 5000)
}, duration)
}
/**