-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3b5788
commit 9c2aec3
Showing
7 changed files
with
132 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<script lang="ts"> | ||
import type { Snippet } from "svelte"; | ||
import Button from "./Button.svelte"; | ||
import Icon from "./Icon.svelte"; | ||
interface Props { | ||
title: string; | ||
children: Snippet; | ||
} | ||
let { title, children } = $props<Props>(); | ||
let dialog = $state<HTMLDialogElement>(); | ||
export function show() { | ||
dialog?.showModal(); | ||
} | ||
export function hide() { | ||
dialog?.close(); | ||
} | ||
</script> | ||
|
||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions a11y-click-events-have-key-events --> | ||
<dialog | ||
class="modal" | ||
bind:this={dialog} | ||
onclick={evt => { | ||
if (evt.currentTarget.tagName !== "DIALOG") return; | ||
|
||
const rect = dialog?.getBoundingClientRect(); | ||
if (!rect) return; | ||
|
||
const isInDialog = | ||
rect.top <= evt.clientY && | ||
evt.clientY <= rect.top + rect.height && | ||
rect.left <= evt.clientX && | ||
evt.clientX <= rect.left + rect.width; | ||
if (!isInDialog) dialog?.close(); | ||
}} | ||
> | ||
<header class="header"> | ||
<span class="title">{title}</span> | ||
<Button onclick={() => dialog?.close()}><Icon name="close" /></Button> | ||
</header> | ||
<div class="content"> | ||
{@render children()} | ||
</div> | ||
</dialog> | ||
|
||
<style> | ||
.modal { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
translate: -50% -50%; | ||
border-radius: 16px; | ||
border: none; | ||
} | ||
::backdrop { | ||
background-color: #00000099; | ||
} | ||
.header { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 16px; | ||
box-shadow: 0 1px 0 #00000022; | ||
} | ||
.title { | ||
font-weight: 700; | ||
font-size: 1.25rem; | ||
} | ||
.content { | ||
padding: 16px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters