Add size styles and placeholder to image component

This commit is contained in:
Andrew Kingston 2021-06-25 15:29:24 +01:00
parent 79b3732ef4
commit 1599c8433d
3 changed files with 24 additions and 15 deletions

View File

@ -729,6 +729,7 @@
"description": "A basic component for displaying images",
"icon": "Image",
"illegalChildren": ["section"],
"styles": ["size"],
"settings": [
{
"type": "text",

View File

@ -1,21 +1,29 @@
<script>
import { getContext } from "svelte"
import Placeholder from "./Placeholder.svelte"
const { styleable } = getContext("sdk")
const component = getContext("component")
export let className = ""
export let url = ""
export let description = ""
export let height
export let width
export let url
</script>
<img
{height}
{width}
class={className}
src={url}
alt={description}
use:styleable={$component.styles}
/>
{#if url}
<img src={url} alt={$component.name} use:styleable={$component.styles} />
{:else}
<div
class="placeholder"
use:styleable={{ ...$component.styles, empty: true }}
>
<Placeholder />
</div>
{/if}
<style>
.placeholder {
display: grid;
place-items: center;
height: 75px;
width: 150px;
}
</style>

View File

@ -4,12 +4,12 @@
const { builderStore } = getContext("sdk")
const component = getContext("component")
export let text = $component.name || "Placeholder"
export let text
</script>
{#if $builderStore.inBuilder}
<div>
{text}
{text || $component.name || "Placeholder"}
</div>
{/if}