Hello ![]()
I am currently building a custom view for an item in the block grid in Bellissima (aka WebComponent era of the Umbraco backoffice)
I have a simple element/block type that contains two properties
- Heading (Textstring)
- Images (Media Picker - Limited to a max of two images)
Problem
When changing the order of the images in the media picker it does not update the images displayed, however printing the two GUID/Keys of the picked media items correctly display and update in the component.
Video
Questions
-
Should I be using
umb-imaging-thumbnailto help render out the picked image or using an alternative approach with some context that I need to consume to resolve/convert the picked GUID to an image URL ? -
Why when I drag and drop and change the order of the images or pick a new image to replace one, that it does not update the image rendered with
<umb-imaging-thumbnail>?
Code
manifest.ts
export const manifests: Array<UmbExtensionManifest> = [
{
name: "Block Preview - Images",
alias: "blockpreview.images",
type: "blockEditorCustomView",
forContentTypeAlias: "imagesBlock",
js: () => import("./images-block"),
}
];
images-block.ts
import { html, customElement, LitElement, property, css, when } from '@umbraco-cms/backoffice/external/lit';
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
import { type UmbBlockDataType } from '@umbraco-cms/backoffice/block';
import type { UmbBlockEditorCustomViewConfiguration, UmbBlockEditorCustomViewElement } from '@umbraco-cms/backoffice/block-custom-view';
import { commonStyles } from './common-styles';
@customElement('images-block-custom-view')
export class ImagesBlockCustomView extends UmbElementMixin(LitElement) implements UmbBlockEditorCustomViewElement {
@property({ attribute: false })
content?: UmbBlockDataType & {
images: Array<{ mediaKey: string }>;
}
@property({ attribute: false })
label?: string;
@property({ attribute: false })
settings?: UmbBlockDataType;
@property({ attribute: false })
config?: UmbBlockEditorCustomViewConfiguration;
constructor() {
super();
}
render() {
const leftImageMediaKey = this.content?.images?.[0]?.mediaKey ?? '';
const rightImageMediaKey = this.content?.images?.[1]?.mediaKey ?? '';
return html`
<fieldset>
<legend>${this.label ?? 'Images'}</legend>
<a href=${this.config?.editContentPath ?? ''} class="edit">
<figure>
<h2>${this.content?.heading}</h2>
<pre>
Left = ${leftImageMediaKey}
Right = ${rightImageMediaKey}
</pre>
<div id="grid">
<div>
${when(
leftImageMediaKey,
() => html`<umb-imaging-thumbnail .unique=${leftImageMediaKey!} width="600" mode="Crop"></umb-imaging-thumbnail>`,
() => html`<p>No image selected</p>`
)}
</div>
<div>
${when(
rightImageMediaKey,
() => html`<umb-imaging-thumbnail .unique=${rightImageMediaKey!} width="600" mode="Crop"></umb-imaging-thumbnail>`,
() => html`<p>No image selected</p>`
)}
</div>
</div>
</figure>
</a>
</fieldset>
<!-- <pre>${JSON.stringify(this.content, null, 2)}</pre> -->
`;
}
static styles = [
commonStyles,
css`
h2 {
color: var(--colour-black);
font-family: var(--font-family-bravo);
font-size: var(--font-size-heading-3);
text-align: center;
}
#grid {
display:grid;
grid-template-columns: 1fr 1fr;
gap: 24px;
div {
background: var(--colour-grey--mid-light);
}
p {
text-align: center;
}
}
`,
];
}
export default ImagesBlockCustomView;
declare global {
interface HTMLElementTagNameMap {
'images-block-custom-view': ImagesBlockCustomView;
}
}