-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): add simple modal component
Signed-off-by: Jordan Shatford <[email protected]>
- Loading branch information
1 parent
e5da767
commit 0c5ca0e
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
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,51 @@ | ||
<script lang="ts"> | ||
import { tv } from 'tailwind-variants'; | ||
import { fly, fade } from 'svelte/transition'; | ||
const modalClasses = tv({ | ||
slots: { | ||
outerDivClass: 'fixed inset-0 z-50 overflow-y-auto', | ||
backgroundOuterDivClass: | ||
'flex min-h-screen items-end justify-center px-4 pb-20 pt-4 text-center sm:block sm:p-0', | ||
backgroundTransitionDivClass: | ||
'fixed inset-0 cursor-pointer bg-zinc-800 bg-opacity-75 transition-opacity', | ||
trickCenteringSpanClass: 'hidden sm:inline-block sm:h-screen sm:align-middle', | ||
contentDivClass: | ||
'inline-block transform overflow-hidden rounded-lg bg-white text-left align-bottom shadow-xl transition-all dark:bg-zinc-900 sm:my-8 sm:w-full sm:max-w-lg sm:align-middle' | ||
} | ||
}); | ||
export let show: boolean = false; | ||
const { | ||
outerDivClass, | ||
backgroundOuterDivClass, | ||
backgroundTransitionDivClass, | ||
trickCenteringSpanClass, | ||
contentDivClass | ||
} = modalClasses(); | ||
</script> | ||
|
||
{#if show} | ||
<div class={outerDivClass()} aria-labelledby="modal-title" role="dialog" aria-modal="true"> | ||
<div class={backgroundOuterDivClass()}> | ||
<div | ||
class={backgroundTransitionDivClass()} | ||
aria-hidden="true" | ||
on:click={() => (show = false)} | ||
in:fade={{ duration: 300 }} | ||
out:fade={{ delay: 200, duration: 200 }} | ||
/> | ||
<!-- This element is to trick the browser into centering the modal contents. --> | ||
<span class={trickCenteringSpanClass()} aria-hidden="true">​</span> | ||
<div | ||
{...$$restProps} | ||
class={contentDivClass({ class: $$props.class })} | ||
in:fly={{ y: -10, delay: 200, duration: 200 }} | ||
out:fly={{ y: -10, duration: 200 }} | ||
> | ||
<slot /> | ||
</div> | ||
</div> | ||
</div> | ||
{/if} |
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