impr: merge mono-ui with photon (#455)
This commit is contained in:
1 parent
16075f72f2
commit
180d6fcc0d
40 files changed
+2024
-1
No files matched your search
@@ -0,0 +1,52 @@
|
||||
<script lang="ts">
|
||||
export let label: string = ''
|
||||
|
||||
const badgeColor = {
|
||||
red: 'bg-red-500 text-white ring-transparent',
|
||||
green: 'bg-green-500 text-white dark:text-black ring-transparent',
|
||||
yellow: 'bg-yellow-500 text-black ring-transparent',
|
||||
gray: 'bg-gray-600 text-white ring-transparent',
|
||||
blue: 'bg-blue-500 text-white ring-transparent',
|
||||
purple: 'bg-purple-500 text-white ring-transparent',
|
||||
'red-subtle': `bg-red-100 dark:bg-red-500/20 text-red-600 dark:text-red-400
|
||||
ring-red-400 dark:ring-red-500/30`,
|
||||
'green-subtle': `bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400
|
||||
ring-green-400 dark:ring-green-500/30`,
|
||||
'yellow-subtle': `bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400
|
||||
ring-yellow-400 dark:ring-yellow-500/30`,
|
||||
'gray-subtle': `bg-gray-100 dark:bg-gray-500/20 text-gray-700 dark:text-gray-300
|
||||
ring-gray-400 dark:ring-gray-400/30`,
|
||||
'blue-subtle': `bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300
|
||||
ring-blue-400 dark:ring-blue-400/30`,
|
||||
'purple-subtle': `bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400
|
||||
ring-purple-400 dark:ring-purple-500/30`,
|
||||
custom: ''
|
||||
}
|
||||
|
||||
const badgeRoundness = {
|
||||
full: 'rounded-full',
|
||||
md: 'rounded-md',
|
||||
custom: ''
|
||||
}
|
||||
|
||||
type BadgeColor = keyof typeof badgeColor
|
||||
type BadgeRoundness = keyof typeof badgeRoundness
|
||||
|
||||
export let color: BadgeColor = 'gray-subtle'
|
||||
export let rounding: BadgeRoundness = 'full'
|
||||
export let allowIconOnly: boolean = false
|
||||
</script>
|
||||
|
||||
<span
|
||||
class="{allowIconOnly ? 'max-md:px-1.5 max-md:py-1.5' : ''} px-2.5 py-1 {badgeRoundness[
|
||||
rounding
|
||||
]} text-xs font-medium flex items-center gap-1 ring-1 ring-inset {badgeColor[
|
||||
color
|
||||
]} {$$props.class}"
|
||||
title={label}
|
||||
>
|
||||
<slot name="icon" />
|
||||
<span class={allowIconOnly ? 'hidden md:contents' : 'contents'}>
|
||||
<slot />
|
||||
</span>
|
||||
</span>
|
||||
@@ -0,0 +1,183 @@
|
||||
<script context="module" lang="ts">
|
||||
export type ButtonColor = keyof typeof buttonColor
|
||||
export type ButtonAlignment = keyof typeof buttonAlignment
|
||||
export type ButtonShadow = keyof typeof buttonShadow
|
||||
|
||||
export const buttonAlignment = {
|
||||
left: 'justify-start text-left',
|
||||
center: 'justify-center text-center',
|
||||
right: 'justify-end text-right'
|
||||
}
|
||||
|
||||
export const buttonColor = {
|
||||
primary: `border border-transparent bg-primary-900 text-white
|
||||
dark:bg-primary-100 dark:text-black hover:brightness-125 dark:hover:brightness-90 active:brightness-90
|
||||
active:dark:brightness-75`,
|
||||
|
||||
secondary: `border border-slate-200 border-b-slate-300 dark:border-zinc-800 dark:border-t-zinc-700/70 bg-white dark:bg-zinc-900
|
||||
hover:bg-slate-100 hover:dark:bg-zinc-800 hover:dark:border-zinc-700 hover:dark:border-zinc-700 active:dark:bg-zinc-900 active:bg-slate-200`,
|
||||
|
||||
tertiary:
|
||||
'border border-transparent bg-transparent hover:bg-slate-100 hover:dark:bg-zinc-800 dark:text-zinc-200',
|
||||
|
||||
danger: 'border border-red-500 bg-red-500 hover:text-red-500 hover:bg-transparent text-white',
|
||||
'danger-subtle': 'text-red-500 hover:bg-red-500 hover:!text-inherit',
|
||||
|
||||
'success-subtle': 'text-green-500 hover:bg-green-500 hover:!text-inherit',
|
||||
|
||||
'warning-subtle': 'text-yellow-500 hover:bg-yellow-500 hover:!text-inherit',
|
||||
|
||||
ghost: `border border-slate-200 dark:border-zinc-800 bg-transparent
|
||||
hover:bg-slate-100 hover:dark:bg-zinc-800 hover:dark:border-zinc-700 dark:text-zinc-400 hover:text-inherit
|
||||
hover:dark:text-inherit`,
|
||||
|
||||
elevated: `bg-slate-100 dark:bg-zinc-800 border border-slate-200
|
||||
dark:border-zinc-700 hover:bg-zinc-200 hover:dark:bg-zinc-700 hover:border-slate-300
|
||||
hover:dark:border-zinc-600`,
|
||||
|
||||
elevatedLow: `bg-slate-100 dark:bg-zinc-900 border border-slate-200
|
||||
dark:border-zinc-800 hover:bg-slate-200 hover:dark:bg-zinc-800 hover:border-slate-300
|
||||
hover:dark:border-zinc-700`,
|
||||
|
||||
none: ''
|
||||
}
|
||||
|
||||
export const buttonShadow = {
|
||||
sm: 'shadow-sm',
|
||||
none: 'shadow-none'
|
||||
}
|
||||
|
||||
export type ButtonSize = keyof typeof buttonSize
|
||||
|
||||
export const buttonSize = {
|
||||
sm: 'px-2 py-1',
|
||||
md: 'px-3 py-1.5',
|
||||
lg: 'px-4 py-2',
|
||||
xl: 'px-6 py-3',
|
||||
'square-sm': 'w-6 h-6',
|
||||
'square-md': 'w-8 h-8',
|
||||
'square-lg': 'w-10 h-10',
|
||||
'square-xl': 'w-12 h-12',
|
||||
custom: ''
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import Spinner from '../loader/Spinner.svelte'
|
||||
|
||||
type ButtonRoundness = 'pill' | 'xl' | 'lg' | 'md' | 'none'
|
||||
type ButtonRoundingSide = 'all' | 'left' | 'right' | 'top' | 'bottom'
|
||||
|
||||
const buttonRounding = {
|
||||
pill: {
|
||||
all: 'rounded-full',
|
||||
left: 'rounded-l-full',
|
||||
right: 'rounded-r-full',
|
||||
top: 'rounded-t-full',
|
||||
bottom: 'rounded-b-full'
|
||||
},
|
||||
|
||||
xl: {
|
||||
all: 'rounded-xl',
|
||||
left: 'rounded-l-xl',
|
||||
right: 'rounded-r-xl',
|
||||
top: 'rounded-t-xl',
|
||||
bottom: 'rounded-b-xl'
|
||||
},
|
||||
|
||||
lg: {
|
||||
all: 'rounded-lg',
|
||||
left: 'rounded-l-lg',
|
||||
right: 'rounded-r-lg',
|
||||
top: 'rounded-t-lg',
|
||||
bottom: 'rounded-b-lg'
|
||||
},
|
||||
|
||||
md: {
|
||||
all: 'rounded-md',
|
||||
left: 'rounded-l-md',
|
||||
right: 'rounded-r-md',
|
||||
top: 'rounded-t-md',
|
||||
bottom: 'rounded-b-md'
|
||||
},
|
||||
|
||||
none: {
|
||||
all: '',
|
||||
left: '',
|
||||
right: '',
|
||||
top: '',
|
||||
bottom: ''
|
||||
}
|
||||
}
|
||||
|
||||
export let loading = false
|
||||
export let submit = false
|
||||
|
||||
export let color: ButtonColor = 'secondary'
|
||||
export let size: ButtonSize = 'md'
|
||||
export let rounding: ButtonRoundness = size == 'lg' ? 'xl' : 'lg'
|
||||
export let roundingSide: ButtonRoundingSide = 'all'
|
||||
export let alignment: ButtonAlignment = 'center'
|
||||
export let shadow: ButtonShadow = 'none'
|
||||
export let column: boolean = false
|
||||
|
||||
export let loaderWidth: number | undefined = undefined
|
||||
|
||||
export let href: string | undefined = undefined
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={href ? 'a' : 'button'}
|
||||
role={href ? 'link' : 'button'}
|
||||
{href}
|
||||
{...$$restProps}
|
||||
on:click
|
||||
on:contextmenu
|
||||
on:drag
|
||||
on:drop
|
||||
on:dragstart
|
||||
on:dragend
|
||||
class="
|
||||
{buttonColor[color]}
|
||||
{buttonSize[size]}
|
||||
{buttonRounding[rounding][roundingSide]}
|
||||
{buttonShadow[shadow]}
|
||||
text-sm transition-all disabled:!opacity-70 disabled:!pointer-events-none
|
||||
disabled:!border disabled:!border-slate-300 disabled:!bg-slate-200
|
||||
disabled:dark:!border-zinc-700 disabled:dark:!bg-zinc-800 disabled:text-inherit
|
||||
font-medium cursor-pointer
|
||||
{$$props.class}
|
||||
{loading ? (color == 'primary' ? '!bg-transparent !text-inherit' : '') : ''}"
|
||||
type={submit ? 'submit' : 'button'}
|
||||
>
|
||||
<div
|
||||
class="flex {column
|
||||
? 'flex-col justify-center'
|
||||
: 'flex-row items-center'} h-full gap-1.5 {buttonAlignment[alignment]}"
|
||||
>
|
||||
{#if loading}
|
||||
<Spinner
|
||||
width={loaderWidth
|
||||
? loaderWidth
|
||||
: size == 'lg'
|
||||
? 18
|
||||
: size == 'md'
|
||||
? 16
|
||||
: size == 'sm'
|
||||
? 14
|
||||
: 14}
|
||||
/>
|
||||
{:else if $$slots.prefix}
|
||||
<slot name="prefix" />
|
||||
{/if}
|
||||
<slot />
|
||||
<slot name="suffix" />
|
||||
</div>
|
||||
</svelte:element>
|
||||
|
||||
<!--
|
||||
@component
|
||||
|
||||
@slot `prefix` -- Will be replaced if `loading` is `true`.
|
||||
@slot `suffix`
|
||||
-->
|
||||
@@ -0,0 +1,76 @@
|
||||
<script lang="ts">
|
||||
import Button from '../button/Button.svelte'
|
||||
import Material from '../materials/Material.svelte'
|
||||
import { Check, Icon, Clipboard } from 'svelte-hero-icons'
|
||||
import { scale } from 'svelte/transition'
|
||||
|
||||
export let src: string
|
||||
export let filename: string | undefined = undefined
|
||||
export let htmlSrc: string | undefined = undefined
|
||||
|
||||
let copied = false
|
||||
|
||||
let pre: HTMLPreElement
|
||||
|
||||
const copy = () => {
|
||||
if ($$slots.default) {
|
||||
if (pre) navigator.clipboard.writeText(pre.innerText)
|
||||
} else if (src) {
|
||||
navigator.clipboard.writeText(src)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Material
|
||||
class="overflow-hidden flex flex-col divide-y divide-slate-200 dark:divide-zinc-800"
|
||||
padding="none"
|
||||
rounding="md"
|
||||
>
|
||||
{#if filename}
|
||||
<div class="flex flex-row items-center justify-between p-3 px-4 text-xs">
|
||||
<span>
|
||||
{filename}
|
||||
</span>
|
||||
<Button
|
||||
size="square-sm"
|
||||
color="tertiary"
|
||||
aria-label="Copy"
|
||||
on:click={() => {
|
||||
copied = true
|
||||
copy()
|
||||
setTimeout(() => (copied = false), 2000)
|
||||
}}
|
||||
>
|
||||
<div class="relative w-full h-full grid place-items-center">
|
||||
{#if !copied}
|
||||
<div
|
||||
transition:scale={{ opacity: 0, start: 0.3 }}
|
||||
style="grid-row: 1; grid-column: 1;"
|
||||
>
|
||||
<Icon src={Clipboard} size="16" slot="prefix" />
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
transition:scale={{ opacity: 0, start: 0.3 }}
|
||||
style="grid-row: 1; grid-column: 1;"
|
||||
>
|
||||
<Icon src={Check} size="16" mini slot="prefix" />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
<pre
|
||||
bind:this={pre}
|
||||
{...$$restProps}
|
||||
class="{$$props.class} bg-white dark:bg-zinc-900 px-4 overflow-auto max-h-96">
|
||||
{#if htmlSrc}
|
||||
{@html htmlSrc}
|
||||
{:else if $$slots.default}
|
||||
<slot />
|
||||
{:else if src}
|
||||
{src}
|
||||
{/if}
|
||||
</pre>
|
||||
</Material>
|
||||
@@ -0,0 +1,54 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '../index.js'
|
||||
import { Check, Icon, Clipboard } from 'svelte-hero-icons'
|
||||
import { scale } from 'svelte/transition'
|
||||
|
||||
/**
|
||||
* Show a copy button.
|
||||
*/
|
||||
export let value: string
|
||||
export let copy: boolean = true
|
||||
|
||||
let copied = false
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="px-4 py-1 flex justify-between max-w-full box-border bg-slate-100 dark:bg-zinc-950 items-center gap-4 rounded-md border dark:border-zinc-800
|
||||
{$$props.class}"
|
||||
>
|
||||
<pre class="overflow-auto max-w-full whitespace-nowrap w-max">
|
||||
{value}
|
||||
</pre>
|
||||
{#if copy}
|
||||
<Button
|
||||
size="square-md"
|
||||
color="tertiary"
|
||||
aria-label="Copy"
|
||||
on:click={() => {
|
||||
copied = true
|
||||
navigator.clipboard.writeText(value)
|
||||
setTimeout(() => (copied = false), 2000)
|
||||
}}
|
||||
>
|
||||
<div class="relative w-full h-full grid place-items-center">
|
||||
{#if !copied}
|
||||
<div
|
||||
transition:scale={{ opacity: 0, start: 0.3 }}
|
||||
class="top-0 left-0"
|
||||
style="grid-row: 1; grid-column: 1;"
|
||||
>
|
||||
<Icon src={Clipboard} size="18" mini slot="prefix" />
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
transition:scale={{ opacity: 0, start: 0.3 }}
|
||||
class="top-0 left-0"
|
||||
style="grid-row: 1; grid-column: 1;"
|
||||
>
|
||||
<Icon src={Check} size="18" mini slot="prefix" />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { backOut, expoOut } from 'svelte/easing'
|
||||
import { slide } from 'svelte/transition'
|
||||
|
||||
export let open: boolean = false
|
||||
</script>
|
||||
|
||||
<div {...$$restProps} class={$$props.class}>
|
||||
<button on:click={() => (open = !open)} class="w-full">
|
||||
<slot name="summary" {open} />
|
||||
</button>
|
||||
{#if open}
|
||||
<div transition:slide={{ axis: 'y', easing: expoOut, duration: 300 }}>
|
||||
<slot {open} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,15 @@
|
||||
<script lang="ts">
|
||||
export let defaultValue: boolean = false
|
||||
export let checked: boolean | undefined = defaultValue
|
||||
export let inlineDescription: boolean = false
|
||||
</script>
|
||||
|
||||
<label class="font-normal cursor-pointer text-sm flex flex-row items-baseline gap-2">
|
||||
<input type="checkbox" bind:checked class="cursor-pointer" />
|
||||
<div class="inline-flex {inlineDescription ? 'flex-row' : 'flex-col'} font-medium gap-1">
|
||||
<slot />
|
||||
{#if $$slots.description}
|
||||
<span class="font-normal text-slate-600 dark:text-zinc-400"><slot name="description" /></span>
|
||||
{/if}
|
||||
</div>
|
||||
</label>
|
||||
@@ -0,0 +1,74 @@
|
||||
<script lang="ts">
|
||||
import { generateID } from '../forms/helper.js'
|
||||
import Material from '../materials/Material.svelte'
|
||||
|
||||
type T = $$Generic
|
||||
|
||||
export let value: T | undefined = undefined
|
||||
export let group: T | undefined = undefined
|
||||
export let id: string = generateID()
|
||||
export let disabled: boolean = false
|
||||
export let title: string | undefined = undefined
|
||||
export let description: string | undefined = undefined
|
||||
export let type: 'radio' | 'checkbox' = 'radio'
|
||||
export let checked: boolean | undefined = undefined
|
||||
|
||||
// prettier-ignore
|
||||
$: selected = type == 'checkbox' ? checked
|
||||
: group != undefined
|
||||
? group == value : false
|
||||
</script>
|
||||
|
||||
<Material
|
||||
class="transition-colors duration-100
|
||||
{selected ? 'bg-blue-200 dark:bg-blue-950 border-blue-400' : ''}"
|
||||
>
|
||||
<label
|
||||
for={id}
|
||||
class="w-full h-full flex flex-row-reverse cursor-pointer items-center gap-4"
|
||||
>
|
||||
{#if type == 'radio'}
|
||||
<input
|
||||
{...$$restProps}
|
||||
{id}
|
||||
type="radio"
|
||||
{value}
|
||||
on:blur
|
||||
bind:group
|
||||
{disabled}
|
||||
class="h-max w-max peer pr-4"
|
||||
/>
|
||||
{:else if type == 'checkbox'}
|
||||
<input
|
||||
{...$$restProps}
|
||||
{id}
|
||||
type="checkbox"
|
||||
{value}
|
||||
on:blur
|
||||
bind:checked
|
||||
{disabled}
|
||||
class="h-max w-max peer pr-4"
|
||||
/>
|
||||
{/if}
|
||||
<div class="flex flex-col space-y-1 w-full h-full">
|
||||
{#if $$slots.title || title}
|
||||
<h1 class="font-medium">
|
||||
{#if $$slots.title}
|
||||
<slot name="title" />
|
||||
{:else if title}
|
||||
{title}
|
||||
{/if}
|
||||
</h1>
|
||||
{/if}
|
||||
{#if $$slots.description || description}
|
||||
<p class="text-sm text-slate-600 dark:text-zinc-400">
|
||||
{#if $$slots.description}
|
||||
<slot name="description" />
|
||||
{:else if description}
|
||||
{description}
|
||||
{/if}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
</label>
|
||||
</Material>
|
||||
@@ -0,0 +1,16 @@
|
||||
<script lang="ts">
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
export let group: string = generateID()
|
||||
export let row: boolean = true
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1 max-w-full">
|
||||
<div
|
||||
class="flex {row
|
||||
? 'flex-row flex-wrap'
|
||||
: 'flex-col'} gap-4 {$$props.class || ''}"
|
||||
>
|
||||
<slot {group} />
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,64 @@
|
||||
<script lang="ts">
|
||||
import Button from '../button/Button.svelte'
|
||||
import { generateID } from '../forms/helper.js'
|
||||
import { Label } from '../index.js'
|
||||
import { Icon, PaperClip } from 'svelte-hero-icons'
|
||||
|
||||
export let accept: string = '*'
|
||||
export let id: string = generateID()
|
||||
export let files: FileList | null = null
|
||||
export let multiple: boolean = false
|
||||
export let preview: boolean = true
|
||||
export let label: string | undefined = undefined
|
||||
|
||||
$: previewURLs =
|
||||
preview && files ? Array.from(files).map(URL.createObjectURL) : undefined
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1 {$$props.class}">
|
||||
{#if $$slots.label || label}
|
||||
<Label for={id} text={label}>
|
||||
<slot name="label" />
|
||||
</Label>
|
||||
{/if}
|
||||
<label
|
||||
class="w-max relative cursor-pointer space-x-2 flex flex-row items-center"
|
||||
>
|
||||
<slot name="button">
|
||||
<Button>Browse</Button>
|
||||
</slot>
|
||||
{#if previewURLs}
|
||||
<div
|
||||
class="flex flex-row items-center -space-x-1 hover:space-x-1 z-20 h-8"
|
||||
>
|
||||
{#each previewURLs as file}
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={file}
|
||||
on:load={() => URL.revokeObjectURL(file)}
|
||||
alt={file}
|
||||
class="w-8 h-8 object-cover rounded-full hover:w-16
|
||||
hover:h-16 transition-all border border-slate-200 ring-1
|
||||
ring-slate-50 dark:ring-zinc-950 bg-white dark:bg-zinc-950"
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<span class="flex flex-row items-center text-slate-600 dark:text-zinc-400">
|
||||
<slot name="choose">
|
||||
{#if (files ?? []).length == 0}
|
||||
No file selected.
|
||||
{:else}
|
||||
{(files ?? []).length} files selected
|
||||
{/if}
|
||||
</slot>
|
||||
</span>
|
||||
<input
|
||||
type="file"
|
||||
bind:files
|
||||
{accept}
|
||||
{multiple}
|
||||
class="w-full h-full inset-0 opacity-0 absolute cursor-pointer"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
@@ -0,0 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
|
||||
export let title: string | undefined
|
||||
|
||||
const dispatcher = createEventDispatcher<{ submit: SubmitEvent }>()
|
||||
</script>
|
||||
|
||||
<form
|
||||
on:submit={(e) => dispatcher('submit', e)}
|
||||
{...$$restProps}
|
||||
class="flex flex-col gap-4 {$$props.class}"
|
||||
>
|
||||
{#if title || $$slots.title}
|
||||
{#if $$slots.title}
|
||||
<slot name="title" />
|
||||
{:else if title}
|
||||
<h1 class="text-2xl font-bold">{title}</h1>
|
||||
{/if}
|
||||
{/if}
|
||||
<slot />
|
||||
</form>
|
||||
@@ -0,0 +1,62 @@
|
||||
<script lang="ts">
|
||||
import Label from '../forms/Label.svelte'
|
||||
import { generateID } from '../forms/helper.js'
|
||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||
import TextInput from './TextInput.svelte'
|
||||
|
||||
export let accept = 'image/*'
|
||||
export let files: FileList | undefined | null = null
|
||||
export let label: string | undefined = undefined
|
||||
export let id: string = generateID()
|
||||
export let url: string | undefined = undefined
|
||||
|
||||
let dragover = false
|
||||
|
||||
$: previewURL = files ? URL.createObjectURL(files[0]) : undefined
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col">
|
||||
{#if $$slots.label || label}
|
||||
<Label for={id} text={label} class="mb-1">
|
||||
<slot name="label" />
|
||||
</Label>
|
||||
{/if}
|
||||
<label
|
||||
class="flex flex-col items-center px-8 py-4 mx-auto w-full rounded-xl
|
||||
border border-slate-200 dark:border-zinc-800 bg-white dark:bg-black
|
||||
cursor-pointer min-h-36 transition-colors {dragover
|
||||
? 'border-sky-500 text-sky-500'
|
||||
: ''}
|
||||
{url != undefined ? 'rounded-b-none' : ''}
|
||||
"
|
||||
on:drop|preventDefault={(event) => (files = event.dataTransfer?.files)}
|
||||
on:dragover|preventDefault={(event) => {
|
||||
if (event.dataTransfer) {
|
||||
event.dataTransfer.dropEffect = 'copy'
|
||||
dragover = true
|
||||
}
|
||||
}}
|
||||
on:dragleave|preventDefault={() => (dragover = false)}
|
||||
>
|
||||
{#if files}
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={previewURL}
|
||||
on:load={() => {
|
||||
if (previewURL) URL.revokeObjectURL(previewURL)
|
||||
}}
|
||||
class="w-full max-w-sm h-full rounded-lg"
|
||||
/>
|
||||
{:else}
|
||||
<Icon src={DocumentPlus} class="opacity-50" size="36" />
|
||||
<p class="text-sm opacity-50">Attach a file</p>
|
||||
{/if}
|
||||
<input type="file" bind:files {accept} class="hidden" />
|
||||
</label>
|
||||
{#if url != undefined}
|
||||
<TextInput
|
||||
class="rounded-t-none border-t-0 rounded-xl"
|
||||
placeholder="https://example.com/img1.png"
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
let forID: string | undefined = undefined
|
||||
export { forID as for }
|
||||
/**
|
||||
* The `text` prop will take precedence over the slot.
|
||||
*/
|
||||
export let text: string | undefined = undefined
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={forID ? 'label' : 'span'}
|
||||
{...$$restProps}
|
||||
for={forID}
|
||||
class="text-sm text-slate-800 dark:text-zinc-200 font-medium w-full {$$props.class || ''}"
|
||||
>
|
||||
{#if text}
|
||||
{text}
|
||||
{:else if $$slots.default}
|
||||
<slot />
|
||||
{/if}
|
||||
</svelte:element>
|
||||
@@ -0,0 +1,40 @@
|
||||
<script lang="ts">
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
type T = $$Generic
|
||||
|
||||
export let value: T
|
||||
export let group: T
|
||||
export let inlineDescription: boolean = false
|
||||
export let id: string = generateID()
|
||||
export let disabled: boolean = false
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="font-normal cursor-pointer text-sm flex flex-row items-baseline gap-2"
|
||||
>
|
||||
<input
|
||||
{...$$restProps}
|
||||
{id}
|
||||
type="radio"
|
||||
bind:group
|
||||
{value}
|
||||
on:blur
|
||||
on:change
|
||||
{disabled}
|
||||
class="cursor-pointer disabled:cursor-not-allowed peer disabled:opacity-50"
|
||||
/>
|
||||
<label
|
||||
for={id}
|
||||
class="inline-flex {inlineDescription
|
||||
? 'flex-row'
|
||||
: 'flex-col'} cursor-pointer peer-disabled:cursor-not-allowed font-medium gap-1 peer-disabled:opacity-50"
|
||||
>
|
||||
<slot />
|
||||
{#if $$slots.description}
|
||||
<span class="font-normal text-slate-600 dark:text-zinc-400">
|
||||
<slot name="description" />
|
||||
</span>
|
||||
{/if}
|
||||
</label>
|
||||
</div>
|
||||
@@ -0,0 +1,16 @@
|
||||
<script lang="ts">
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
export let group: string = generateID()
|
||||
export let row: boolean = false
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
<div
|
||||
class="flex {row
|
||||
? 'flex-row flex-wrap'
|
||||
: 'flex-col'} gap-4 {$$props.class || ''}"
|
||||
>
|
||||
<slot {group} />
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,123 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
buttonColor,
|
||||
buttonSize,
|
||||
type ButtonShadow,
|
||||
type ButtonSize,
|
||||
buttonShadow,
|
||||
} from '../button/Button.svelte'
|
||||
import Label from '../forms/Label.svelte'
|
||||
import { generateID } from '../forms/helper.js'
|
||||
import Menu from '../popover/Menu.svelte'
|
||||
import MenuButton from '../popover/MenuButton.svelte'
|
||||
import Popover from '../popover/Popover.svelte'
|
||||
import { createEventDispatcher, onMount } from 'svelte'
|
||||
import {
|
||||
CheckCircle,
|
||||
ChevronDown,
|
||||
ChevronUpDown,
|
||||
Icon,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
type T = $$Generic
|
||||
|
||||
export let value: T | undefined = undefined
|
||||
export let placeholder: string | undefined = undefined
|
||||
export let label: string | undefined = undefined
|
||||
export let size: ButtonSize = 'md'
|
||||
export let shadow: ButtonShadow = 'none'
|
||||
|
||||
export let id: string = generateID()
|
||||
|
||||
let open = false
|
||||
let element: HTMLSelectElement
|
||||
|
||||
let options: { value: any; label: string | null; disabled: boolean }[] = []
|
||||
|
||||
// Capture all options from the select element
|
||||
$: options = element?.options
|
||||
? Array.from(element?.options).map((option) => ({
|
||||
value: option.value,
|
||||
label: option.innerHTML,
|
||||
disabled: option.disabled,
|
||||
}))
|
||||
: []
|
||||
|
||||
const dispatcher = createEventDispatcher<{
|
||||
change: any
|
||||
contextmenu: any
|
||||
input: any
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1 {$$props.class}">
|
||||
{#if $$slots.label || label}
|
||||
<Label for={id} text={label}>
|
||||
<slot name="label" />
|
||||
</Label>
|
||||
{/if}
|
||||
|
||||
<div class="w-full relative">
|
||||
<Menu bind:open>
|
||||
<select
|
||||
slot="target"
|
||||
{id}
|
||||
bind:this={element}
|
||||
class="{buttonSize[size]} {buttonShadow[
|
||||
shadow
|
||||
]} {buttonColor.secondary} appearance-none transition-colors rounded-lg text-sm
|
||||
w-full min-w-full cursor-pointer pr-6 {buttonColor.secondary}
|
||||
{$$props.class}"
|
||||
bind:value
|
||||
on:mousedown={(e) => {
|
||||
e.preventDefault()
|
||||
}}
|
||||
on:keypress={(e) => {
|
||||
e.preventDefault()
|
||||
open = !open
|
||||
}}
|
||||
on:change
|
||||
on:contextmenu
|
||||
{placeholder}
|
||||
>
|
||||
{#if placeholder}
|
||||
<option disabled selected value="">{placeholder}</option>
|
||||
{/if}
|
||||
<slot />
|
||||
</select>
|
||||
|
||||
{#each options as option}
|
||||
<slot name="option" {option} selected={option.value == value}>
|
||||
<MenuButton
|
||||
on:contextmenu={() => dispatcher('contextmenu')}
|
||||
on:click={() => {
|
||||
value = option.value
|
||||
dispatcher('change')
|
||||
}}
|
||||
size="custom"
|
||||
disabled={option.disabled}
|
||||
class="!min-h-0 !py-[5px] {option.value == value
|
||||
? '!bg-slate-100 dark:!bg-zinc-800'
|
||||
: ''}"
|
||||
>
|
||||
{@html option.label}
|
||||
{#if option.value == value}
|
||||
<Icon
|
||||
src={CheckCircle}
|
||||
size="16"
|
||||
micro
|
||||
class="text-primary-900 dark:text-primary-100 ml-auto"
|
||||
/>
|
||||
{/if}
|
||||
</MenuButton>
|
||||
</slot>
|
||||
{/each}
|
||||
</Menu>
|
||||
<Icon
|
||||
src={ChevronUpDown}
|
||||
mini
|
||||
size="16"
|
||||
class="absolute right-0 top-1/4 mx-2 box-border pointer-events-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,37 @@
|
||||
<script lang="ts">
|
||||
export let defaultValue: boolean = false
|
||||
export let checked: boolean = defaultValue
|
||||
</script>
|
||||
|
||||
<label class="font-normal cursor-pointer flex flex-row items-start gap-4 group {$$props.class}">
|
||||
<div
|
||||
class="w-11 h-6 rounded-full relative z-[inherit] cursor-pointer flex flex-row transition-colors shadow-sm
|
||||
{checked ? 'bg-primary-900 dark:bg-primary-100' : 'bg-slate-200 dark:bg-zinc-800'}
|
||||
p-0.5 flex-shrink-0"
|
||||
>
|
||||
<input
|
||||
bind:checked
|
||||
type="checkbox"
|
||||
class="peer appearance-none absolute top-0 left-0 w-full h-full cursor-pointer z-10"
|
||||
/>
|
||||
<div
|
||||
class="box-border w-5 h-full bg-white peer-checked:dark:bg-black rounded-full shadow-sm
|
||||
group-active:w-6 transition peer-checked:translate-x-5 group-active:peer-checked:translate-x-4
|
||||
rtl:peer-checked:-translate-x-5 rtl:group-active:peer-checked:-translate-x-4"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col {$$props.labelClass}">
|
||||
<slot />
|
||||
{#if $$slots.description}
|
||||
<span class="font-normal text-sm text-slate-700 dark:text-zinc-300">
|
||||
<slot name="description" />
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<style>
|
||||
.transition {
|
||||
transition: all 500ms cubic-bezier(0.075, 0.82, 0.165, 1);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,81 @@
|
||||
<script context="module" lang="ts">
|
||||
export type Size = keyof typeof sizeClass
|
||||
|
||||
export const sizeClass = {
|
||||
sm: 'p-3',
|
||||
md: 'p-4',
|
||||
lg: 'p-5',
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import Label from '../forms/Label.svelte'
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
export let label: string | undefined = undefined
|
||||
export let value: string = ''
|
||||
export let placeholder: string = ''
|
||||
export let disabled: boolean = false
|
||||
export let required: boolean = false
|
||||
export let size: Size = 'md'
|
||||
export let id: string = generateID()
|
||||
export let rows: number = 4
|
||||
|
||||
export let element: HTMLTextAreaElement | undefined = undefined
|
||||
|
||||
const borderClass = `
|
||||
border border-slate-200 dark:border-zinc-800
|
||||
`
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1 {$$props.class}">
|
||||
{#if $$slots.label || label}
|
||||
<Label
|
||||
for={id}
|
||||
text={label}
|
||||
class="peer-invalid:text-red-500 {required
|
||||
? "after:content-['*'] after:text-red-500 after:ml-1"
|
||||
: ''}"
|
||||
>
|
||||
<slot name="label" />
|
||||
</Label>
|
||||
{/if}
|
||||
<div
|
||||
class="rounded-xl flex flex-col items-center text-sm bg-white dark:bg-zinc-950 {$$props.class}"
|
||||
>
|
||||
<textarea
|
||||
{id}
|
||||
{placeholder}
|
||||
{disabled}
|
||||
{rows}
|
||||
bind:value
|
||||
on:input
|
||||
on:change
|
||||
on:keydown
|
||||
on:focus
|
||||
on:paste
|
||||
bind:this={element}
|
||||
{...$$restProps}
|
||||
class="{sizeClass[size]} {borderClass} focus:border-slate-800
|
||||
focus:dark:border-zinc-200 bg-white dark:bg-zinc-950
|
||||
focus:outline-none focus:ring-2 ring-slate-800/50 rounded-xl
|
||||
dark:ring-zinc-200/50 transition-all text-sm w-full disabled:bg-slate-100
|
||||
disabled:cursor-not-allowed disabled:dark:bg-zinc-900 invalid:!border-red-500
|
||||
peer invalid:text-red-500 z-10
|
||||
{$$props.class || ''}"
|
||||
class:rounded-b-none={$$slots.suffix}
|
||||
class:border-b-0={$$slots.suffix}
|
||||
/>
|
||||
{#if $$slots.suffix}
|
||||
<div
|
||||
class="{borderClass} {sizeClass[
|
||||
size
|
||||
]} w-full border-t-0 rounded-xl rounded-t-none
|
||||
flex items-center"
|
||||
>
|
||||
<slot name="suffix" />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<slot />
|
||||
</div>
|
||||
@@ -0,0 +1,96 @@
|
||||
<script context="module" lang="ts">
|
||||
export type Size = keyof typeof sizeClass
|
||||
export type Shadow = keyof typeof shadowClass
|
||||
|
||||
export const sizeClass = {
|
||||
sm: 'px-3 py-1.5',
|
||||
md: 'px-4 py-2',
|
||||
lg: 'px-5 py-3',
|
||||
}
|
||||
|
||||
export const shadowClass = {
|
||||
sm: 'shadow-sm',
|
||||
none: 'shadow-none',
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import Label from '../forms/Label.svelte'
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
export let label: string | undefined = undefined
|
||||
export let value: string = ''
|
||||
export let placeholder: string = ''
|
||||
export let disabled: boolean = false
|
||||
export let required: boolean = false
|
||||
export let size: Size = 'md'
|
||||
export let id: string = generateID()
|
||||
export let inlineAffixes: boolean = false
|
||||
export let shadow: Shadow = 'none'
|
||||
|
||||
const borderClass = `
|
||||
border border-slate-200 border-b-slate-300 dark:border-zinc-900 dark:border-t-zinc-800
|
||||
`
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1 {$$props.class}">
|
||||
{#if $$slots.label || label}
|
||||
<Label
|
||||
for={id}
|
||||
text={label}
|
||||
class="peer-invalid:text-red-500 {required
|
||||
? "after:content-['*'] after:text-red-500 after:ml-1"
|
||||
: ''}"
|
||||
>
|
||||
<slot name="label" />
|
||||
</Label>
|
||||
{/if}
|
||||
<div
|
||||
class="{shadowClass[shadow]} border {borderClass}
|
||||
focus-within:border-primary-900 focus-within:dark:border-primary-100 focus-within:ring-2
|
||||
ring-slate-300 dark:ring-zinc-700
|
||||
transition-colors
|
||||
rounded-lg flex flex-row items-center text-sm {$$props.class}"
|
||||
>
|
||||
{#if $$slots.prefix}
|
||||
<div
|
||||
class="rounded-lg rounded-r-none
|
||||
text-slate-600 dark:text-zinc-400 {inlineAffixes
|
||||
? 'bg-white dark:bg-zinc-950 pr-0 w-8'
|
||||
: ''} {sizeClass[size]}"
|
||||
>
|
||||
<slot name="prefix" />
|
||||
</div>
|
||||
{/if}
|
||||
<input
|
||||
type="text"
|
||||
{id}
|
||||
{placeholder}
|
||||
{disabled}
|
||||
bind:value
|
||||
on:input
|
||||
on:change
|
||||
on:focus
|
||||
{...$$restProps}
|
||||
class="{sizeClass[size]} bg-white dark:bg-zinc-950
|
||||
focus:outline-none rounded-lg text-sm w-full disabled:bg-slate-100
|
||||
disabled:cursor-not-allowed disabled:dark:bg-zinc-950 invalid:!border-red-500
|
||||
peer invalid:text-red-500 z-10
|
||||
{$$props.class || ''}"
|
||||
class:rounded-l-none={$$slots.prefix}
|
||||
class:border-l-0={$$slots.prefix && inlineAffixes}
|
||||
class:rounded-r-none={$$slots.suffix}
|
||||
class:border-r-0={$$slots.suffix && inlineAffixes}
|
||||
/>
|
||||
{#if $$slots.suffix}
|
||||
<div
|
||||
class="rounded-lg rounded-l-none text-slate-600 dark:text-zinc-400 {inlineAffixes
|
||||
? 'bg-white dark:bg-zinc-950 pl-0'
|
||||
: ''} {sizeClass[size]}"
|
||||
>
|
||||
<slot name="suffix" />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<slot />
|
||||
</div>
|
||||
@@ -0,0 +1 @@
|
||||
export const generateID = () => Math.floor(Math.random() * 1000000).toString()
|
||||
@@ -0,0 +1,42 @@
|
||||
// Reexport your entry components here
|
||||
|
||||
export { default as Button } from './button/Button.svelte'
|
||||
export { buttonColor, buttonSize, buttonShadow } from './button/Button.svelte'
|
||||
export { default as Codeblock } from './code/Codeblock.svelte'
|
||||
export { default as Snippet } from './code/Snippet.svelte'
|
||||
export { default as Spinner } from './loader/Spinner.svelte'
|
||||
export { default as Routebar } from './nav/Routebar.svelte'
|
||||
export { default as Material } from './materials/Material.svelte'
|
||||
|
||||
export { default as Form } from './forms/Form.svelte'
|
||||
export { default as Label } from './forms/Label.svelte'
|
||||
export { default as FileInput } from './forms/FileInput.svelte'
|
||||
export { default as TextInput } from './forms/TextInput.svelte'
|
||||
export { default as TextArea } from './forms/TextArea.svelte'
|
||||
export { default as Select } from './forms/Select.svelte'
|
||||
export { default as ImageInput } from './forms/ImageInput.svelte'
|
||||
|
||||
export { default as Checkbox } from './forms/Checkbox.svelte'
|
||||
export { default as Switch } from './forms/Switch.svelte'
|
||||
|
||||
export { default as Radio } from './forms/Radio.svelte'
|
||||
export { default as RadioGroup } from './forms/RadioGroup.svelte'
|
||||
export { default as Choicebox } from './forms/Choicebox.svelte'
|
||||
export { default as ChoiceboxGroup } from './forms/ChoiceboxGroup.svelte'
|
||||
|
||||
export { default as Popover } from './popover/Popover.svelte'
|
||||
export { default as Menu } from './popover/Menu.svelte'
|
||||
export { default as MenuDivider } from './popover/MenuDivider.svelte'
|
||||
export { default as MenuButton } from './popover/MenuButton.svelte'
|
||||
export { default as Disclosure } from './disclosure/Disclosure.svelte'
|
||||
export { default as Modal } from './modal/Modal.svelte'
|
||||
export { modal, action } from './modal/modal.js'
|
||||
export { default as ModalContainer } from './modal/ModalContainer.svelte'
|
||||
|
||||
export { toast, removeToast, toasts, toastColors } from './toast/toasts.js'
|
||||
export { default as ToastContainer } from './toast/ToastContainer.svelte'
|
||||
|
||||
export { default as Note } from './note/Note.svelte'
|
||||
export { default as Badge } from './badge/Badge.svelte'
|
||||
export { default as Placeholder } from './placeholder/Placeholder.svelte'
|
||||
export { default as Search } from './search/Search.svelte'
|
||||
@@ -0,0 +1,35 @@
|
||||
<script lang="ts">
|
||||
export let width: number = 16
|
||||
</script>
|
||||
|
||||
<svg
|
||||
{...$$restProps}
|
||||
{width}
|
||||
height={width}
|
||||
role="status"
|
||||
class="inline -mt-px animate-spin text-zinc-400 fill-primary-900
|
||||
dark:text-zinc-600 dark:fill-primary-100"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
|
||||
<style>
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
.animate-spin {
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,69 @@
|
||||
<script lang="ts">
|
||||
type Elevation = keyof typeof elevationClass
|
||||
type Padding = keyof typeof paddingClass
|
||||
type Rounding = keyof typeof roundedClass
|
||||
type Color = keyof typeof colorClass
|
||||
|
||||
const elevationClass = {
|
||||
flat: '',
|
||||
low: 'shadow-xs',
|
||||
medium: 'shadow-sm',
|
||||
high: 'shadow-md',
|
||||
xhigh: 'shadow-lg',
|
||||
max: 'shadow-xl'
|
||||
}
|
||||
|
||||
const paddingClass = {
|
||||
none: 'p-0',
|
||||
sm: 'p-2',
|
||||
md: 'p-4',
|
||||
lg: 'p-5',
|
||||
xl: 'p-6'
|
||||
}
|
||||
|
||||
const roundedClass = {
|
||||
none: 'rounded-none',
|
||||
sm: 'rounded-sm',
|
||||
md: 'rounded-md',
|
||||
lg: 'rounded-lg',
|
||||
xl: 'rounded-xl',
|
||||
'2xl': 'rounded-2xl',
|
||||
full: 'rounded-full'
|
||||
}
|
||||
|
||||
const colorClass = {
|
||||
default:
|
||||
'bg-white dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800 border-b-slate-300 dark:border-t-zinc-700',
|
||||
distinct:
|
||||
'bg-white dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800 border-b-slate-300 dark:border-t-zinc-700',
|
||||
transparent:
|
||||
'border border-slate-200 dark:border-zinc-900 border-b-slate-300 dark:border-t-zinc-800',
|
||||
none: ''
|
||||
}
|
||||
|
||||
export let elevation: Elevation = 'flat'
|
||||
export let padding: Padding = 'md'
|
||||
export let rounding: Rounding = 'lg'
|
||||
export let color: Color = 'default'
|
||||
|
||||
export let element: string = 'div'
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={element}
|
||||
on:click
|
||||
on:keypress
|
||||
on:keydown
|
||||
on:keyup
|
||||
on:focus
|
||||
{...$$restProps}
|
||||
class="{elevationClass[elevation]}
|
||||
{paddingClass[padding]}
|
||||
{roundedClass[rounding]}
|
||||
{colorClass[color]}
|
||||
text-sm
|
||||
{$$props.class}
|
||||
"
|
||||
>
|
||||
<slot />
|
||||
</svelte:element>
|
||||
@@ -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>
|
||||
@@ -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}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<script lang="ts">
|
||||
import Button from '../button/Button.svelte'
|
||||
|
||||
type Route = string
|
||||
|
||||
type RouteObject = {
|
||||
url: Route
|
||||
children?: RouteObject[]
|
||||
name: string
|
||||
}
|
||||
|
||||
/**
|
||||
* The routes for the routebar.
|
||||
*/
|
||||
export let routes: RouteObject[]
|
||||
export let currentRoute: Route | undefined = undefined
|
||||
|
||||
export let parentRoute: Route | undefined = undefined
|
||||
export let depth: number = 0
|
||||
</script>
|
||||
|
||||
<svelte:element this={depth == 0 ? 'nav' : 'ul'} class="flex flex-col h-full">
|
||||
{#each routes as route}
|
||||
{#if route.children}
|
||||
<Button
|
||||
class="{depth > 0 ? 'pl-6' : ''} {route.url == currentRoute
|
||||
? 'border-t-0 border-r-0 border-b-0 border-l !border-slate-900 dark:!border-zinc-50'
|
||||
: 'border-t-0 border-r-0 border-b-0 border-l !border-slate-300 dark:!border-zinc-700'} rounded-l-none {depth ==
|
||||
0
|
||||
? 'mt-2'
|
||||
: ''} font-bold"
|
||||
href={route.url}
|
||||
alignment="left"
|
||||
color="tertiary"
|
||||
size="lg"
|
||||
>
|
||||
{route.name}
|
||||
</Button>
|
||||
<svelte:self
|
||||
routes={route.children}
|
||||
{currentRoute}
|
||||
{parentRoute}
|
||||
depth={depth + 1}
|
||||
/>
|
||||
{:else}
|
||||
<Button
|
||||
href={route.url}
|
||||
alignment="left"
|
||||
color="tertiary"
|
||||
size="lg"
|
||||
class="{depth > 1 ? 'pl-12' : depth > 0 ? 'pl-6' : ''} {route.url ==
|
||||
currentRoute
|
||||
? 'border-t-0 border-r-0 border-b-0 border-l !border-slate-950 dark:!border-zinc-50'
|
||||
: 'border-t-0 border-r-0 border-b-0 border-l !border-slate-300 dark:!border-zinc-700'} font-normal rounded-l-none"
|
||||
>
|
||||
{route.name}
|
||||
</Button>
|
||||
{/if}
|
||||
{/each}
|
||||
</svelte:element>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { Material } from '../index.js'
|
||||
import { Icon, InformationCircle } from 'svelte-hero-icons'
|
||||
|
||||
export let content: string | undefined = undefined
|
||||
</script>
|
||||
|
||||
<Material padding="sm" class="flex flex-row space-x-2 items-center">
|
||||
<Icon src={InformationCircle} size="18" mini />
|
||||
<p>
|
||||
{#if $$slots.default}
|
||||
<slot />
|
||||
{:else if content}
|
||||
{content}
|
||||
{/if}
|
||||
</p>
|
||||
</Material>
|
||||
@@ -0,0 +1,37 @@
|
||||
<script lang="ts">
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
export let icon: IconSource | undefined = undefined
|
||||
export let title: string | undefined = undefined
|
||||
export let description: string | undefined = undefined
|
||||
</script>
|
||||
|
||||
<div class="text-slate-700 dark:text-zinc-300 flex flex-col justify-center items-center gap-2">
|
||||
{#if icon || $$slots.icon}
|
||||
<div class="border border-slate-200 dark:border-zinc-700 dark:bg-zinc-800 p-3 rounded-full">
|
||||
{#if $$slots.icon}
|
||||
<slot name="icon" />
|
||||
{:else if icon}
|
||||
<Icon src={icon} size="28" />
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="flex flex-col gap-1 text-center">
|
||||
<h1 class="text-slate-900 dark:text-zinc-100 text-lg font-medium">
|
||||
{#if $$slots.title}
|
||||
<slot name="title" />
|
||||
{:else if title}
|
||||
{title}
|
||||
{/if}
|
||||
</h1>
|
||||
{#if description || $$slots.description}
|
||||
<p class="text-sm text-center font-normal">
|
||||
{#if $$slots.description}
|
||||
<slot name="description" />
|
||||
{:else if description}
|
||||
{description}
|
||||
{/if}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
<slot />
|
||||
</div>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script lang="ts">
|
||||
import Material from '../materials/Material.svelte'
|
||||
import Popover, { type Origin } from '../popover/Popover.svelte'
|
||||
import {
|
||||
offset,
|
||||
type Middleware,
|
||||
type Placement,
|
||||
shift,
|
||||
type Strategy,
|
||||
flip,
|
||||
autoPlacement,
|
||||
size,
|
||||
} from '@floating-ui/core'
|
||||
|
||||
export let openOnHover: boolean = false
|
||||
export let open: boolean = false
|
||||
|
||||
export let placement: Placement = 'bottom-start'
|
||||
export let middleware: Middleware[] = [
|
||||
offset(6),
|
||||
shift({ padding: 6 }),
|
||||
flip(),
|
||||
]
|
||||
export let strategy: Strategy = 'absolute'
|
||||
</script>
|
||||
|
||||
<Popover
|
||||
{openOnHover}
|
||||
{placement}
|
||||
{middleware}
|
||||
{strategy}
|
||||
{...$$restProps}
|
||||
bind:open
|
||||
popoverClass="backdrop-blur-xl rounded-xl w-full max-w-[280px]"
|
||||
class={$$props.class}
|
||||
>
|
||||
<slot name="target" slot="target" />
|
||||
<div
|
||||
slot="popover"
|
||||
class="w-full max-w-[280px] origin-top-left
|
||||
max-h-[32rem] overflow-auto list-none shadow-lg rounded-xl"
|
||||
>
|
||||
<Material
|
||||
class="flex flex-col py-2 list-none bg-white/80 dark:bg-zinc-900/80 px-2 gap-px"
|
||||
color="distinct"
|
||||
padding="none"
|
||||
rounding="xl"
|
||||
>
|
||||
<slot />
|
||||
</Material>
|
||||
</div>
|
||||
</Popover>
|
||||
@@ -0,0 +1,38 @@
|
||||
<script lang="ts">
|
||||
import Button, {
|
||||
type ButtonAlignment,
|
||||
type ButtonColor,
|
||||
} from '../button/Button.svelte'
|
||||
|
||||
export let color: ButtonColor = 'tertiary'
|
||||
export let alignment: ButtonAlignment = 'left'
|
||||
export let href: string | undefined = undefined
|
||||
export let disabled: boolean = false
|
||||
</script>
|
||||
|
||||
<Button
|
||||
{...$$restProps}
|
||||
on:click
|
||||
{color}
|
||||
rounding="none"
|
||||
class="w-full px-2 rounded-lg min-h-[36px] font-normal {disabled
|
||||
? 'opacity-70 pointer-events-none cursor-not-allowed'
|
||||
: ''} {color == 'tertiary'
|
||||
? 'hover:dark:bg-zinc-800/70'
|
||||
: ''} duration-100 {$$props.class}"
|
||||
{alignment}
|
||||
{href}
|
||||
{disabled}
|
||||
>
|
||||
<span
|
||||
class="contents {color == 'tertiary'
|
||||
? 'text-slate-600 dark:text-zinc-400'
|
||||
: ''}
|
||||
flex-shrink-0"
|
||||
slot="prefix"
|
||||
>
|
||||
<slot name="prefix" />
|
||||
</span>
|
||||
<slot />
|
||||
<slot name="suffix" slot="suffix" />
|
||||
</Button>
|
||||
@@ -0,0 +1,6 @@
|
||||
<div
|
||||
class="text-slate-800 dark:text-zinc-200 text-xs font-medium py-2 px-2 flex items-center gap-1"
|
||||
>
|
||||
<div><slot /></div>
|
||||
<hr class="flex-shrink flex-1 border-slate-200 dark:border-zinc-800 border-opacity-70" />
|
||||
</div>
|
||||
@@ -0,0 +1,120 @@
|
||||
<script context="module" lang="ts">
|
||||
export type Origin = keyof typeof popoverOrigins
|
||||
|
||||
export const popoverOrigins = {
|
||||
'top-right': 'bottom-full right-0 origin-bottom-right',
|
||||
'bottom-left': 'top-full origin-top-left',
|
||||
'top-left': 'bottom-full left-0 origin-bottom-left',
|
||||
'bottom-right': 'top-full right-0 origin-top-right',
|
||||
'top-center': 'bottom-full -left-[450%] origin-bottom',
|
||||
'bottom-center': 'top-full -left-[450%] origin-top',
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { Material } from '../index'
|
||||
import { backOut, elasticIn, elasticOut, expoOut } from 'svelte/easing'
|
||||
import { fly, scale } from 'svelte/transition'
|
||||
import { createFloatingActions } from 'svelte-floating-ui'
|
||||
import {
|
||||
offset,
|
||||
type Middleware,
|
||||
flip,
|
||||
shift,
|
||||
type Placement,
|
||||
type Strategy,
|
||||
size,
|
||||
} from '@floating-ui/core'
|
||||
import Portal from './Portal.svelte'
|
||||
import { focusTrap } from 'svelte-focus-trap'
|
||||
import { tick } from 'svelte'
|
||||
|
||||
export let openOnHover: boolean = false
|
||||
export let open = false
|
||||
export let placement: Placement = 'bottom-start'
|
||||
export let middleware: Middleware[] = [offset(6), shift(), flip()]
|
||||
export let strategy: Strategy = 'fixed'
|
||||
export let manual: boolean = false
|
||||
|
||||
let canUseContents = true
|
||||
|
||||
let el: any
|
||||
|
||||
const [floatingRef, floatingContent] = createFloatingActions({
|
||||
strategy: strategy,
|
||||
placement: placement,
|
||||
middleware: middleware,
|
||||
})
|
||||
|
||||
const customFloatingContent = (node: HTMLDivElement) => {
|
||||
// if (!canUseContents) return
|
||||
|
||||
floatingContent(node)
|
||||
}
|
||||
|
||||
const customFloatingRef = (node: HTMLButtonElement) => {
|
||||
const n = node.children.item(0)
|
||||
|
||||
// @ts-ignore
|
||||
if (n) floatingRef(n)
|
||||
else {
|
||||
canUseContents = false
|
||||
floatingRef(node)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:body
|
||||
on:click={(e) => {
|
||||
if (openOnHover) return
|
||||
|
||||
if (!el?.contains(e.target)) {
|
||||
open = false
|
||||
}
|
||||
}}
|
||||
on:keydown={async (e) => {
|
||||
if (open && e.key == 'Escape') {
|
||||
open = false
|
||||
el?.firstChild.focus()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
{#if $$slots.target}
|
||||
<button
|
||||
on:mouseover={() => (openOnHover ? (open = true) : false)}
|
||||
on:mouseleave={() => (openOnHover ? (open = false) : false)}
|
||||
on:focus={() => (openOnHover ? (open = true) : false)}
|
||||
on:focusout={() => (openOnHover ? (open = false) : false)}
|
||||
on:click={() => (!openOnHover && !manual ? (open = !open) : false)}
|
||||
on:keydown={(e) => {
|
||||
if (e.key == 'Escape') open = false
|
||||
}}
|
||||
role="menu"
|
||||
type="button"
|
||||
class="{canUseContents
|
||||
? 'contents text-left'
|
||||
: 'w-max h-max'} {$$props.class}"
|
||||
bind:this={el}
|
||||
use:customFloatingRef
|
||||
>
|
||||
<slot name="target" />
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
{#if open}
|
||||
<Portal class="z-[150]">
|
||||
<div
|
||||
transition:scale={{ duration: 200, start: 0.96, easing: backOut }}
|
||||
class="z-[150] {$$props.popoverClass}"
|
||||
use:customFloatingContent
|
||||
use:focusTrap
|
||||
>
|
||||
<slot name="popover">
|
||||
<Material elevation="high" color="distinct" class="flex flex-col">
|
||||
<slot />
|
||||
</Material>
|
||||
</slot>
|
||||
</div>
|
||||
</Portal>
|
||||
{/if}
|
||||
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment'
|
||||
|
||||
// https://github.com/sveltejs/svelte/issues/3088#issuecomment-505785516
|
||||
import { onMount, onDestroy, createEventDispatcher } from 'svelte'
|
||||
let slottedElements: HTMLDivElement, portal: HTMLDivElement
|
||||
|
||||
const dispatch = createEventDispatcher<{ mounted: void }>()
|
||||
|
||||
onMount(() => {
|
||||
if (!browser) return
|
||||
portal = document?.createElement('div')
|
||||
if (portal) portal.className = 'portal-mount'
|
||||
document?.body.appendChild(portal)
|
||||
portal?.appendChild(slottedElements)
|
||||
dispatch('mounted')
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
portal.remove()
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="portal-initial-mount-point">
|
||||
<div bind:this={slottedElements} class="portal-content {$$props.class || ''}">
|
||||
<slot />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.portal-initial-mount-point {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,86 @@
|
||||
<script lang="ts">
|
||||
import { Menu, TextInput, Spinner, MenuButton } from '../index.js'
|
||||
import { debounce } from '../util/time.js'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { Icon, MagnifyingGlass } from 'svelte-hero-icons'
|
||||
|
||||
export let query: string = ''
|
||||
|
||||
type T = $$Generic
|
||||
let items: T[] = []
|
||||
|
||||
export let selected: T | undefined = undefined
|
||||
|
||||
export let search: (query: string) => Promise<T[]>
|
||||
export let extractName: (item: T) => string
|
||||
|
||||
/**
|
||||
* This is here so that the menu doesn't open as soon as it's mounted.
|
||||
*/
|
||||
let openMenu = false
|
||||
let searching = false
|
||||
|
||||
const dispatcher = createEventDispatcher<{
|
||||
input: Event
|
||||
select: T | undefined
|
||||
}>()
|
||||
|
||||
export let select = (item: T) => {
|
||||
selected = item
|
||||
query = extractName(item)
|
||||
dispatcher('select', item)
|
||||
}
|
||||
|
||||
const debounceFunc = debounce(async () => {
|
||||
searching = true
|
||||
openMenu = true
|
||||
items = await search(query)
|
||||
searching = false
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="relative">
|
||||
<Menu bind:open={openMenu}>
|
||||
<slot name="input" slot="target">
|
||||
<TextInput
|
||||
bind:value={query}
|
||||
on:input={(e) => {
|
||||
searching = true
|
||||
openMenu = true
|
||||
dispatcher('input', e)
|
||||
debounceFunc()
|
||||
}}
|
||||
on:focus={(e) => {
|
||||
searching = true
|
||||
openMenu = true
|
||||
dispatcher('input', e)
|
||||
debounceFunc()
|
||||
}}
|
||||
{...$$restProps}
|
||||
inlineAffixes
|
||||
slot="target"
|
||||
>
|
||||
<div slot="prefix" class="h-5 flex items-center">
|
||||
<Icon src={MagnifyingGlass} mini size="16" />
|
||||
</div>
|
||||
</TextInput>
|
||||
</slot>
|
||||
{#if searching}
|
||||
<div class="w-full h-24 grid place-items-center">
|
||||
<Spinner width={24} />
|
||||
</div>
|
||||
{:else if items.length == 0}
|
||||
<div class="text-center h-24 grid place-items-center">
|
||||
<slot name="noresults">No results found.</slot>
|
||||
</div>
|
||||
{:else}
|
||||
{#each items as item}
|
||||
<slot {extractName} {item} {dispatcher} {select}>
|
||||
<MenuButton on:click={() => select(item)}>
|
||||
{extractName(item)}
|
||||
</MenuButton>
|
||||
</slot>
|
||||
{/each}
|
||||
{/if}
|
||||
</Menu>
|
||||
</div>
|
||||
@@ -0,0 +1,76 @@
|
||||
<script lang="ts">
|
||||
import { Spinner } from '../index.js'
|
||||
import { backOut } from 'svelte/easing'
|
||||
import { type Toast, toasts, toastColors } from './toasts.js'
|
||||
import {
|
||||
InformationCircle,
|
||||
ExclamationTriangle,
|
||||
ExclamationCircle,
|
||||
CheckCircle,
|
||||
Icon,
|
||||
XMark,
|
||||
Check,
|
||||
} from 'svelte-hero-icons'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
export let toast: Toast
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="{toastColors[
|
||||
toast.type
|
||||
]} relative w-80 rounded-lg overflow-hidden flex flex-row items-center"
|
||||
transition:fly={{
|
||||
duration: 300,
|
||||
y: 8,
|
||||
opacity: 0,
|
||||
}}
|
||||
>
|
||||
{#if toast.loading}
|
||||
<div class="relative m-2 ml-4 flex-shrink-0">
|
||||
<Spinner width={20} />
|
||||
</div>
|
||||
{:else}
|
||||
<Icon
|
||||
size="20"
|
||||
mini
|
||||
class="relative m-2 ml-4 flex-shrink-0"
|
||||
src={toast.type == 'info'
|
||||
? InformationCircle
|
||||
: toast.type == 'success'
|
||||
? CheckCircle
|
||||
: toast.type == 'warning'
|
||||
? ExclamationTriangle
|
||||
: toast.type == 'error'
|
||||
? ExclamationCircle
|
||||
: ExclamationCircle}
|
||||
/>
|
||||
{/if}
|
||||
<div class="flex flex-col p-4 pl-0 break-words max-w-full">
|
||||
{#if toast.title}
|
||||
<h1 class="text-base font-bold">{toast.title}</h1>
|
||||
{/if}
|
||||
<p class="text-sm">{toast.content}</p>
|
||||
</div>
|
||||
<div class="ml-auto flex items-center gap-1 m-2">
|
||||
{#if toast.action}
|
||||
<button
|
||||
on:click={() => {
|
||||
toast.action?.()
|
||||
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
|
||||
}}
|
||||
class="rounded-lg w-max transition-colors hover:bg-black/20 hover:dark:bg-white/20 p-2"
|
||||
>
|
||||
<Icon src={Check} size="16" mini />
|
||||
</button>
|
||||
{/if}
|
||||
<button
|
||||
on:click={() => {
|
||||
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
|
||||
}}
|
||||
class="rounded-lg w-max transition-colors hover:bg-black/20 hover:dark:bg-white/20 p-2"
|
||||
>
|
||||
<Icon src={XMark} size="16" mini />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
import Toast from './Toast.svelte'
|
||||
import { flip } from 'svelte/animate'
|
||||
import { toasts } from './toasts.js'
|
||||
import { backInOut, backOut } from 'svelte/easing'
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="fixed right-0 bottom-0 flex flex-col items-end justify-end z-[200] p-4
|
||||
group overflow-hidden h-screen min-w-[24rem] pointer-events-none gap-4"
|
||||
>
|
||||
{#each $toasts as toast, index (toast.id)}
|
||||
<div
|
||||
animate:flip={{ duration: 500, easing: backOut }}
|
||||
class="pointer-events-auto transition-all
|
||||
duration-300"
|
||||
>
|
||||
<Toast {toast} />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -0,0 +1,65 @@
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
type ToastType = keyof typeof toastColors
|
||||
|
||||
export const toastColors = {
|
||||
error: 'bg-white dark:bg-zinc-950 text-red-600 dark:text-red-400 border border-red-700',
|
||||
warning:
|
||||
'bg-white dark:bg-zinc-950 text-yellow-600 dark:text-yellow-400 border border-yellow-600',
|
||||
success: 'bg-white dark:bg-zinc-950 text-green-700 dark:text-green-400 border border-green-500',
|
||||
info: 'dark:bg-zinc-950 bg-white border border-slate-200 dark:border-zinc-800 shadow-lg'
|
||||
}
|
||||
|
||||
export interface Toast {
|
||||
id: number
|
||||
title?: string
|
||||
content: string
|
||||
type: ToastType
|
||||
loading?: boolean
|
||||
action?: () => any
|
||||
}
|
||||
|
||||
export const toasts = writable<Toast[]>([])
|
||||
|
||||
export function toast({
|
||||
title,
|
||||
content,
|
||||
type = 'info',
|
||||
duration = 5000,
|
||||
loading = false,
|
||||
action
|
||||
}: {
|
||||
title?: string
|
||||
content: string
|
||||
type?: ToastType
|
||||
duration?: number
|
||||
loading?: boolean
|
||||
action?: () => any
|
||||
}) {
|
||||
let id = 0
|
||||
|
||||
toasts.update((toasts) => {
|
||||
id = Math.floor(Math.random() * 10000)
|
||||
|
||||
return [
|
||||
...toasts,
|
||||
{
|
||||
id: id,
|
||||
content: content,
|
||||
title: title,
|
||||
type: type,
|
||||
loading: loading,
|
||||
action: action
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
||||
}, duration)
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
export const removeToast = (id: number) =>
|
||||
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
||||
@@ -0,0 +1,7 @@
|
||||
export const debounce = (fn: Function, ms = 300) => {
|
||||
let timeoutId: ReturnType<typeof setTimeout>
|
||||
return function (this: any, ...args: any[]) {
|
||||
clearTimeout(timeoutId)
|
||||
timeoutId = setTimeout(() => fn.apply(this, args), ms)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user