Animate menu close with shared pop transition
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
import { pop } from '$lib/utils/transitions';
|
||||
|
||||
interface Props {
|
||||
class?: string;
|
||||
style?: string;
|
||||
@@ -12,9 +14,8 @@
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="glass-panel animate-pop rounded-panel p-1.5 {border
|
||||
? 'border border-hairline'
|
||||
: ''} {klass}"
|
||||
transition:pop|global
|
||||
class="glass-panel rounded-panel p-1.5 {border ? 'border border-hairline' : ''} {klass}"
|
||||
{style}
|
||||
>
|
||||
{@render children()}
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
import X from '@lucide/svelte/icons/x';
|
||||
import IconButton from '../primitives/IconButton.svelte';
|
||||
import { fade } from 'svelte/transition';
|
||||
import { expoOut } from 'svelte/easing';
|
||||
import type { TransitionConfig } from 'svelte/transition';
|
||||
import { pop } from '$lib/utils/transitions';
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
@@ -48,15 +47,6 @@
|
||||
);
|
||||
}
|
||||
|
||||
function pop(node: Element, { duration = 200 }: { duration?: number } = {}): TransitionConfig {
|
||||
return {
|
||||
duration,
|
||||
easing: expoOut,
|
||||
css: (t) =>
|
||||
`opacity: ${t}; transform: scale(${0.98 + 0.02 * t}) translateY(${0.25 * (1 - t)}rem);`
|
||||
};
|
||||
}
|
||||
|
||||
function onWindowKeydown(event: KeyboardEvent) {
|
||||
if (!open) return;
|
||||
if (event.key === 'Escape') {
|
||||
|
||||
Reference in New Issue
Block a user