I started working with Umbraco 15 and implementing Block Grid backoffice view following this tutorial: Custom Views for Block List | Umbraco CMS
But property:
@property({ attribute: false })
settings?: UmbBlockDataType;
Is always undefined.
This is my module:
import { html, customElement, LitElement, property } from '@umbraco-cms/backoffice/external/lit';
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
import type { UmbBlockEditorCustomViewElement } from '@umbraco-cms/backoffice/block-custom-view';
import { type UmbBlockDataType } from '@umbraco-cms/backoffice/block';
// UmbBlockDataType
@customElement('button-component')
export class ButtonBlockCustomView extends UmbElementMixin(LitElement) implements UmbBlockEditorCustomViewElement {
@property({ attribute: false })
content?: UmbBlockDataType;
@property({ attribute: false })
settings?: UmbBlockDataType;
getSizeFromSettings(size:string) {
if (!size || size.trim() === '') return '';
switch (size) {
case 'large':
return ' btn--lg';
case 'medium':
return ' btn--md';
case 'small':
return ' btn--sm';
default:
return '';
}
}
override render() {
debugger;
const sizeClass = this.getSizeFromSettings(this.settings?.size as string);
const link: {name: string}[] = this.content?.link as {name: string}[];
return html`
<link rel="stylesheet" href="/assets/css/styles/allstyles.css" />
<a class="btn btn--primary ${sizeClass}">
${link[0].name
? html`<span>${link[0].name}</span>`
: ''}
${this.settings?.buttonArrow
? html`
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none">
<path
fill="#1C2541"
fill-rule="evenodd"
d="M12.075 5.576a.6.6 0 0 0 0 .848l4.976 4.976H6a.6.6 0 1 0 0 1.2H17.05l-4.976 4.976a.6.6 0 0 0 .849.848l6-6a.6.6 0 0 0 0-.848l-6-6a.6.6 0 0 0-.849 0Z"
clip-rule="evenodd"
></path>
</svg>
`
: ''}
</a>
`;
}
}
export default ButtonBlockCustomView;
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/115085-umbraco-block-grid-backoffice-custom-view-the-settings-property-is-always-undefined-for-umbraco-15