Skip to content

Commit 26eaa66

Browse files
committed
Add linkable component
1 parent e690337 commit 26eaa66

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<script lang="ts">
2+
import { cn } from '@/utils';
3+
import type { Snippet } from 'svelte';
4+
import { Button } from '$lib/components/ui/button';
5+
import { IconHash } from '@tabler/icons-svelte';
6+
7+
let {
8+
id,
9+
children,
10+
class: className,
11+
...restProps
12+
}: {
13+
id: string;
14+
children: Snippet;
15+
class?: string;
16+
} = $props();
17+
18+
let buttonVisible = $state(false);
19+
20+
function onMouseEnter() {
21+
buttonVisible = true;
22+
}
23+
24+
function onMouseLeave() {
25+
buttonVisible = false;
26+
}
27+
28+
function gotoLink() {
29+
window.location.hash = id;
30+
}
31+
</script>
32+
33+
<div
34+
class={cn('relative flex scroll-mt-24 items-center', className)}
35+
{...restProps}
36+
{id}
37+
onmouseenter={onMouseEnter}
38+
onmouseleave={onMouseLeave}
39+
>
40+
{@render children()}
41+
<div class="relative flex items-center">
42+
<div class="absolute h-12 w-12"></div>
43+
<Button
44+
class="hover:text-foreground absolute left-2 h-8 w-8 text-blue-500 transition-all
45+
hover:cursor-pointer {buttonVisible ? 'opacity-100' : 'opacity-0'}"
46+
variant="outline"
47+
size="icon"
48+
onclick={gotoLink}
49+
>
50+
<IconHash />
51+
</Button>
52+
</div>
53+
</div>

0 commit comments

Comments
 (0)