design: Change toast design
This commit is contained in:
1 parent
e243848e17
commit
4bacc2f0a1
6 files changed
+50
-41
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
||||||
|
import { twMerge } from 'tailwind-merge'
|
||||||
|
|
||||||
type ButtonColor = keyof typeof buttonColor
|
type ButtonColor = keyof typeof buttonColor
|
||||||
type ButtonSize = keyof typeof buttonSize
|
type ButtonSize = keyof typeof buttonSize
|
||||||
@@ -48,16 +49,14 @@
|
|||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
export let href: string | undefined = undefined
|
export let href: string | undefined = undefined
|
||||||
|
|
||||||
let buttonClass = `
|
let buttonClass = twMerge(
|
||||||
${buttonColor[color]}
|
buttonColor[color],
|
||||||
${buttonSize[size]}
|
buttonSize[size],
|
||||||
${buttonRoundness[rounded]}
|
buttonRoundness[rounded],
|
||||||
${
|
loading ? (color == 'primary' ? '!bg-transparent !text-inherit' : '') : '',
|
||||||
loading ? (color == 'primary' ? '!bg-transparent !text-inherit' : '') : ''
|
'text-sm transition-all disabled:opacity-70 disabled:pointer-events-none',
|
||||||
}
|
$$props.class
|
||||||
text-sm transition-all disabled:opacity-70 disabled:pointer-events-none
|
)
|
||||||
${$$props.class}
|
|
||||||
`
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if href}
|
{#if href}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
||||||
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||||
import MenuButton from '$lib/components/ui/menu/MenuButton.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 { authData, getInstance, instance, user } from '$lib/lemmy.js'
|
||||||
import { Color } from '$lib/ui/colors.js'
|
import { Color } from '$lib/ui/colors.js'
|
||||||
import {
|
import {
|
||||||
@@ -39,6 +40,16 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-row gap-2 py-2 px-3">
|
<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">
|
<Button href="/communities" label="Communities">
|
||||||
<Icon src={GlobeAlt} width={16} slot="icon" />
|
<Icon src={GlobeAlt} width={16} slot="icon" />
|
||||||
<span class="hidden sm:inline">Explore</span>
|
<span class="hidden sm:inline">Explore</span>
|
||||||
|
|||||||
@@ -12,26 +12,23 @@
|
|||||||
Icon,
|
Icon,
|
||||||
XMark,
|
XMark,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { expoInOut } from 'svelte/easing'
|
import { fly } from 'svelte/transition'
|
||||||
import { scale } from 'svelte/transition'
|
|
||||||
export let toast: Toast
|
export let toast: Toast
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<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"
|
class="{toast.type} relative w-80 rounded-md overflow-hidden flex flex-row items-center"
|
||||||
transition:scale={{
|
transition:fly={{
|
||||||
duration: 500,
|
duration: 300,
|
||||||
start: 0.8,
|
y: 8,
|
||||||
easing: expoInOut,
|
opacity: 0,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
|
||||||
class="h-full w-[2px] absolute left-0 top-0 bg-gradient-to-b {toast.type}"
|
|
||||||
/>
|
|
||||||
<Icon
|
<Icon
|
||||||
size="20"
|
size="20"
|
||||||
solid
|
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
|
src={toast.type == ToastType.info
|
||||||
? InformationCircle
|
? InformationCircle
|
||||||
: toast.type == ToastType.success
|
: toast.type == ToastType.success
|
||||||
@@ -42,7 +39,7 @@
|
|||||||
? ExclamationCircle
|
? ExclamationCircle
|
||||||
: 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}
|
{#if toast.title}
|
||||||
<h1 class="text-base font-bold">{toast.title}</h1>
|
<h1 class="text-base font-bold">{toast.title}</h1>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -52,8 +49,8 @@
|
|||||||
on:click={() => {
|
on:click={() => {
|
||||||
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
|
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>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,17 +1,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Toast from '$lib/components/ui/toasts/Toast.svelte'
|
import Toast from '$lib/components/ui/toasts/Toast.svelte'
|
||||||
import { flip } from 'svelte/animate'
|
import { flip } from 'svelte/animate'
|
||||||
import { expoInOut } from 'svelte/easing'
|
|
||||||
import { toasts } from '$lib/components/ui/toasts/toasts'
|
import { toasts } from '$lib/components/ui/toasts/toasts'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<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
|
<div
|
||||||
animate:flip={{ duration: 500, easing: expoInOut }}
|
animate:flip={{ duration: 300 }}
|
||||||
class="pointer-events-auto"
|
class="pointer-events-auto -mt-8 transition-all group-hover:pt-12
|
||||||
|
duration-300"
|
||||||
>
|
>
|
||||||
<Toast {toast} />
|
<Toast {toast} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { writable } from 'svelte/store'
|
import { writable } from 'svelte/store'
|
||||||
|
|
||||||
export enum ToastType {
|
export enum ToastType {
|
||||||
'error' = 'from-red-400 to-red-400 text-red-400',
|
'error' = 'bg-red-500 text-black border border-red-600',
|
||||||
'warning' = 'from-yellow-300 to-yellow-300 text-yellow-300',
|
'warning' = 'bg-yellow-400 text-black border border-yellow-500',
|
||||||
'success' = 'from-green-400 to-green-400 text-green-400',
|
'success' = 'bg-green-400 text-black border border-green-500',
|
||||||
'info' = '',
|
'info' = 'dark:bg-zinc-900 bg-white border border-slate-200 dark:border-zinc-800 shadow-lg',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Toast {
|
export interface Toast {
|
||||||
@@ -20,10 +20,12 @@ export function toast({
|
|||||||
title,
|
title,
|
||||||
content,
|
content,
|
||||||
type = ToastType.info,
|
type = ToastType.info,
|
||||||
|
duration = 5000,
|
||||||
}: {
|
}: {
|
||||||
title?: string
|
title?: string
|
||||||
content: string
|
content: string
|
||||||
type: ToastType
|
type?: ToastType
|
||||||
|
duration?: number
|
||||||
}) {
|
}) {
|
||||||
let id = 0
|
let id = 0
|
||||||
|
|
||||||
@@ -31,19 +33,19 @@ export function toast({
|
|||||||
id = Math.floor(Math.random() * 10000)
|
id = Math.floor(Math.random() * 10000)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
...toasts,
|
||||||
{
|
{
|
||||||
id: id,
|
id: id,
|
||||||
content: content,
|
content: content,
|
||||||
title: title,
|
title: title,
|
||||||
type: type,
|
type: type,
|
||||||
},
|
},
|
||||||
...toasts,
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
||||||
}, 5000)
|
}, duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
|
|
||||||
<Card class="flex flex-col bg-white rounded-md p-4 max-w-full">
|
<Card class="flex flex-col bg-white rounded-md p-4 max-w-full">
|
||||||
{#if !isPrivateMessage(item)}
|
{#if !isPrivateMessage(item)}
|
||||||
<div class="flex flex-row items-center">
|
<div class="flex flex-row items-center justify-between">
|
||||||
<div
|
<div
|
||||||
class="text-sm max-w-[80ch] whitespace-nowrap text-ellipsis
|
class="text-sm max-w-[80ch] whitespace-nowrap text-ellipsis
|
||||||
overflow-hidden {read ? 'opacity-50' : ''}"
|
overflow-hidden {read ? 'opacity-50' : ''}"
|
||||||
@@ -85,9 +85,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="w-max ml-auto">
|
<Button href="/post/{item.post.id}#{item.comment.id}">Jump</Button>
|
||||||
<Button href="/post/{item.post.id}#{item.comment.id}">Jump</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Comment
|
<Comment
|
||||||
@@ -137,9 +135,9 @@
|
|||||||
<Button
|
<Button
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
{loading}
|
{loading}
|
||||||
large
|
|
||||||
on:click={() => replyToMessage(item)}
|
on:click={() => replyToMessage(item)}
|
||||||
color="primary"
|
color="primary"
|
||||||
|
size="sm"
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in new issue
Block a user