Revert "perf: improve efficiency and performance"
This commit is contained in:
1 parent
7e188f218a
commit
4177b42fc2
32 files changed
+470
-248
No files matched your search
@@ -1,5 +1,11 @@
|
||||
<script lang="ts">
|
||||
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
|
||||
@@ -48,13 +54,13 @@
|
||||
|
||||
<span
|
||||
{...rest}
|
||||
class={[
|
||||
badgeRoundness[rounding],
|
||||
badgeColor[color],
|
||||
'px-2.5 py-1 text-xs font-medium flex items-center gap-1 ring-1 ring-inset',
|
||||
allowIconOnly && 'max-md:px-1.5 max-md:py-1.5',
|
||||
clazz,
|
||||
]}
|
||||
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
|
||||
]} {clazz}"
|
||||
title={label}
|
||||
>
|
||||
{@render icon?.()}
|
||||
|
||||
@@ -123,14 +123,14 @@
|
||||
role={href ? 'link' : 'button'}
|
||||
{href}
|
||||
{...rest}
|
||||
tabindex={disabled || loading ? -1 : undefined}
|
||||
tabindex={disabled ? -1 : undefined}
|
||||
class={[
|
||||
buttonColor[color],
|
||||
loading ? buttonColor.secondary : buttonColor[color],
|
||||
buttonSize[size],
|
||||
buttonRounding[rounding],
|
||||
buttonShadow[shadow],
|
||||
'text-sm transition-all font-medium cursor-pointer duration-75 disabled:opacity-50 disabled:pointer-events-none disabled:shadow-none',
|
||||
disabled || (loading && 'pointer-events-none opacity-50 shadow-none'),
|
||||
disabled && 'pointer-events-none opacity-50 shadow-none',
|
||||
alignment == 'center'
|
||||
? 'origin-center'
|
||||
: alignment == 'left'
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '../index.js'
|
||||
import { Check, Icon, Clipboard } from 'svelte-hero-icons'
|
||||
import { scale } from 'svelte/transition'
|
||||
|
||||
let copied = $state(false)
|
||||
|
||||
interface Props {
|
||||
/**
|
||||
* Show a copy button.
|
||||
*/
|
||||
value: string
|
||||
copy?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let { value, copy = true, class: clazz = '' }: Props = $props()
|
||||
</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
|
||||
{clazz}"
|
||||
>
|
||||
<pre class="overflow-auto max-w-full whitespace-nowrap w-max">
|
||||
{value}
|
||||
</pre>
|
||||
{#if copy}
|
||||
<Button
|
||||
size="square-md"
|
||||
color="tertiary"
|
||||
aria-label="Copy"
|
||||
onclick={() => {
|
||||
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 />
|
||||
</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 />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,58 @@
|
||||
<script lang="ts">
|
||||
import { createBubbler } from 'svelte/legacy'
|
||||
|
||||
const bubble = createBubbler()
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
type T = $$Generic
|
||||
|
||||
interface Props {
|
||||
value: T
|
||||
group: T
|
||||
inlineDescription?: boolean
|
||||
id?: string
|
||||
disabled?: boolean
|
||||
children?: import('svelte').Snippet
|
||||
description?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
value,
|
||||
group = $bindable(),
|
||||
inlineDescription = false,
|
||||
id = generateID(),
|
||||
disabled = false,
|
||||
children,
|
||||
description,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="font-normal cursor-pointer text-sm flex flex-row items-baseline gap-2"
|
||||
>
|
||||
<input
|
||||
{...rest}
|
||||
{id}
|
||||
type="radio"
|
||||
bind:group
|
||||
{value}
|
||||
onblur={bubble('blur-sm')}
|
||||
onchange={bubble('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"
|
||||
>
|
||||
{@render children?.()}
|
||||
{#if description}
|
||||
<span class="font-normal text-slate-600 dark:text-zinc-400">
|
||||
{@render description?.()}
|
||||
</span>
|
||||
{/if}
|
||||
</label>
|
||||
</div>
|
||||
@@ -0,0 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
interface Props {
|
||||
group?: string
|
||||
row?: boolean
|
||||
class?: string
|
||||
children?: import('svelte').Snippet<[{ group: string }]>
|
||||
}
|
||||
|
||||
let {
|
||||
group = generateID(),
|
||||
row = false,
|
||||
class: clazz = '',
|
||||
children,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
<div
|
||||
class="flex {row ? 'flex-row flex-wrap' : 'flex-col'} gap-4 {clazz || ''}"
|
||||
>
|
||||
{@render children?.({ group })}
|
||||
</div>
|
||||
</div>
|
||||
@@ -3,6 +3,7 @@
|
||||
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 Material } from './materials/Material.svelte'
|
||||
|
||||
@@ -17,6 +18,9 @@ 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 Popover } from './popover/Popover.svelte'
|
||||
export { default as Menu } from './popover/Menu.svelte'
|
||||
export { default as MenuDivider } from './popover/MenuDivider.svelte'
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
<script 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 {
|
||||
flip,
|
||||
@@ -55,7 +68,11 @@
|
||||
middleware: middleware,
|
||||
})
|
||||
|
||||
const customFloatingContent = (node: HTMLDivElement) => floatingContent(node)
|
||||
const customFloatingContent = (node: HTMLDivElement) => {
|
||||
// if (!canUseContents) return
|
||||
|
||||
floatingContent(node)
|
||||
}
|
||||
|
||||
const customFloatingRef = (node: HTMLDivElement) => {
|
||||
const n = node.children.item(0)
|
||||
@@ -67,13 +84,6 @@
|
||||
floatingRef(node)
|
||||
}
|
||||
}
|
||||
|
||||
// let previousFocus = $state<Element>()
|
||||
// function focusTrap(element: HTMLElement) {
|
||||
// previousFocus = document.activeElement ?? previousFocus
|
||||
|
||||
// svelteFocusTrap(element)
|
||||
// }
|
||||
</script>
|
||||
|
||||
<svelte:body
|
||||
@@ -95,6 +105,8 @@
|
||||
onkeydown={async e => {
|
||||
if (open && e.key == 'Escape') {
|
||||
open = false
|
||||
// @ts-expect-error svelte hell
|
||||
el?.firstChild.focus()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user