-
-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathLink.svelte
86 lines (78 loc) · 1.98 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<script>
/** @restProps {a | p} */
/**
* Specify the size of the link
* @type {"sm" | "lg"}
*/
export let size = undefined;
/**
* Specify the href value
* @type {string}
*/
export let href = undefined;
/** Set to `true` to use the inline variant */
export let inline = false;
/**
* Specify the icon to render
* `inline` must be `false`
* @type {typeof import("svelte").SvelteComponent<any>}
*/
export let icon = undefined;
/** Set to `true` to disable the checkbox */
export let disabled = false;
/** Set to `true` to allow visited styles */
export let visited = false;
/** Obtain a reference to the top-level HTML element */
export let ref = null;
</script>
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
{#if disabled}
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<p
bind:this="{ref}"
class:bx--link="{true}"
class:bx--link--disabled="{disabled}"
class:bx--link--inline="{inline}"
class:bx--link--visited="{visited}"
{...$$restProps}
on:click
on:mouseover
on:mouseenter
on:mouseleave
>
<slot />
{#if !inline && ($$slots.icon || icon)}
<div class:bx--link__icon="{true}">
<slot name="icon">
<svelte:component this="{icon}" />
</slot>
</div>
{/if}
</p>
{:else}
<a
bind:this="{ref}"
class:bx--link="{true}"
class:bx--link--disabled="{disabled}"
class:bx--link--inline="{inline}"
class:bx--link--visited="{visited}"
class:bx--link--sm="{size === 'sm'}"
class:bx--link--lg="{size === 'lg'}"
rel="{$$restProps.target === '_blank' ? 'noopener noreferrer' : undefined}"
href="{href}"
{...$$restProps}
on:click
on:mouseover
on:mouseenter
on:mouseleave
>
<slot />
{#if !inline && ($$slots.icon || icon)}
<div class:bx--link__icon="{true}">
<slot name="icon">
<svelte:component this="{icon}" />
</slot>
</div>
{/if}
</a>
{/if}