Skip to content

Commit b81d459

Browse files
ability to hide block actions (#19626)
Co-authored-by: Mads Rasmussen <[email protected]>
1 parent df39026 commit b81d459

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

src/Umbraco.Web.UI.Client/src/packages/block/block-grid/components/block-grid-entry/block-grid-entry.element.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
9292
@state()
9393
_unsupported?: boolean;
9494

95+
@state()
96+
_showActions?: boolean;
97+
9598
@state()
9699
_workspaceEditContentPath?: string;
97100

@@ -214,6 +217,13 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
214217
},
215218
null,
216219
);
220+
this.observe(
221+
this.#context.actionsVisibility,
222+
(showActions) => {
223+
this._showActions = showActions;
224+
},
225+
null,
226+
);
217227

218228
this.observe(
219229
this.#context.inlineEditingMode,
@@ -546,12 +556,14 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
546556
}
547557

548558
#renderActionBar() {
549-
return html`
550-
<uui-action-bar>
551-
${this.#renderEditAction()} ${this.#renderEditSettingsAction()} ${this.#renderCopyToClipboardAction()}
552-
${this.#renderDeleteAction()}</uui-action-bar
553-
>
554-
`;
559+
return this._showActions
560+
? html`
561+
<uui-action-bar>
562+
${this.#renderEditAction()} ${this.#renderEditSettingsAction()} ${this.#renderCopyToClipboardAction()}
563+
${this.#renderDeleteAction()}</uui-action-bar
564+
>
565+
`
566+
: nothing;
555567
}
556568

557569
#renderEditAction() {

src/Umbraco.Web.UI.Client/src/packages/block/block-list/components/block-list-entry/block-list-entry.element.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ export class UmbBlockListEntryElement extends UmbLitElement implements UmbProper
8484
@state()
8585
_unsupported?: boolean;
8686

87+
@state()
88+
_showActions?: boolean;
89+
8790
@state()
8891
_workspaceEditContentPath?: string;
8992

@@ -178,6 +181,13 @@ export class UmbBlockListEntryElement extends UmbLitElement implements UmbProper
178181
},
179182
null,
180183
);
184+
this.observe(
185+
this.#context.actionsVisibility,
186+
(showActions) => {
187+
this._showActions = showActions;
188+
},
189+
null,
190+
);
181191
this.observe(
182192
this.#context.inlineEditingMode,
183193
(mode) => {
@@ -412,10 +422,7 @@ export class UmbBlockListEntryElement extends UmbLitElement implements UmbProper
412422
single
413423
>${this.#renderBuiltinBlockView()}</umb-extension-slot
414424
>
415-
<uui-action-bar>
416-
${this.#renderEditContentAction()} ${this.#renderEditSettingsAction()}
417-
${this.#renderCopyToClipboardAction()} ${this.#renderDeleteAction()}
418-
</uui-action-bar>
425+
${this.#renderActionBar()}
419426
${!this._showContentEdit && this._contentInvalid
420427
? html`<uui-badge attention color="invalid" label="Invalid content">!</uui-badge>`
421428
: nothing}
@@ -424,6 +431,15 @@ export class UmbBlockListEntryElement extends UmbLitElement implements UmbProper
424431
: nothing;
425432
}
426433

434+
#renderActionBar() {
435+
return this._showActions
436+
? html`<uui-action-bar>
437+
${this.#renderEditContentAction()} ${this.#renderEditSettingsAction()} ${this.#renderCopyToClipboardAction()}
438+
${this.#renderDeleteAction()}
439+
</uui-action-bar>`
440+
: nothing;
441+
}
442+
427443
#renderEditContentAction() {
428444
return this._showContentEdit && this._workspaceEditContentPath
429445
? html`<uui-button

src/Umbraco.Web.UI.Client/src/packages/block/block-rte/components/block-rte-entry/block-rte-entry.element.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ export class UmbBlockRteEntryElement extends UmbLitElement implements UmbPropert
5959
@state()
6060
_exposed?: boolean;
6161

62+
@state()
63+
_showActions?: boolean;
64+
6265
@state()
6366
_workspaceEditContentPath?: string;
6467

@@ -158,6 +161,14 @@ export class UmbBlockRteEntryElement extends UmbLitElement implements UmbPropert
158161
},
159162
null,
160163
);
164+
165+
this.observe(
166+
this.#context.actionsVisibility,
167+
(showActions) => {
168+
this._showActions = showActions;
169+
},
170+
null,
171+
);
161172
// Data props:
162173
this.observe(
163174
this.#context.layout,
@@ -269,7 +280,7 @@ export class UmbBlockRteEntryElement extends UmbLitElement implements UmbPropert
269280
single>
270281
${this.#renderRefBlock()}
271282
</umb-extension-slot>
272-
<uui-action-bar> ${this.#renderEditAction()} ${this.#renderEditSettingsAction()} </uui-action-bar>
283+
${this.#renderActionBar()}
273284
${!this._showContentEdit && this._contentInvalid
274285
? html`<uui-badge attention color="invalid" label="Invalid content">!</uui-badge>`
275286
: nothing}
@@ -278,6 +289,12 @@ export class UmbBlockRteEntryElement extends UmbLitElement implements UmbPropert
278289
: nothing;
279290
}
280291

292+
#renderActionBar() {
293+
return this._showActions
294+
? html` <uui-action-bar> ${this.#renderEditAction()} ${this.#renderEditSettingsAction()}</uui-action-bar> `
295+
: nothing;
296+
}
297+
281298
#renderRefBlock() {
282299
return html`<umb-ref-rte-block
283300
.label=${this._label}

src/Umbraco.Web.UI.Client/src/packages/block/block/context/block-entry.context.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ export abstract class UmbBlockEntryContext<
6565
#hasExpose = new UmbBooleanState(undefined);
6666
readonly hasExpose = this.#hasExpose.asObservable();
6767

68+
#actionsVisibility = new UmbBooleanState(true);
69+
readonly actionsVisibility = this.#actionsVisibility.asObservable();
70+
71+
hideActions() {
72+
this.#actionsVisibility.setValue(false);
73+
}
74+
showActions() {
75+
this.#actionsVisibility.setValue(true);
76+
}
77+
6878
public readonly readOnlyGuard = new UmbReadOnlyVariantGuardManager(this);
6979

7080
// Workspace alike methods, to enables editing of data without the need of a workspace (Custom views and block grid inline editing mode for example).

0 commit comments

Comments
 (0)