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