design: re-do menus, dynamic origin animations

This commit is contained in:
James Xylight committed 2025-08-22 15:35:53 -07:00
1 parent 148436d3b8
commit 0805313852
14 files changed
+91 -74

No files matched your search

+11 -10
View File
@@ -3,8 +3,8 @@
export type Shadow = keyof typeof shadowClass
export const sizeClass = {
sm: 'px-3 py-1.5',
md: 'px-4 py-2',
sm: 'px-3 py-1',
md: 'px-3.5 py-1.5',
lg: 'px-5 py-3',
}
@@ -39,7 +39,7 @@
import Label from '../forms/Label.svelte'
import { generateID } from '../forms/helper.js'
const borderClass = `border border-slate-200 border-b-slate-300 dark:border-t-zinc-800 dark:border-zinc-900`
const borderClass = `border border-slate-200 border-b-slate-300 dark:border-zinc-800`
let {
label = undefined,
@@ -86,10 +86,11 @@
>
{#if prefix}
<div
class="rounded-xl rounded-r-none
text-slate-600 dark:text-zinc-400 {inlineAffixes
? 'bg-white dark:bg-zinc-950 pr-0 w-8'
: ''} {sizeClass[size]}"
class={[
'rounded-xl rounded-r-none text-slate-600 dark:text-zinc-400',
inlineAffixes && 'bg-white dark:bg-zinc-900 pr-0 w-8',
sizeClass[size],
]}
>
{@render prefix?.()}
</div>
@@ -104,9 +105,9 @@
{...rest}
class={[
sizeClass[size],
`bg-white dark:bg-zinc-950
`bg-white dark:bg-zinc-900
focus:outline-hidden rounded-xl text-sm w-full disabled:bg-slate-100
disabled:cursor-not-allowed dark:disabled:bg-zinc-950 invalid:border-red-500!
disabled:cursor-not-allowed dark:disabled:bg-zinc-800 invalid:border-red-500!
peer invalid:text-red-500 z-10`,
prefix && 'rounded-l-none',
prefix && inlineAffixes && 'border-l-0',
@@ -119,7 +120,7 @@
<div
class={[
'rounded-xl rounded-l-none text-slate-600 dark:text-zinc-400',
inlineAffixes && 'bg-white dark:bg-zinc-950 pl-0',
inlineAffixes && 'bg-white dark:bg-zinc-900 pl-0',
sizeClass[size],
]}
>
+4 -1
View File
@@ -26,6 +26,7 @@
>
oncontextmenu?: HTMLSelectAttributes['oncontextmenu']
onchange?: HTMLSelectAttributes['onchange']
placement?: Placement
}
export type { Props as SelectProps }
@@ -51,6 +52,7 @@
import MenuButton from '../../popover/MenuButton.svelte'
import Label from '../Label.svelte'
import { generateID } from '../helper.js'
import type { Placement } from 'svelte-floating-ui/core'
let open = $state(false)
let element: HTMLSelectElement | undefined = $state()
@@ -84,6 +86,7 @@
customOption,
oncontextmenu,
onchange,
placement = 'bottom',
...rest
}: Props<T> = $props()
</script>
@@ -96,7 +99,7 @@
{/if}
<div class="w-full relative">
<Menu bind:open>
<Menu bind:open {placement}>
{#snippet target()}
<select
{...rest}
+4 -4
View File
@@ -43,17 +43,17 @@
{manual}
{...rest}
bind:open
popoverClass="backdrop-blur-xl rounded-2xl w-full max-w-[280px]"
popoverClass="rounded-xl w-full backdrop-blur-md max-w-72"
class={clazz}
{target}
>
{#snippet popover()}
<div
class="w-full max-w-sm origin-top-left max-h-128 overflow-auto list-none shadow-lg rounded-2xl"
class="w-full max-w-sm origin-top-left max-h-128 overflow-auto list-none shadow-lg rounded-xl"
>
<div
class="flex flex-col px-0 list-none bg-white/80 dark:bg-zinc-900/90 rounded-2xl
border border-slate-300 dark:border-zinc-800 border-opacity-50 py-1"
class="flex flex-col p-1 list-none bg-white/80 dark:bg-zinc-900/90 rounded-xl
border border-slate-300 dark:border-zinc-800 border-opacity-50 gap-px"
>
{@render children?.(open)}
</div>
+1 -1
View File
@@ -40,7 +40,7 @@
size="custom"
rounding="none"
class={[
'w-full px-4.5 py-1.5 min-h-7 duration-100 font-normal',
'w-full px-3 py-1.5 min-h-7 duration-75 hover:cursor-default font-normal rounded-lg',
disabled && 'opacity-70 pointer-events-none cursor-not-allowed',
color == 'tertiary' && 'dark:hover:bg-zinc-800/70',
clazz,
+4 -10
View File
@@ -1,18 +1,12 @@
<script>
/**
* @typedef {Object} Props
* @property {import('svelte').Snippet} [children]
*/
/** @type {Props} */
<script lang="ts">
let { children } = $props()
</script>
<div
class="text-slate-800 dark:text-zinc-200 text-xs font-medium m-4 mb-1 flex items-center gap-1"
class="text-slate-800 dark:text-zinc-200 text-xs font-medium m-3 my-2 mb-1 flex items-center gap-1"
>
<div>{@render children?.()}</div>
<div class="sr-only">{@render children?.()}</div>
<hr
class="shrink flex-1 border-slate-200 dark:border-zinc-800 border-opacity-70"
class="shrink flex-1 border-slate-100 dark:border-zinc-800 border-opacity-70 -mx-4"
/>
</div>
+34 -13
View File
@@ -1,16 +1,3 @@
<script module lang="ts">
export type Origin = keyof typeof popoverOrigins
export const popoverOrigins = {
'top-right': 'bottom-full right-0 origin-bottom-right',
'bottom-left': 'top-full origin-top-left',
'top-left': 'bottom-full left-0 origin-bottom-left',
'bottom-right': 'top-full right-0 origin-top-right',
'top-center': 'bottom-full -left-[450%] origin-bottom',
'bottom-center': 'top-full -left-[450%] origin-top',
}
</script>
<script lang="ts">
import {
flip,
@@ -62,12 +49,46 @@
let el = $state<HTMLElement>()
let popoverEl = $state<HTMLElement>()
let origins: Record<Placement, string> = {
bottom: 'top',
'bottom-end': 'top right',
'bottom-start': 'top left',
left: 'left',
'left-end': 'left',
'left-start': 'left',
right: 'right',
'right-end': 'right',
'right-start': 'right',
top: 'bottom',
'top-end': 'bottom right',
'top-start': 'bottom',
}
const [floatingRef, floatingContent] = createFloatingActions({
strategy: strategy,
placement: placement,
middleware: middleware,
onComputed: ({ x, y, placement }) => {
if (popoverEl) {
popoverEl.style.transformOrigin = origins[placement]
}
console.log(placement)
// @ts-expect-error svelte hell
Object.assign(el?.children?.item?.(0) ?? el, {
top: '0',
left: '0',
transform: `translate3d(${roundByDPR(x)}px,${roundByDPR(y)}px,0)`,
})
},
})
function roundByDPR(value: number) {
const dpr = window.devicePixelRatio || 1
return Math.round(value * dpr) / dpr
}
const customFloatingContent = (node: HTMLDivElement) => {
// if (!canUseContents) return
+6 -16
View File
@@ -24,7 +24,8 @@
<div
class={[
toastColors[toast.type],
'relative rounded-2xl overflow-hidden flex flex-row items-center gap-2 px-3 py-3 backdrop-blur-lg',
'relative rounded-xl overflow-hidden flex flex-row items-center gap-2 px-3 py-3',
'bg-white dark:bg-zinc-900 shadow-lg',
toast.long ? 'w-full max-w-lg' : 'w-80',
]}
transition:fly={{
@@ -42,16 +43,7 @@
<Icon
size="28"
mini
class={[
'relative self-center shrink-0 p-1 rounded-lg',
toast.type == 'info'
? 'bg-slate-200 dark:bg-zinc-50 text-slate-700 dark:text-zinc-700'
: toast.type == 'success'
? 'bg-green-400 dark:bg-green-300 dark:text-green-900 text-green-50'
: toast.type == 'warning'
? 'bg-yellow-400 dark:bg-yellow-300 dark:text-yellow-900 text-yellow-50'
: 'bg-red-400 dark:bg-red-300 dark:text-red-900 text-red-50',
]}
class={['relative self-center shrink-0 p-1 rounded-lg']}
src={toast.type == 'info'
? InformationCircle
: toast.type == 'success'
@@ -63,9 +55,7 @@
: ExclamationCircle}
/>
{/if}
<div
class="flex flex-col break-words max-w-full text-slate-900 dark:text-zinc-50"
>
<div class="flex flex-col break-words max-w-full text-inherit">
{#if toast.title}
<h1 class="text-base font-semibold">{toast.title}</h1>
{/if}
@@ -90,9 +80,9 @@
onclick={() => {
toasts.update(toasts => toasts.filter(t => t.id != toast.id))
}}
class="rounded-lg w-max transition-colors hover:bg-slate-100 dark:hover:bg-zinc-800 p-1 cursor-pointer"
class="rounded-lg w-max transition-colors hover:bg-slate-100 dark:hover:bg-zinc-800 p-1 cursor-pointer text-slate-600 dark:text-zinc-400"
>
<Icon src={XMark} size="20" micro />
<Icon src={XMark} size="16" micro />
</button>
</div>
</div>
+1 -1
View File
@@ -11,7 +11,7 @@
>
{#each $toasts as toast (toast.id)}
<div
animate:flip={{ duration: 500, easing: expoOut }}
animate:flip={{ duration: 300, easing: expoOut }}
class="pointer-events-auto transition-all
duration-300"
>
+4 -4
View File
@@ -3,10 +3,10 @@ import { writable } from 'svelte/store'
type ToastType = keyof typeof toastColors
export const toastColors = {
error: 'bg-red-100/50 dark:bg-red-900/20 border-red-300/40 border',
warning: 'bg-yellow-100/50 dark:bg-yellow-500/5 border-yellow-500/40 border',
success: 'bg-green-100/50 dark:bg-green-900/20 border-green-300/40 border',
info: 'dark:bg-zinc-925/90 bg-white border border-slate-200 dark:border-zinc-800',
error: 'text-red-600 dark:text-red-400',
warning: 'text-yellow-600 dark:text-yellow-400',
success: 'text-green-600 dark:text-green-400',
info: '',
}
export interface Toast {