Rework conditions for Button

- Was prefetching mailto links, so needs to detect if url string is starting
- Check if it actually has slots, then add a class
This commit is contained in:
2022-08-01 18:09:51 +02:00
parent 01859031aa
commit 54dc1a24ff

View File

@@ -19,14 +19,14 @@
className,
effect ? effect : undefined,
...[color, size].map(variant => variant && `${className}--${variant}`),
$$slots ? `has-icon-${slotPosition}` : undefined,
Object.keys($$slots).length !== 0 ? `has-icon-${slotPosition}` : undefined,
$$props.class
].join(' ').trim()
// Define external links
let rel: string, target: string
$: isExternal = /(http(s?)):\/\//i.test(url)
$: rel = isExternal ? 'external noopener noreferrer' : null
$: isExternal = /^(http|https):\/\//i.test(url)
$: isProtocol = /^(mailto|tel):/i.test(url)
$: rel = isExternal ? 'external noopener' : null
$: target = isExternal ? '_blank' : null
</script>
@@ -43,9 +43,9 @@
{:else if tag === 'a'}
<a
href={url} class={classes}
{rel} {target}
sveltekit:prefetch={url && isExternal ? null : true}
sveltekit:noscroll={isExternal ? null : true}
{target} {rel}
sveltekit:prefetch={url && (isExternal || isProtocol) ? null : true}
sveltekit:noscroll={isExternal || isProtocol ? null : true}
{disabled}
tabindex="0"
on:click