2020-02-14 12:51:45 +01:00
|
|
|
<script>
|
2020-11-18 20:18:18 +01:00
|
|
|
import { getContext } from "svelte"
|
2021-06-30 21:09:26 +02:00
|
|
|
import "@spectrum-css/typography/dist/index-vars.css"
|
2020-11-18 20:18:18 +01:00
|
|
|
|
2021-06-11 12:37:05 +02:00
|
|
|
const { styleable, builderStore } = getContext("sdk")
|
2020-11-24 12:02:10 +01:00
|
|
|
const component = getContext("component")
|
2020-11-17 13:08:24 +01:00
|
|
|
|
2021-06-11 12:37:05 +02:00
|
|
|
export let text
|
2021-06-23 15:21:37 +02:00
|
|
|
export let color
|
|
|
|
export let align
|
|
|
|
export let bold
|
|
|
|
export let italic
|
|
|
|
export let underline
|
|
|
|
export let size
|
2021-06-11 12:37:05 +02:00
|
|
|
|
|
|
|
$: placeholder = $builderStore.inBuilder && !text
|
|
|
|
$: componentText = $builderStore.inBuilder
|
2021-06-30 09:46:02 +02:00
|
|
|
? text || $component.name || "Placeholder text"
|
2021-06-11 12:37:05 +02:00
|
|
|
: text || ""
|
2021-06-30 21:09:26 +02:00
|
|
|
$: sizeClass = `spectrum-Heading--size${size || "M"}`
|
|
|
|
$: alignClass = `align--${align || "left"}`
|
2021-06-23 15:21:37 +02:00
|
|
|
|
|
|
|
// Add color styles to main styles object, otherwise the styleable helper
|
|
|
|
// overrides the color when it's passed as inline style.
|
2021-07-01 01:47:38 +02:00
|
|
|
$: styles = enrichStyles($component.styles, color)
|
|
|
|
|
|
|
|
const enrichStyles = (styles, color) => {
|
|
|
|
if (!color) {
|
|
|
|
return styles
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...styles,
|
|
|
|
normal: {
|
|
|
|
...styles?.normal,
|
|
|
|
color,
|
|
|
|
},
|
|
|
|
}
|
2021-06-23 15:21:37 +02:00
|
|
|
}
|
2020-02-14 12:51:45 +01:00
|
|
|
</script>
|
|
|
|
|
2021-06-23 15:21:37 +02:00
|
|
|
<h1
|
|
|
|
use:styleable={styles}
|
|
|
|
class:placeholder
|
|
|
|
class:bold
|
|
|
|
class:italic
|
|
|
|
class:underline
|
2021-06-30 21:09:26 +02:00
|
|
|
class="spectrum-Heading {sizeClass} {alignClass}"
|
2021-06-23 15:21:37 +02:00
|
|
|
>
|
2021-06-30 21:09:26 +02:00
|
|
|
{componentText}
|
2021-06-23 15:21:37 +02:00
|
|
|
</h1>
|
2021-02-23 11:02:21 +01:00
|
|
|
|
|
|
|
<style>
|
2021-06-23 15:21:37 +02:00
|
|
|
h1 {
|
2021-02-23 11:02:21 +01:00
|
|
|
white-space: pre-wrap;
|
2021-06-23 15:21:37 +02:00
|
|
|
font-weight: 600;
|
2021-02-23 11:02:21 +01:00
|
|
|
}
|
2021-06-11 12:37:05 +02:00
|
|
|
.placeholder {
|
|
|
|
font-style: italic;
|
2021-07-05 15:02:49 +02:00
|
|
|
color: var(--spectrum-global-color-gray-600);
|
2021-06-11 12:37:05 +02:00
|
|
|
}
|
2021-06-23 15:21:37 +02:00
|
|
|
.bold {
|
|
|
|
font-weight: 700;
|
|
|
|
}
|
|
|
|
.italic {
|
|
|
|
font-style: italic;
|
|
|
|
}
|
|
|
|
.underline {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
2021-06-30 21:09:26 +02:00
|
|
|
|
2021-06-23 15:21:37 +02:00
|
|
|
.align--left {
|
|
|
|
text-align: left;
|
|
|
|
}
|
|
|
|
.align--center {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
.align--right {
|
|
|
|
text-align: right;
|
|
|
|
}
|
|
|
|
.align-justify {
|
|
|
|
text-align: justify;
|
|
|
|
}
|
2021-02-23 11:02:21 +01:00
|
|
|
</style>
|