-
Notifications
You must be signed in to change notification settings - Fork 485
/
Copy pathLink.svelte
63 lines (60 loc) · 1.53 KB
/
Link.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<script lang="ts">
import type { FormDataConvertible, Method, PreserveStateOption, SerializationArrayFormat } from '@inertiajs/core'
import { inertia } from '../index'
export let href: string
export let as: keyof HTMLElementTagNameMap = 'a'
export let data: Record<string, FormDataConvertible> = {}
export let method: Method = 'get'
export let replace: boolean = false
export let preserveScroll: PreserveStateOption = false
export let preserveState: PreserveStateOption | null = null
export let only: string[] = []
export let except: string[] = []
export let headers: Record<string, string> = {}
export let queryStringArrayFormat: SerializationArrayFormat = 'brackets'
export let formDataArrayFormat: SerializationArrayFormat = 'indices'
$: asProp = method !== 'get' ? 'button' : as.toLowerCase()
$: elProps =
{
a: { href },
button: { type: 'button' },
}[asProp] || {}
</script>
<!-- svelte-ignore a11y-no-static-element-interactions -->
<svelte:element
this={as}
use:inertia={{
...(as !== 'a' ? { href } : {}),
data,
method,
replace,
preserveScroll,
preserveState: preserveState ?? method !== 'get',
only,
except,
headers,
queryStringArrayFormat,
formDataArrayFormat,
}}
{...$$restProps}
{...elProps}
on:focus
on:blur
on:click
on:dblclick
on:mousedown
on:mousemove
on:mouseout
on:mouseover
on:mouseup
on:cancel-token
on:before
on:start
on:progress
on:finish
on:cancel
on:success
on:error
>
<slot />
</svelte:element>