migrate: convert most components to svelte 5
This commit is contained in:
1 parent
d670f39f0a
commit
10ef4123da
225 files changed
+5441
-3341
No files matched your search
@@ -1,14 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import { browser } from '$app/environment'
|
||||
import { tick } from 'svelte'
|
||||
|
||||
export let label: string | undefined = undefined
|
||||
export let value: string
|
||||
export let required: boolean = false
|
||||
let textarea: HTMLTextAreaElement = $state()
|
||||
|
||||
let textarea: HTMLTextAreaElement
|
||||
|
||||
$: adjustHeight(value)
|
||||
async function adjustHeight(value: string) {
|
||||
await tick()
|
||||
if (textarea) {
|
||||
@@ -16,8 +13,25 @@
|
||||
textarea.style.height = `${textarea.scrollHeight}px` // Set height to the scrollHeight
|
||||
}
|
||||
}
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
label?: string | undefined
|
||||
value: string
|
||||
required?: boolean
|
||||
class?: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
label = undefined,
|
||||
value = $bindable(),
|
||||
required = false,
|
||||
class: clazz = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
run(() => {
|
||||
adjustHeight(value)
|
||||
})
|
||||
</script>
|
||||
|
||||
<label class="w-full">
|
||||
@@ -31,11 +45,11 @@
|
||||
{/if}
|
||||
<textarea
|
||||
bind:this={textarea}
|
||||
on:input={() => adjustHeight(value)}
|
||||
oninput={() => adjustHeight(value)}
|
||||
bind:value
|
||||
{required}
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
rows={1}
|
||||
class="font-semibold text-2xl focus:outline-none w-full bg-transparent resize-none {clazz}"
|
||||
/>
|
||||
></textarea>
|
||||
</label>
|
||||
@@ -13,9 +13,7 @@
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<Label text={label} class="mb-1">
|
||||
<slot name="label" />
|
||||
</Label>
|
||||
<Label text={label} class="mb-1" />
|
||||
<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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
export const parseURL = (href: string) => {
|
||||
try {
|
||||
return new URL(href)
|
||||
@@ -9,25 +9,38 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export let href: string
|
||||
export let highlight: boolean = false
|
||||
export let nowrap: boolean = false
|
||||
interface Props {
|
||||
href: string
|
||||
highlight?: boolean
|
||||
nowrap?: boolean
|
||||
children?: import('svelte').Snippet
|
||||
class?: string
|
||||
icon?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
$: richURL = $$slots.default ? undefined : parseURL(href)
|
||||
let {
|
||||
href,
|
||||
highlight = false,
|
||||
nowrap = false,
|
||||
children,
|
||||
class: clazz = '',
|
||||
icon,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let richURL = $derived(children ? undefined : parseURL(href))
|
||||
</script>
|
||||
|
||||
<a
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
{href}
|
||||
class="{highlight
|
||||
? 'text-blue-500'
|
||||
: ''} hover:underline max-w-full inline-flex items-center gap-1 {clazz}"
|
||||
>
|
||||
<slot name="icon" />
|
||||
<slot>
|
||||
{@render icon?.()}
|
||||
{#if children}{@render children()}{:else}
|
||||
<span
|
||||
class="flex relative gap-0 {nowrap
|
||||
? 'w-full whitespace-nowrap overflow-hidden text-ellipsis text-xs'
|
||||
@@ -52,5 +65,5 @@
|
||||
{href}
|
||||
{/if}
|
||||
</span>
|
||||
</slot>
|
||||
{/if}
|
||||
</a>
|
||||
@@ -1,8 +1,15 @@
|
||||
<script lang="ts">
|
||||
export let value: number
|
||||
export let min: number = 0
|
||||
export let max: number = 100
|
||||
export let step: number = 1
|
||||
import { createBubbler } from 'svelte/legacy'
|
||||
|
||||
const bubble = createBubbler()
|
||||
interface Props {
|
||||
value: number
|
||||
min?: number
|
||||
max?: number
|
||||
step?: number
|
||||
}
|
||||
|
||||
let { value = $bindable(), min = 0, max = 100, step = 1 }: Props = $props()
|
||||
</script>
|
||||
|
||||
<input
|
||||
@@ -11,10 +18,10 @@
|
||||
{min}
|
||||
{max}
|
||||
{step}
|
||||
on:change
|
||||
on:click
|
||||
on:keydown
|
||||
on:keypress
|
||||
onchange={bubble('change')}
|
||||
onclick={bubble('click')}
|
||||
onkeydown={bubble('keydown')}
|
||||
onkeypress={bubble('keypress')}
|
||||
class="w-full appearance-none h-2 cursor-pointer bg-slate-100 dark:bg-zinc-800
|
||||
rounded-full range"
|
||||
/>
|
||||
|
||||
@@ -1,24 +1,39 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { ChevronDown, Icon } from 'svelte-hero-icons'
|
||||
import { Button } from 'mono-svelte'
|
||||
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
type T = $$Generic
|
||||
export let options: T[]
|
||||
export let disabled: boolean[] = []
|
||||
export let optionNames: string[] = []
|
||||
export let selected: T
|
||||
export let headless: boolean = false
|
||||
|
||||
let clazz: string = ''
|
||||
export let buttonClazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
options: T[]
|
||||
disabled?: boolean[]
|
||||
optionNames?: string[]
|
||||
selected: T
|
||||
headless?: boolean
|
||||
class?: string
|
||||
buttonClazz?: string
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
}
|
||||
|
||||
let {
|
||||
options,
|
||||
disabled = [],
|
||||
optionNames = [],
|
||||
selected = $bindable(),
|
||||
headless = false,
|
||||
class: clazz = '',
|
||||
buttonClazz = '',
|
||||
children,
|
||||
}: Props = $props()
|
||||
|
||||
const dispatcher = createEventDispatcher<{ select: T }>()
|
||||
|
||||
$: {
|
||||
run(() => {
|
||||
dispatcher('select', selected)
|
||||
}
|
||||
})
|
||||
|
||||
let containerClass = `
|
||||
flex flex-row rtl:flex-row-reverse items-center w-max max-w-full overflow-auto
|
||||
@@ -57,7 +72,7 @@
|
||||
{#each options as option, index}
|
||||
<button
|
||||
class={buttonClass(selected == option)}
|
||||
on:click|preventDefault={() => (selected = option)}
|
||||
onclick={preventDefault(() => (selected = option))}
|
||||
disabled={disabled[index] ?? false}
|
||||
type="button"
|
||||
>
|
||||
@@ -65,9 +80,9 @@
|
||||
{#if headless && option == selected}
|
||||
<div
|
||||
class="absolute -bottom-1 left-0 w-full border-b-2 rounded-t-sm border-black dark:border-white"
|
||||
/>
|
||||
></div>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
<slot {selected} />
|
||||
{@render children?.({ selected })}
|
||||
Reference in new issue
Block a user