Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: expose button for block custom views #17577

Open
wants to merge 1 commit into
base: v15/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Umbraco.Web.UI.Client/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"backoffice",
"Backoffice",
"combobox",
"contenteditable",
"ctrls",
"devs",
"Dropcursor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,16 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
if (ext.component) {
ext.component.classList.add('umb-block-grid__block--view');
}
return ext.component;
if (this._exposed) {
return ext.component;
} else {
return html`<div>
${ext.component}
<umb-block-overlay-expose-button
.contentTypeName=${this._contentTypeName}
@click=${this.#expose}></umb-block-overlay-expose-button>
</div>`;
}
};

#renderInlineEditBlock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
ManifestBlockEditorCustomView,
UmbBlockEditorCustomViewProperties,
} from '@umbraco-cms/backoffice/block-custom-view';
import type { UmbExtensionElementInitializer } from '@umbraco-cms/backoffice/extension-api';

/**
* @element umb-block-list-entry
Expand Down Expand Up @@ -277,6 +278,19 @@ export class UmbBlockListEntryElement extends UmbLitElement implements UmbProper
return true;
};

#extensionSlotRenderMethod = (ext: UmbExtensionElementInitializer<ManifestBlockEditorCustomView>) => {
if (this._exposed) {
return ext.component;
} else {
return html`<div>
${ext.component}
<umb-block-overlay-expose-button
.contentTypeName=${this._contentTypeName}
@click=${this.#expose}></umb-block-overlay-expose-button>
</div>`;
}
};

#renderRefBlock() {
return html`<umb-ref-list-block
.label=${this._label}
Expand Down Expand Up @@ -305,6 +319,7 @@ export class UmbBlockListEntryElement extends UmbLitElement implements UmbProper
<umb-extension-slot
type="blockEditorCustomView"
default-element=${this._inlineEditingMode ? 'umb-inline-list-block' : 'umb-ref-list-block'}
.renderMethod=${this.#extensionSlotRenderMethod}
.props=${this._blockViewProps}
.filter=${this.#extensionSlotFilterMethod}
single
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { stringOrStringArrayContains } from '@umbraco-cms/backoffice/utils';
import '../ref-rte-block/index.js';
import { UmbObserveValidationStateController } from '@umbraco-cms/backoffice/validation';
import { UmbDataPathBlockElementDataQuery } from '@umbraco-cms/backoffice/block';
import type { UmbExtensionElementInitializer } from '@umbraco-cms/backoffice/extension-api';

/**
* @class UmbBlockRteEntryElement
Expand Down Expand Up @@ -242,12 +243,26 @@ export class UmbBlockRteEntryElement extends UmbLitElement implements UmbPropert
this.#context.expose();
};

#extensionSlotRenderMethod = (ext: UmbExtensionElementInitializer<ManifestBlockEditorCustomView>) => {
if (this._exposed) {
return ext.component;
} else {
return html`<div>
${ext.component}
<umb-block-overlay-expose-button
.contentTypeName=${this._contentTypeName}
@click=${this.#expose}></umb-block-overlay-expose-button>
</div>`;
}
};

#renderBlock() {
return html`
<div class="uui-text uui-font">
<umb-extension-slot
type="blockEditorCustomView"
default-element="umb-ref-rte-block"
.renderMethod=${this.#extensionSlotRenderMethod}
.props=${this._blockViewProps}
.filter=${this.#filterBlockCustomViews}
single>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { css, customElement, html, nothing, property } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';

/**
* @description
* This element is used to render a expose button that goes on top of a block.
*/
@customElement('umb-block-overlay-expose-button')
export class UmbBlockOverlayExposeButtonElement extends UmbLitElement {
@property({ attribute: false })
contentTypeName?: string;

override render() {
return this.contentTypeName
? html`<uui-button look="secondary"
><uui-icon name="icon-add"></uui-icon>
<umb-localize key="blockEditor_createThisFor" .args=${[this.contentTypeName]}></umb-localize
></uui-button>`
: nothing;
}

static override styles = [
css`
:host {
position: absolute;
inset: 0;
}

uui-button {
position: absolute;
inset: 0;
opacity: 0.8;
}

:host:hover uui-button {
opacity: 1;
}
`,
];
}

export default UmbBlockOverlayExposeButtonElement;

declare global {
interface HTMLElementTagNameMap {
'umb-block-overlay-expose-button': UmbBlockOverlayExposeButtonElement;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './block-overlay-expose-button/block-overlay-expose-button.element.js';
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './components/index.js';
export * from './context/index.js';
export * from './modals/index.js';
export * from './property-value-resolver/index.js';
Expand Down
Loading