Skip to content

Commit

Permalink
Canvas: tweak image component to fit all image sizes (#6705)
Browse files Browse the repository at this point in the history
  • Loading branch information
djbarnwal authored and grahamplata committed Feb 21, 2025
1 parent 681b0ff commit 61a7ff2
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions web-common/src/features/canvas/components/image/Image.svelte
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
<script lang="ts">
import ComponentError from "@rilldata/web-common/features/canvas/components/ComponentError.svelte";
import type { ImageProperties } from "@rilldata/web-common/features/templates/types";
import type { V1ComponentSpecRendererProperties } from "@rilldata/web-common/runtime-client";
import httpClient from "@rilldata/web-common/runtime-client/http-client";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
import type { ImageSpec } from "./";
export let rendererProperties: V1ComponentSpecRendererProperties;
const instanceId = $runtime.instanceId;
const DEFAULT_IMAGE_PROPERTIES: ImageProperties = {
url: "",
css: {
"object-fit": "contain",
opacity: "1",
filter: "blur(0px) saturate(1)",
},
};
$: imageProperties = {
...DEFAULT_IMAGE_PROPERTIES,
...rendererProperties,
css: {
...DEFAULT_IMAGE_PROPERTIES.css,
...rendererProperties.css,
},
} as ImageProperties;
$: styleString = Object.entries(imageProperties.css || {})
.map(([k, v]) => `${k}:${v}`)
.join(";");
$: imageProperties = rendererProperties as ImageSpec;
let imageSrc: string | null = null;
let errorMessage: string | null = null;
Expand All @@ -37,7 +17,7 @@
fetchImage(imageProperties.url);
} else {
imageSrc = null;
errorMessage = null;
errorMessage = "No image URL provided";
}
}
Expand Down Expand Up @@ -80,10 +60,12 @@
{#if errorMessage}
<ComponentError error={errorMessage} />
{:else}
<img
src={imageSrc || ""}
alt={"Dashboard Image"}
draggable="false"
style={styleString}
/>
<div class="flex items-center justify-center h-full w-full">
<img
src={imageSrc || ""}
alt={"Canvas Image"}
draggable="false"
class="h-full w-full object-contain"
/>
</div>
{/if}

0 comments on commit 61a7ff2

Please sign in to comment.