-
Notifications
You must be signed in to change notification settings - Fork 0
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
2209fac
commit 5e719ac
Showing
14 changed files
with
338 additions
and
38 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
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
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,55 @@ | ||
<script lang="ts"> | ||
import { | ||
createDialog, | ||
createSync, | ||
melt, | ||
type AnyMeltElement, | ||
type CreateDialogProps | ||
} from '@melt-ui/svelte' | ||
import { ModalContext, type ModalContextData } from '$lib/components/modal/context' | ||
import { setContext, type Snippet } from 'svelte' | ||
import ModalOverlay from './ModalOverlay.svelte' | ||
import ModalPopup from './ModalPopup.svelte' | ||
interface Props { | ||
trigger?: Snippet<[{ trigger: ModalContextData['elements']['trigger'] }]> | ||
children?: Snippet<[{ close: () => void }]> | ||
options?: Omit<CreateDialogProps, 'forceVisible'> | ||
open?: boolean | ||
} | ||
let { trigger, options = {}, children, open = $bindable(false) }: Props = $props() | ||
const modal = createDialog({ | ||
forceVisible: true, | ||
...options | ||
}) | ||
setContext(ModalContext, modal) | ||
const { | ||
elements: { trigger: triggerEl, portalled, overlay } | ||
} = modal | ||
const sync = createSync(modal.states) | ||
$effect(() => { | ||
sync.open(open, (v) => (open = v)) | ||
}) | ||
</script> | ||
|
||
{@render trigger?.({ trigger: triggerEl })} | ||
|
||
{#if open} | ||
<div use:melt={$portalled}> | ||
<ModalOverlay> | ||
<ModalPopup> | ||
{@render children?.({ | ||
close: () => { | ||
open = false | ||
} | ||
})} | ||
</ModalPopup> | ||
</ModalOverlay> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script lang="ts"> | ||
import type { Snippet } from 'svelte' | ||
interface Props { | ||
left?: Snippet | ||
right?: Snippet | ||
} | ||
const { left, right }: Props = $props() | ||
</script> | ||
|
||
<div class="actions"> | ||
{@render left?.()} | ||
<div class="spacer"></div> | ||
{@render right?.()} | ||
</div> | ||
|
||
<style lang="scss"> | ||
.actions { | ||
display: flex; | ||
gap: 12px; | ||
} | ||
.spacer { | ||
flex-grow: 1; | ||
} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script lang="ts"> | ||
import { melt } from '@melt-ui/svelte' | ||
import { ModalContext, type ModalContextData } from '$lib/components/modal/context' | ||
import { getContext, type Snippet } from 'svelte' | ||
import { fade, fly } from 'svelte/transition' | ||
interface Props { | ||
children?: Snippet | ||
} | ||
let { children }: Props = $props() | ||
const { | ||
elements: { overlay } | ||
} = getContext<ModalContextData>(ModalContext) | ||
</script> | ||
|
||
<div class="modal-overlay"> | ||
<div class="backdrop" use:melt={$overlay} transition:fade={{ duration: 150 }}></div> | ||
<div class="content" transition:fly={{ duration: 400, y: 48, opacity: 0 }}> | ||
{@render children?.()} | ||
</div> | ||
</div> | ||
|
||
<style lang="scss"> | ||
.modal-overlay { | ||
position: fixed; | ||
z-index: 100; | ||
inset: 0; | ||
} | ||
.content { | ||
position: fixed; | ||
inset: 0; | ||
display: flex; | ||
justify-content: center; | ||
pointer-events: none; | ||
} | ||
.backdrop { | ||
position: fixed; | ||
inset: 0; | ||
background-color: rgba(0, 0, 0, 0.3); | ||
} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<script lang="ts"> | ||
import { getContext, type Snippet } from 'svelte' | ||
import { ModalContext, type ModalContextData } from './context' | ||
import { melt } from '@melt-ui/svelte' | ||
interface Props { | ||
children?: Snippet | ||
} | ||
const { children }: Props = $props() | ||
const { | ||
elements: { content } | ||
} = getContext<ModalContextData>(ModalContext) | ||
</script> | ||
|
||
<div class="modal-popup" use:melt={$content}> | ||
{@render children?.()} | ||
</div> | ||
|
||
<style lang="scss"> | ||
@use '../../stylesheets/system/colors' as *; | ||
@use '../../stylesheets/system/breakpoints' as *; | ||
.modal-popup { | ||
background-color: $darkblue; | ||
padding: 32px; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 24px; | ||
pointer-events: all; | ||
width: 100%; | ||
max-height: calc(100% - 64px); | ||
overflow-y: auto; | ||
align-self: flex-end; | ||
border-radius: 12px 12px 0 0; | ||
@include breakpoint('sm') { | ||
border-radius: 12px; | ||
max-width: 564px; | ||
margin: 18px; | ||
align-self: center; | ||
} | ||
} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<script lang="ts"> | ||
import { getContext, type Snippet } from 'svelte' | ||
import { ModalContext, type ModalContextData } from './context' | ||
import { melt } from '@melt-ui/svelte' | ||
interface Props { | ||
children?: Snippet | ||
} | ||
const { children }: Props = $props() | ||
const { | ||
elements: { title } | ||
} = getContext<ModalContextData>(ModalContext) | ||
</script> | ||
|
||
<div use:melt={$title} class="title"> | ||
{@render children?.()} | ||
</div> | ||
|
||
<style lang="scss"> | ||
.title { | ||
font-size: 28px; | ||
line-height: 120%; | ||
font-weight: 500; | ||
text-align: center; | ||
} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import type { createDialog } from '@melt-ui/svelte' | ||
|
||
export const ModalContext = Symbol('modal context') | ||
export type ModalContextData = ReturnType<typeof createDialog> |
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
Oops, something went wrong.