design: re-do menus, dynamic origin animations
This commit is contained in:
14 files changed
+91
-74
No files matched your search
@@ -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>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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>
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user