1
0
Fork 0
mirror of synced 2024-09-18 02:08:34 +12:00
budibase/packages/standard-components/src/Link.svelte

106 lines
2 KiB
Svelte
Raw Normal View History

2020-02-21 06:06:50 +13:00
<script>
import { getContext } from "svelte"
const { linkable, styleable, builderStore } = getContext("sdk")
const component = getContext("component")
export let url
export let text
export let openInNewTab
export let color
export let align
export let bold
export let italic
export let underline
export let size
2020-02-26 04:21:23 +13:00
$: external = url && !url.startsWith("/")
2020-02-26 04:21:23 +13:00
$: target = openInNewTab ? "_blank" : "_self"
$: placeholder = $builderStore.inBuilder && !text
$: componentText = $builderStore.inBuilder
? text || "Placeholder link"
: text || ""
// Add color styles to main styles object, otherwise the styleable helper
// overrides the color when it's passed as inline style.
$: styles = {
...$component.styles,
normal: {
...$component.styles?.normal,
color,
},
}
2020-02-21 06:06:50 +13:00
</script>
{#if $builderStore.inBuilder || componentText}
{#if external}
<a
{target}
href={url || "/"}
use:styleable={styles}
class:placeholder
class:bold
class:italic
class:underline
class="align--{align || 'left'} size--{size || 'M'}"
>
{componentText}
</a>
{:else}
<a
use:linkable
href={url || "/"}
use:styleable={styles}
class:placeholder
class:bold
class:italic
class:underline
class="align--{align || 'left'} size--{size || 'M'}"
>
{componentText}
</a>
{/if}
2021-02-26 22:58:24 +13:00
{/if}
<style>
a {
color: var(--spectrum-alias-text-color);
display: inline-block;
white-space: pre-wrap;
}
.placeholder {
font-style: italic;
color: var(--grey-6);
}
.bold {
font-weight: 600;
}
.italic {
font-style: italic;
}
.underline {
text-decoration: underline;
}
.size--S {
font-size: 14px;
}
.size--M {
font-size: 16px;
}
.size--L {
font-size: 18px;
}
.align--left {
text-align: left;
}
.align--center {
text-align: center;
}
.align--right {
text-align: right;
}
.align-justify {
text-align: justify;
}
</style>