migrate: convert most components to svelte 5
This commit is contained in:
1 parent
d670f39f0a
commit
10ef4123da
225 files changed
+5441
-3341
No files matched your search
@@ -7,27 +7,42 @@
|
||||
import { focusTrap } from 'svelte-focus-trap'
|
||||
import Portal from '../popover/Portal.svelte'
|
||||
|
||||
export let action: string | undefined = undefined
|
||||
export let open = false
|
||||
export let title: string | undefined = undefined
|
||||
export let dismissable: boolean = true
|
||||
interface Props {
|
||||
action?: string | undefined;
|
||||
open?: boolean;
|
||||
title?: string | undefined;
|
||||
dismissable?: boolean;
|
||||
customTitle?: import('svelte').Snippet;
|
||||
children?: import('svelte').Snippet;
|
||||
actions?: import('svelte').Snippet<[any]>;
|
||||
}
|
||||
|
||||
let el: any
|
||||
let {
|
||||
action = undefined,
|
||||
open = $bindable(false),
|
||||
title = undefined,
|
||||
dismissable = true,
|
||||
customTitle,
|
||||
children,
|
||||
actions
|
||||
}: Props = $props();
|
||||
|
||||
let el: any = $state()
|
||||
|
||||
const dispatcher = createEventDispatcher<{ action: any; dismissed: any }>()
|
||||
</script>
|
||||
|
||||
<Portal>
|
||||
{#if open}
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
||||
<div
|
||||
role="dialog"
|
||||
class="overflow-hidden fixed top-0 left-0 w-screen h-screen z-[100]
|
||||
flex flex-col items-center justify-center backdrop-blur-sm
|
||||
bg-white/50 dark:bg-black/50 box-border p-4"
|
||||
transition:fade|global={{ duration: 100 }}
|
||||
on:click={(e) => {
|
||||
onclick={(e) => {
|
||||
if (!el.contains(e.target)) {
|
||||
open = false
|
||||
|
||||
@@ -35,7 +50,7 @@ bg-white/50 dark:bg-black/50 box-border p-4"
|
||||
}
|
||||
}}
|
||||
>
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
bind:this={el}
|
||||
use:focusTrap
|
||||
@@ -60,20 +75,22 @@ bg-white/50 dark:bg-black/50 box-border p-4"
|
||||
dispatcher('dismissed')
|
||||
}}
|
||||
>
|
||||
<Icon src={XMark} size="20" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={XMark} size="20" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
<h1 class="font-semibold text-xl max-w-full">
|
||||
{#if $$slots.title}
|
||||
<slot name="title" />
|
||||
{#if customTitle}
|
||||
{@render customTitle?.()}
|
||||
{:else if title}
|
||||
{title}
|
||||
{/if}
|
||||
</h1>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
{#if action}
|
||||
<div class="mt-2 flex w-full">
|
||||
<slot name="action" {action}>
|
||||
{#if actions}{@render actions({ action, })}{:else}
|
||||
<Button
|
||||
class="w-full"
|
||||
on:click={(e) => {
|
||||
@@ -87,7 +104,7 @@ bg-white/50 dark:bg-black/50 box-border p-4"
|
||||
>
|
||||
{action}
|
||||
</Button>
|
||||
</slot>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy';
|
||||
|
||||
import Button from '../button/Button.svelte'
|
||||
import Modal from '../modal/Modal.svelte'
|
||||
import { Icon } from 'svelte-hero-icons'
|
||||
import { shownModal } from './modal.js'
|
||||
|
||||
let open = false
|
||||
let open = $state(false)
|
||||
|
||||
// reactivity hack
|
||||
$: open = $shownModal ? true : false
|
||||
run(() => {
|
||||
open = $shownModal ? true : false
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if $shownModal}
|
||||
|
||||
Reference in new issue
Block a user