impr: merge mono-ui with photon (#455)

This commit is contained in:
Xylight authored and GitHub committed 2024-09-24 19:33:52 -07:00
1 parent 16075f72f2
commit 180d6fcc0d
40 files changed
+2024 -1

No files matched your search

+96
View File
@@ -0,0 +1,96 @@
<script lang="ts">
import { Button } from '../index.js'
import { createEventDispatcher } from 'svelte'
import { Icon, XMark } from 'svelte-hero-icons'
import { backOut, expoOut } from 'svelte/easing'
import { fade, scale } from 'svelte/transition'
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
let el: any
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 -->
<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) => {
if (!el.contains(e.target)) {
open = false
dispatcher('dismissed')
}
}}
>
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
bind:this={el}
use:focusTrap
transition:scale|global={{
start: 0.95,
easing: backOut,
duration: 300,
}}
class="w-full border border-slate-200 border-b-slate-300
dark:border-zinc-900 dark:border-t-zinc-800 dark:border-b-zinc-900
rounded-2xl max-w-lg box-border mx-auto overscroll-contain shadow-lg overflow-auto
p-5 flex flex-col gap-2 dark:bg-zinc-950 dark:bg-zinc-925
bg-white relative"
>
{#if dismissable}
<Button
class="absolute top-0 right-0 m-2 text-slate-600 dark:text-zinc-400"
color="tertiary"
size="square-sm"
on:click={() => {
open = false
dispatcher('dismissed')
}}
>
<Icon src={XMark} size="20" mini slot="prefix" />
</Button>
{/if}
<h1 class="font-semibold text-xl max-w-full">
{#if $$slots.title}
<slot name="title" />
{:else if title}
{title}
{/if}
</h1>
<slot />
{#if action}
<div class="mt-2 flex w-full">
<slot name="action" {action}>
<Button
class="w-full"
on:click={(e) => {
dispatcher('action', e)
open = false
dispatcher('dismissed')
}}
color="primary"
size="lg"
rounding="xl"
>
{action}
</Button>
</slot>
</div>
{/if}
</div>
</div>
{/if}
</Portal>
+43
View File
@@ -0,0 +1,43 @@
<script lang="ts">
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
// reactivity hack
$: open = $shownModal ? true : false
</script>
{#if $shownModal}
<Modal
title={$shownModal.title}
dismissable={$shownModal.dismissable}
on:dismissed={() => shownModal.set(undefined)}
bind:open
>
<p>{$shownModal.body}</p>
{#if $shownModal.actions}
<div
class="flex items-center gap-2 {$shownModal.actions.length >= 3
? 'flex-col'
: 'flex-row'}"
>
{#each $shownModal.actions as action}
<Button
size="lg"
class="flex-1 w-full"
on:click={action.action}
color={action.type}
>
{#if action.icon}
<Icon src={action.icon} mini size="16" slot="prefix" />
{/if}
{action.content}
</Button>
{/each}
</div>
{/if}
</Modal>
{/if}
+65
View File
@@ -0,0 +1,65 @@
import type { IconSource } from 'svelte-hero-icons'
import { writable } from 'svelte/store'
export let shownModal = writable<Modal | undefined>(undefined)
interface Modal {
actions: Action[]
title: string
body?: string
/**
* Whether the modal has a close button or not
*/
dismissable: boolean
type: 'error' | 'info' | 'success'
}
type Action = {
/**
* What function to run when this action is clicked. If undefined, it'll close the window.
*/
action: () => any
type: 'danger' | 'secondary' | 'primary'
content: string
icon?: IconSource
close: boolean
}
export const action = (action?: {
action?: () => any
type?: 'danger' | 'secondary' | 'primary'
content?: string
icon?: IconSource
close?: boolean
}): Action => ({
action: action?.action
? () => {
action?.action?.()
if (action.close) shownModal.set(undefined)
}
: () => shownModal.set(undefined),
type: action?.type ?? 'secondary',
content: action?.content || 'OK',
close: action?.close ?? true
})
export function modal(inputModal: {
actions?: Action[]
title: string
body: string
/**
* Whether the modal has a close button or not
*/
dismissable?: boolean
type?: 'error' | 'info' | 'success'
}) {
const modal: Modal = {
actions: inputModal.actions ?? [action()],
dismissable: inputModal.dismissable ?? true,
title: inputModal.title,
body: inputModal.body,
type: inputModal.type ?? 'info'
}
shownModal.set(modal)
}