flotilla/src/lib/components/Link.svelte

40 lines
764 B
Svelte
Raw Normal View History

2024-08-08 23:32:46 +00:00
<script lang="ts">
import type {Snippet} from "svelte"
2024-10-15 19:02:11 +00:00
import {goto} from "$app/navigation"
2025-02-04 03:28:29 +00:00
import {stopPropagation} from "@lib/html"
2024-08-08 23:32:46 +00:00
const {
children,
href,
external = false,
replaceState = false,
...restProps
}: {
children: Snippet
2025-02-04 00:37:14 +00:00
href: string
external?: boolean
replaceState?: boolean
disabled?: boolean
class?: string
2026-01-22 20:37:30 +00:00
'data-tip'?: string
} = $props()
2024-10-11 22:29:54 +00:00
const go = (e: Event) => {
if (!external) {
e.preventDefault()
2024-10-24 18:52:02 +00:00
goto(href, {replaceState})
}
}
2024-08-08 23:32:46 +00:00
</script>
<a
{href}
2025-02-04 00:37:14 +00:00
{...restProps}
onclick={stopPropagation(go)}
2025-02-04 00:37:14 +00:00
class="cursor-pointer {restProps.class}"
2024-08-08 23:32:46 +00:00
rel={external ? "noopener noreferer" : ""}
target={external ? "_blank" : ""}>
{@render children?.()}
2024-08-08 23:32:46 +00:00
</a>