fix: Fix lint errors (#559)
* cleanup: postactions styling * misc: fix first round of errors * pkg: remove vitest * fix: fix lint errors stage 2 * fix: fix lint errors stage 3 * fix: fix lint errors, stage 3 * misc: update eslint rules to warn for writable derived
This commit is contained in:
1 parent
1824245f13
commit
76c581123a
225 files changed
+1553
-2352
No files matched your search
@@ -108,7 +108,8 @@
|
||||
},
|
||||
}
|
||||
|
||||
interface Props extends Omit<HTMLButtonAttributes, 'prefix'> {
|
||||
interface Props
|
||||
extends Omit<HTMLButtonAttributes | HTMLAnchorAttributes, 'prefix'> {
|
||||
loading?: boolean
|
||||
submit?: boolean
|
||||
color?: ButtonColor
|
||||
@@ -118,7 +119,6 @@
|
||||
alignment?: ButtonAlignment
|
||||
shadow?: ButtonShadow
|
||||
column?: boolean
|
||||
animations?: any
|
||||
loaderWidth?: number | undefined
|
||||
href?: string | undefined
|
||||
class?: ClassValue
|
||||
@@ -126,14 +126,17 @@
|
||||
children?: Snippet
|
||||
suffix?: Snippet
|
||||
onclick?: HTMLButtonAttributes['onclick']
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export type { Props as ButtonProps }
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { ClassValue, HTMLButtonAttributes } from 'svelte/elements'
|
||||
import type {
|
||||
ClassValue,
|
||||
HTMLAnchorAttributes,
|
||||
HTMLButtonAttributes,
|
||||
} from 'svelte/elements'
|
||||
|
||||
import Spinner from '../loader/Spinner.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
@@ -148,10 +151,6 @@
|
||||
alignment = 'center',
|
||||
shadow = 'none',
|
||||
column = false,
|
||||
animations = {
|
||||
scale: false,
|
||||
large: false,
|
||||
},
|
||||
disabled,
|
||||
loaderWidth = undefined,
|
||||
href = undefined,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
let copied = $state(false)
|
||||
|
||||
let pre: HTMLPreElement = $state()
|
||||
let pre = $state<HTMLPreElement>()
|
||||
|
||||
const copy = () => {
|
||||
if (children) {
|
||||
@@ -22,7 +22,6 @@
|
||||
htmlSrc?: string | undefined
|
||||
children?: import('svelte').Snippet
|
||||
class?: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { backOut, expoOut } from 'svelte/easing'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import { slide } from 'svelte/transition'
|
||||
|
||||
interface Props {
|
||||
open?: boolean
|
||||
class?: ClassValue
|
||||
summary?: import('svelte').Snippet<[any]>
|
||||
extended?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
[key: string]: any
|
||||
summary?: Snippet<[{ open: boolean }]>
|
||||
extended?: Snippet
|
||||
children?: Snippet<[{ open: boolean }]>
|
||||
}
|
||||
|
||||
let {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import Button from '../button/Button.svelte'
|
||||
import { generateID } from '../forms/helper.js'
|
||||
import { Label } from '../index.js'
|
||||
import { Icon, PaperClip } from 'svelte-hero-icons'
|
||||
|
||||
interface Props {
|
||||
accept?: string
|
||||
@@ -51,12 +50,11 @@
|
||||
<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 -->
|
||||
{#each previewURLs as file (file)}
|
||||
<img
|
||||
src={file}
|
||||
onload={() => URL.revokeObjectURL(file)}
|
||||
alt={file}
|
||||
alt=""
|
||||
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"
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||
import Label from '../forms/Label.svelte'
|
||||
import { generateID } from '../forms/helper.js'
|
||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||
import TextInput from './TextInput.svelte'
|
||||
|
||||
interface Props {
|
||||
@@ -43,11 +41,11 @@
|
||||
: ''}
|
||||
{url != undefined ? 'rounded-b-none' : ''}
|
||||
"
|
||||
ondrop={(event) => {
|
||||
ondrop={event => {
|
||||
event.preventDefault()
|
||||
files = event.dataTransfer?.files ?? null
|
||||
}}
|
||||
ondragover={(event) => {
|
||||
ondragover={event => {
|
||||
event.preventDefault()
|
||||
|
||||
if (event.dataTransfer) {
|
||||
@@ -55,7 +53,7 @@
|
||||
dragover = true
|
||||
}
|
||||
}}
|
||||
ondragleave={(e) => {
|
||||
ondragleave={e => {
|
||||
e.preventDefault()
|
||||
dragover = false
|
||||
}}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
import type { HTMLAttributes } from 'svelte/elements'
|
||||
|
||||
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
||||
for?: string | undefined
|
||||
/**
|
||||
* The `text` prop will take precedence over the slot.
|
||||
@@ -7,7 +9,6 @@
|
||||
text?: string | undefined
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
disabled?: boolean
|
||||
children?: import('svelte').Snippet
|
||||
description?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
group?: string
|
||||
row?: boolean
|
||||
class?: string
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
children?: import('svelte').Snippet<[{ group: string }]>
|
||||
}
|
||||
|
||||
let {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
defaultValue?: boolean
|
||||
checked?: boolean
|
||||
labelClass?: string
|
||||
class?: string
|
||||
@@ -9,7 +8,6 @@
|
||||
}
|
||||
|
||||
let {
|
||||
defaultValue = false,
|
||||
checked = $bindable(),
|
||||
labelClass = '',
|
||||
class: clazz = '',
|
||||
|
||||
@@ -34,10 +34,7 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type {
|
||||
HTMLInputAttributes,
|
||||
HTMLInputTypeAttribute,
|
||||
} from 'svelte/elements'
|
||||
import type { HTMLInputAttributes } from 'svelte/elements'
|
||||
|
||||
import Label from '../forms/Label.svelte'
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" generics="T">
|
||||
import { getContext, onMount, type Snippet } from 'svelte'
|
||||
import type { HTMLAttributes, HTMLOptionAttributes } from 'svelte/elements'
|
||||
<script lang="ts">
|
||||
import { getContext, type Snippet } from 'svelte'
|
||||
import type { IconSource } from 'svelte-hero-icons'
|
||||
import type { HTMLOptionAttributes } from 'svelte/elements'
|
||||
|
||||
interface Props extends Omit<HTMLOptionAttributes, 'prefix'> {
|
||||
children: Snippet
|
||||
@@ -10,7 +10,7 @@
|
||||
let { children, icon, ...rest }: Props = $props()
|
||||
|
||||
let optionElement = $state<HTMLOptionElement>()
|
||||
let option: any = $derived({
|
||||
let option = $derived({
|
||||
value: optionElement?.value ?? '',
|
||||
label: optionElement?.innerText?.trim() ?? '',
|
||||
icon: icon,
|
||||
@@ -29,7 +29,7 @@
|
||||
const context = getContext<SelectContext>('select')
|
||||
|
||||
$effect(() => {
|
||||
if (!context.options.find((v) => v == option)) {
|
||||
if (!context.options.find(v => v == option)) {
|
||||
context.options.push(option)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,28 +1,56 @@
|
||||
<script lang="ts" generics="T">
|
||||
import { run, createBubbler } from 'svelte/legacy'
|
||||
<script lang="ts" module>
|
||||
interface Props<T> extends Omit<HTMLSelectAttributes, 'size'> {
|
||||
value?: T | string | undefined
|
||||
placeholder?: string | undefined
|
||||
label?: string | undefined
|
||||
size?: ButtonSize
|
||||
shadow?: ButtonShadow
|
||||
id?: string
|
||||
class?: ClassValue
|
||||
baseClass?: ClassValue
|
||||
selectClass?: ClassValue
|
||||
customLabel?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
customOption?: import('svelte').Snippet<
|
||||
[
|
||||
{
|
||||
option: {
|
||||
value: string
|
||||
label: string
|
||||
icon?: IconSource
|
||||
disabled?: boolean
|
||||
}
|
||||
selected: boolean
|
||||
},
|
||||
]
|
||||
>
|
||||
oncontextmenu?: HTMLSelectAttributes['oncontextmenu']
|
||||
onchange?: HTMLSelectAttributes['onchange']
|
||||
}
|
||||
|
||||
const bubble = createBubbler()
|
||||
import {
|
||||
buttonColor,
|
||||
buttonSize,
|
||||
type ButtonShadow,
|
||||
type ButtonSize,
|
||||
buttonShadow,
|
||||
} from '../../button/Button.svelte'
|
||||
import Label from '../Label.svelte'
|
||||
import { generateID } from '../helper.js'
|
||||
import Menu from '../../popover/Menu.svelte'
|
||||
import MenuButton from '../../popover/MenuButton.svelte'
|
||||
import Popover from '../../popover/Popover.svelte'
|
||||
import { createEventDispatcher, onMount, setContext, tick } from 'svelte'
|
||||
export type { Props as SelectProps }
|
||||
</script>
|
||||
|
||||
<script lang="ts" generics="T">
|
||||
import { setContext, tick } from 'svelte'
|
||||
import {
|
||||
CheckCircle,
|
||||
ChevronDown,
|
||||
ChevronUpDown,
|
||||
Icon,
|
||||
type IconSource,
|
||||
} from 'svelte-hero-icons'
|
||||
import type { ClassValue, HTMLSelectAttributes } from 'svelte/elements'
|
||||
import {
|
||||
buttonColor,
|
||||
buttonShadow,
|
||||
buttonSize,
|
||||
type ButtonShadow,
|
||||
type ButtonSize,
|
||||
} from '../../button/Button.svelte'
|
||||
import Menu from '../../popover/Menu.svelte'
|
||||
import MenuButton from '../../popover/MenuButton.svelte'
|
||||
import Label from '../Label.svelte'
|
||||
import { generateID } from '../helper.js'
|
||||
|
||||
let open = $state(false)
|
||||
let element: HTMLSelectElement | undefined = $state()
|
||||
@@ -40,23 +68,6 @@
|
||||
options: [],
|
||||
})
|
||||
|
||||
interface Props extends Omit<HTMLSelectAttributes, 'size'> {
|
||||
value?: T | string | undefined
|
||||
placeholder?: string | undefined
|
||||
label?: string | undefined
|
||||
size?: ButtonSize
|
||||
shadow?: ButtonShadow
|
||||
id?: string
|
||||
class?: ClassValue
|
||||
baseClass?: ClassValue
|
||||
selectClass?: ClassValue
|
||||
customLabel?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
customOption?: import('svelte').Snippet<[any]>
|
||||
oncontextmenu?: HTMLSelectAttributes['oncontextmenu']
|
||||
onchange?: HTMLSelectAttributes['onchange']
|
||||
}
|
||||
|
||||
let {
|
||||
value = $bindable(undefined),
|
||||
placeholder = undefined,
|
||||
@@ -73,7 +84,7 @@
|
||||
oncontextmenu,
|
||||
onchange,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
}: Props<T> = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1 {clazz} {baseClass}">
|
||||
@@ -96,10 +107,10 @@
|
||||
w-full min-w-full cursor-pointer pr-6 {buttonColor.secondary}
|
||||
{clazz} {selectClass}"
|
||||
bind:value
|
||||
onmousedown={(e) => {
|
||||
onmousedown={e => {
|
||||
e.preventDefault()
|
||||
}}
|
||||
onkeypress={(e) => {
|
||||
onkeypress={e => {
|
||||
e.preventDefault()
|
||||
open = !open
|
||||
}}
|
||||
@@ -114,7 +125,7 @@
|
||||
</select>
|
||||
{/snippet}
|
||||
|
||||
{#each context.options as option}
|
||||
{#each context.options as option (option)}
|
||||
{#if customOption}{@render customOption({
|
||||
option,
|
||||
selected: option.value == value,
|
||||
|
||||
@@ -5,7 +5,6 @@ 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 Label } from './forms/Label.svelte'
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
width?: number
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let { width = 16, ...rest }: Props = $props()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { createBubbler } from 'svelte/legacy'
|
||||
import type { ClassValue, HTMLAttributes } from 'svelte/elements'
|
||||
|
||||
const bubble = createBubbler()
|
||||
type Elevation = keyof typeof elevationClass
|
||||
type Padding = keyof typeof paddingClass
|
||||
type Rounding = keyof typeof roundedClass
|
||||
@@ -46,15 +45,14 @@
|
||||
none: '',
|
||||
}
|
||||
|
||||
interface Props {
|
||||
interface Props extends HTMLAttributes<HTMLDivElement> {
|
||||
elevation?: Elevation
|
||||
padding?: Padding
|
||||
rounding?: Rounding
|
||||
color?: Color
|
||||
element?: string
|
||||
class?: string
|
||||
class?: ClassValue
|
||||
children?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -72,13 +70,14 @@
|
||||
<svelte:element
|
||||
this={element}
|
||||
{...rest}
|
||||
class="{elevationClass[elevation]}
|
||||
{paddingClass[padding]}
|
||||
{roundedClass[rounding]}
|
||||
{colorClass[color]}
|
||||
text-sm
|
||||
{clazz}
|
||||
"
|
||||
class={[
|
||||
elevationClass[elevation],
|
||||
paddingClass[padding],
|
||||
roundedClass[rounding],
|
||||
colorClass[color],
|
||||
'text-sm',
|
||||
clazz,
|
||||
]}
|
||||
>
|
||||
{@render children?.()}
|
||||
</svelte:element>
|
||||
@@ -1,12 +1,12 @@
|
||||
<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'
|
||||
import { Icon, XMark } from 'svelte-hero-icons'
|
||||
import { backOut } from 'svelte/easing'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import { fade, scale } from 'svelte/transition'
|
||||
import { Button } from '../index.js'
|
||||
import Portal from '../popover/Portal.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
|
||||
interface Props {
|
||||
action?: string | undefined
|
||||
@@ -14,9 +14,9 @@
|
||||
title?: string | undefined | null
|
||||
dismissable?: boolean
|
||||
class?: ClassValue
|
||||
customTitle?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
actions?: import('svelte').Snippet<[any]>
|
||||
customTitle?: Snippet
|
||||
children?: Snippet
|
||||
actions?: Snippet<[{ action: string }]>
|
||||
ondismissed?: () => void
|
||||
onaction?: () => void
|
||||
}
|
||||
@@ -34,20 +34,19 @@
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
let el: any = $state()
|
||||
let el = $state<HTMLElement>()
|
||||
</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-xs
|
||||
bg-white/50 dark:bg-black/50 box-border p-4"
|
||||
transition:fade|global={{ duration: 100 }}
|
||||
onclick={(e) => {
|
||||
onclick={e => {
|
||||
// @ts-expect-error html node hell
|
||||
if (!el.contains(e.target)) {
|
||||
open = false
|
||||
|
||||
@@ -55,7 +54,6 @@ bg-white/50 dark:bg-black/50 box-border p-4"
|
||||
}
|
||||
}}
|
||||
>
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
bind:this={el}
|
||||
use:focusTrap
|
||||
@@ -100,7 +98,7 @@ bg-white/50 dark:bg-black/50 box-border p-4"
|
||||
{#if actions}{@render actions({ action })}{:else}
|
||||
<Button
|
||||
class="w-full"
|
||||
onclick={(e) => {
|
||||
onclick={() => {
|
||||
onaction?.()
|
||||
open = false
|
||||
ondismissed?.()
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
? 'flex-col'
|
||||
: 'flex-row'}"
|
||||
>
|
||||
{#each $shownModal.actions as action}
|
||||
{#each $shownModal.actions as action (action)}
|
||||
<Button
|
||||
size="lg"
|
||||
class="flex-1 w-full"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { IconSource } from 'svelte-hero-icons'
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
export let shownModal = writable<Modal | undefined>(undefined)
|
||||
export const shownModal = writable<Modal | undefined>()
|
||||
|
||||
interface Modal {
|
||||
actions: Action[]
|
||||
@@ -18,7 +18,7 @@ type Action = {
|
||||
/**
|
||||
* What function to run when this action is clicked. If undefined, it'll close the window.
|
||||
*/
|
||||
action: () => any
|
||||
action: () => void
|
||||
type: 'danger' | 'secondary' | 'primary'
|
||||
content: string
|
||||
icon?: IconSource
|
||||
@@ -26,7 +26,7 @@ type Action = {
|
||||
}
|
||||
|
||||
export const action = (action?: {
|
||||
action?: () => any
|
||||
action?: () => void
|
||||
type?: 'danger' | 'secondary' | 'primary'
|
||||
content?: string
|
||||
icon?: IconSource
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
<script lang="ts">
|
||||
import Routebar from './Routebar.svelte'
|
||||
import Button from '../button/Button.svelte'
|
||||
|
||||
type Route = string
|
||||
|
||||
type RouteObject = {
|
||||
url: Route
|
||||
children?: RouteObject[]
|
||||
name: string
|
||||
}
|
||||
|
||||
interface Props {
|
||||
/**
|
||||
* The routes for the routebar.
|
||||
*/
|
||||
routes: RouteObject[]
|
||||
currentRoute?: Route | undefined
|
||||
parentRoute?: Route | undefined
|
||||
depth?: number
|
||||
}
|
||||
|
||||
let {
|
||||
routes,
|
||||
currentRoute = undefined,
|
||||
parentRoute = undefined,
|
||||
depth = 0,
|
||||
}: Props = $props()
|
||||
</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>
|
||||
<Routebar
|
||||
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>
|
||||
@@ -1,16 +1,13 @@
|
||||
<script lang="ts">
|
||||
import Material from '../materials/Material.svelte'
|
||||
import Popover, { type Origin } from '../popover/Popover.svelte'
|
||||
import {
|
||||
flip,
|
||||
offset,
|
||||
shift,
|
||||
type Middleware,
|
||||
type Placement,
|
||||
shift,
|
||||
type Strategy,
|
||||
flip,
|
||||
autoPlacement,
|
||||
size,
|
||||
} from '@floating-ui/core'
|
||||
import Popover from '../popover/Popover.svelte'
|
||||
|
||||
interface Props {
|
||||
openOnHover?: boolean
|
||||
@@ -22,7 +19,6 @@
|
||||
class?: string
|
||||
target?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
import Button, {
|
||||
type ButtonAlignment,
|
||||
type ButtonColor,
|
||||
type ButtonProps,
|
||||
} from '../button/Button.svelte'
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
|
||||
interface Props {
|
||||
interface Props extends ButtonProps {
|
||||
color?: ButtonColor
|
||||
alignment?: ButtonAlignment
|
||||
href?: string | undefined
|
||||
disabled?: boolean
|
||||
class?: string
|
||||
icon?: IconSource
|
||||
prefix?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
suffix?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
prefix?: Snippet
|
||||
children?: Snippet
|
||||
suffix?: Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -25,9 +26,9 @@
|
||||
disabled = false,
|
||||
class: clazz = '',
|
||||
icon,
|
||||
prefix,
|
||||
prefix: passedPrefix,
|
||||
children,
|
||||
suffix,
|
||||
suffix: passedSuffix,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
@@ -55,12 +56,12 @@
|
||||
{#if icon}
|
||||
<Icon src={icon} micro size="16" />
|
||||
{:else}
|
||||
{@render prefix?.()}
|
||||
{@render passedPrefix?.()}
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
{@render children?.()}
|
||||
{#snippet suffix()}
|
||||
{@render suffix?.()}
|
||||
{@render passedSuffix?.()}
|
||||
{/snippet}
|
||||
</Button>
|
||||
@@ -12,22 +12,20 @@
|
||||
</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,
|
||||
offset,
|
||||
shift,
|
||||
type Middleware,
|
||||
type Placement,
|
||||
type Strategy,
|
||||
size,
|
||||
} from '@floating-ui/core'
|
||||
import Portal from './Portal.svelte'
|
||||
import { createFloatingActions } from 'svelte-floating-ui'
|
||||
import { focusTrap } from 'svelte-focus-trap'
|
||||
import { tick } from 'svelte'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { scale } from 'svelte/transition'
|
||||
import { Material } from '../index'
|
||||
import Portal from './Portal.svelte'
|
||||
|
||||
interface Props {
|
||||
openOnHover?: boolean
|
||||
@@ -61,8 +59,8 @@
|
||||
|
||||
let canUseContents = $state(true)
|
||||
|
||||
let el: any = $state()
|
||||
let popoverEl: any = $state()
|
||||
let el = $state<HTMLElement>()
|
||||
let popoverEl = $state<HTMLElement>()
|
||||
|
||||
const [floatingRef, floatingContent] = createFloatingActions({
|
||||
strategy: strategy,
|
||||
@@ -79,7 +77,7 @@
|
||||
const customFloatingRef = (node: HTMLDivElement) => {
|
||||
const n = node.children.item(0)
|
||||
|
||||
// @ts-ignore
|
||||
// @ts-expect-error svelte hell
|
||||
if (n) floatingRef(n)
|
||||
else {
|
||||
canUseContents = false
|
||||
@@ -89,11 +87,13 @@
|
||||
</script>
|
||||
|
||||
<svelte:body
|
||||
onclick={(e) => {
|
||||
onclick={e => {
|
||||
if (openOnHover) return
|
||||
|
||||
// @ts-expect-error svelte hell
|
||||
if (!el?.contains(e.target) && open) {
|
||||
if (!autoClose) {
|
||||
// @ts-expect-error svelte hell
|
||||
if (popoverEl && !popoverEl.contains(e.target)) {
|
||||
open = false
|
||||
}
|
||||
@@ -102,9 +102,10 @@
|
||||
}
|
||||
}
|
||||
}}
|
||||
onkeydown={async (e) => {
|
||||
onkeydown={async e => {
|
||||
if (open && e.key == 'Escape') {
|
||||
open = false
|
||||
// @ts-expect-error svelte hell
|
||||
el?.firstChild.focus()
|
||||
}
|
||||
}}
|
||||
@@ -117,7 +118,7 @@
|
||||
onfocus={() => (openOnHover ? (open = true) : false)}
|
||||
onfocusout={() => (openOnHover ? (open = false) : false)}
|
||||
onclick={() => (!openOnHover && !manual ? (open = !open) : false)}
|
||||
onkeydown={(e) => {
|
||||
onkeydown={e => {
|
||||
if (e.key == 'Escape') open = false
|
||||
}}
|
||||
tabindex="0"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
// https://github.com/sveltejs/svelte/issues/3088#issuecomment-505785516
|
||||
import { onMount, onDestroy, createEventDispatcher } from 'svelte'
|
||||
let slottedElements: HTMLDivElement = $state(),
|
||||
let slottedElements = $state<HTMLDivElement>(),
|
||||
portal: HTMLDivElement
|
||||
|
||||
const dispatch = createEventDispatcher<{ mounted: void }>()
|
||||
@@ -13,7 +13,7 @@
|
||||
portal = document?.createElement('div')
|
||||
if (portal) portal.className = 'portal-mount'
|
||||
document?.body.appendChild(portal)
|
||||
portal?.appendChild(slottedElements)
|
||||
if (slottedElements) portal?.appendChild(slottedElements)
|
||||
dispatch('mounted')
|
||||
})
|
||||
|
||||
|
||||
@@ -4,11 +4,19 @@
|
||||
selected?: T | undefined
|
||||
search: (query: string) => Promise<T[]>
|
||||
extractName: (item: T) => string
|
||||
select?: any
|
||||
select?: (item: T) => void
|
||||
input?: import('svelte').Snippet
|
||||
noresults?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
onselect?: (value: T | undefined) => void
|
||||
children?: import('svelte').Snippet<
|
||||
[
|
||||
{
|
||||
select: (item?: T) => void
|
||||
item: T
|
||||
extractName: (item: T) => string
|
||||
},
|
||||
]
|
||||
>
|
||||
onselect?: (value?: T) => void
|
||||
oninput?: TextInputProps['oninput']
|
||||
}
|
||||
|
||||
@@ -19,7 +27,6 @@
|
||||
import type { TextInputProps } from 'mono-svelte/forms/TextInput.svelte'
|
||||
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'
|
||||
|
||||
let items: T[] = $state([])
|
||||
@@ -62,13 +69,13 @@
|
||||
{#if input}{@render input()}{:else}
|
||||
<TextInput
|
||||
bind:value={query}
|
||||
oninput={(e) => {
|
||||
oninput={e => {
|
||||
searching = true
|
||||
openMenu = true
|
||||
oninput?.(e)
|
||||
debounceFunc()
|
||||
}}
|
||||
onfocus={(e) => {
|
||||
onfocus={e => {
|
||||
searching = true
|
||||
openMenu = true
|
||||
oninput?.(e)
|
||||
@@ -94,7 +101,7 @@
|
||||
{#if noresults}{@render noresults()}{:else}No results found.{/if}
|
||||
</div>
|
||||
{:else}
|
||||
{#each items as item}
|
||||
{#each items as item (item)}
|
||||
{#if children}{@render children({
|
||||
extractName,
|
||||
item,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { Spinner } from '../index.js'
|
||||
import { backOut, expoOut } from 'svelte/easing'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { type Toast, toasts, toastColors } from './toasts.js'
|
||||
import {
|
||||
InformationCircle,
|
||||
@@ -62,7 +62,7 @@
|
||||
<button
|
||||
onclick={() => {
|
||||
toast.action?.()
|
||||
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
|
||||
toasts.update(toasts => toasts.filter(t => t.id != toast.id))
|
||||
}}
|
||||
class="rounded-lg w-max transition-colors hover:bg-black/20 dark:hover:bg-white/20 p-2"
|
||||
>
|
||||
@@ -71,7 +71,7 @@
|
||||
{/if}
|
||||
<button
|
||||
onclick={() => {
|
||||
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
|
||||
toasts.update(toasts => toasts.filter(t => t.id != toast.id))
|
||||
}}
|
||||
class="rounded-lg w-max transition-colors hover:bg-black/20 dark:hover:bg-white/20 p-2"
|
||||
>
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
import Toast from './Toast.svelte'
|
||||
import { flip } from 'svelte/animate'
|
||||
import { toasts } from './toasts.js'
|
||||
import { backInOut, backOut, expoOut } from 'svelte/easing'
|
||||
import { expoOut } 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-96 pointer-events-none gap-4"
|
||||
>
|
||||
{#each $toasts as toast, index (toast.id)}
|
||||
{#each $toasts as toast (toast.id)}
|
||||
<div
|
||||
animate:flip={{ duration: 500, easing: expoOut }}
|
||||
class="pointer-events-auto transition-all
|
||||
|
||||
@@ -18,7 +18,7 @@ export interface Toast {
|
||||
content: string
|
||||
type: ToastType
|
||||
loading?: boolean
|
||||
action?: () => any
|
||||
action?: () => void
|
||||
}
|
||||
|
||||
export const toasts = writable<Toast[]>([])
|
||||
@@ -36,11 +36,11 @@ export function toast({
|
||||
type?: ToastType
|
||||
duration?: number
|
||||
loading?: boolean
|
||||
action?: () => any
|
||||
action?: () => void
|
||||
}) {
|
||||
let id = 0
|
||||
|
||||
toasts.update((toasts) => {
|
||||
toasts.update(toasts => {
|
||||
id = Math.floor(Math.random() * 10000)
|
||||
|
||||
return [
|
||||
@@ -57,11 +57,11 @@ export function toast({
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
||||
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))
|
||||
toasts.update(toasts => toasts.filter(toast => toast.id != id))
|
||||
@@ -1,5 +1,6 @@
|
||||
export const debounce = (fn: Function, ms = 300) => {
|
||||
let timeoutId: ReturnType<typeof setTimeout>
|
||||
// eslint-disable-next-line
|
||||
return function (this: any, ...args: any[]) {
|
||||
clearTimeout(timeoutId)
|
||||
timeoutId = setTimeout(() => fn.apply(this, args), ms)
|
||||
|
||||
Reference in new issue
Block a user