1
0
Fork 0
mirror of synced 2024-09-18 10:20:11 +12:00
budibase/packages/standard-components/src/Text.svelte

83 lines
1.6 KiB
Svelte
Raw Normal View History

<script>
import { getContext } from "svelte"
2021-06-11 22:37:05 +12:00
const { styleable, builderStore } = getContext("sdk")
const component = getContext("component")
2021-06-11 22:37:05 +12:00
export let text
export let color
export let align
export let bold
export let italic
export let underline
export let size
2021-06-11 22:37:05 +12:00
$: placeholder = $builderStore.inBuilder && !text
$: componentText = $builderStore.inBuilder
2021-06-30 19:46:02 +12:00
? text || $component.name || "Placeholder text"
2021-06-11 22:37:05 +12:00
: text || ""
$: sizeClass = `spectrum-Body--size${size || "M"}`
$: alignClass = `align--${align || "left"}`
// Add color styles to main styles object, otherwise the styleable helper
// overrides the color when it's passed as inline style.
$: styles = enrichStyles($component.styles, color)
const enrichStyles = (styles, color) => {
if (!color) {
return styles
}
return {
...styles,
normal: {
...styles?.normal,
color,
},
}
}
</script>
<p
use:styleable={styles}
class:placeholder
class:bold
class:italic
class:underline
class="spectrum-Body {sizeClass} {alignClass}"
>
2021-06-11 22:37:05 +12:00
{componentText}
</p>
<style>
2021-02-23 23:04:07 +13:00
p {
display: inline-block;
2021-02-23 23:04:07 +13:00
white-space: pre-wrap;
margin: 0;
}
2021-06-11 22:37:05 +12:00
.placeholder {
font-style: italic;
color: var(--spectrum-global-color-gray-600);
}
.bold {
font-weight: 600;
}
.italic {
font-style: italic;
}
.underline {
text-decoration: underline;
}
.align--left {
text-align: left;
}
.align--center {
text-align: center;
}
.align--right {
text-align: right;
}
.align-justify {
text-align: justify;
}
</style>