Does anyone know if its possible to add a icon to a workspaceaction.
I have the following manifest i would expext it was possible to add a icon to the metadata but that does not work.
{
type: 'workspaceAction',
kind: 'default',
name: 'Previous page',
alias: 'local.previousPage.action',
weight: 103,
api: () => import('./previous-page.js'),
meta: {
label: '<<<',
look: 'outline',
color: 'positive',
},
conditions: [
{
alias: 'Umb.Condition.WorkspaceAlias',
match: 'Umb.Workspace.Document',
},
],
}
Rockerby
(Richard Ockerby)
April 12, 2025, 12:05am
2
Nope - no option for icon. Here’s the render function for the workspace action button :
#renderButton() {
const label = this.#manifest?.meta.label
? this.localize.string(this.#manifest.meta.label)
: (this.#manifest?.name ?? '');
return html`
<uui-button
data-mark="workspace-action:${this.#manifest?.alias}"
.href=${this._href}
look=${this.#manifest?.meta.look ?? 'default'}
color=${this.#manifest?.meta.color ?? 'default'}
label=${this._additionalOptions ? label + '…' : label}
.disabled=${this._isDisabled}
.state=${this._buttonState}
@click=${this.#onClick}></uui-button>
`;
}
But you can render out whatever you fancy in that space by adding the element
to your manifest and pointing to a custom element. Here’s a full example:
Manifest:
{
type: 'workspaceAction',
kind: 'default',
name: 'Previous page',
alias: 'local.previousPage.action',
weight: 103,
element: () => import('./custom.element'),
api: () => import('./previous-page.js'),
meta: {
label: 'something',
look: 'outline',
color: 'positive'
},
conditions: [
{
alias: 'Umb.Condition.WorkspaceAlias',
match: 'Umb.Workspace.Document',
},
],
}
Custom element:
import { UmbElementMixin } from "@umbraco-cms/backoffice/element-api";
import { LitElement, html, customElement } from "@umbraco-cms/backoffice/external/lit";
@customElement('custom-element-name')
export class CustomElement extends UmbElementMixin(LitElement) {
render() {
return html`
<div>
<p style="background:pink; padding:10px">I'm custom!</p>
</div>
`;
}
}
export default CustomElement;
declare global {
interface HTMLElementTagNameMap {
'custom-element-name': CustomElement;
}
}
Rockerby
(Richard Ockerby)
April 12, 2025, 1:01am
3
I fell down a rabbit hole and wanted to get a working example for myself, so here’s a Gist for a workspace action, with a custom button that has an icon controlled by the meta
custom.element.ts
/*
* This file is a copy of the core version from https://github.com/umbraco/Umbraco-CMS/blob/6bca91a52fabfe96b7ede1837b908b33d78136ed/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-action/default/workspace-action-default-kind.element.ts
* with the addition of a document icon in the button!
*/
import type {
ManifestWorkspaceAction,
ManifestWorkspaceActionMenuItem,
MetaWorkspaceActionDefaultKind,
UmbWorkspaceActionDefaultKind,
This file has been truncated. show original
custom.workspace.action.ts
import { UMB_WORKSPACE_CONTEXT, UmbWorkspaceActionBase } from '@umbraco-cms/backoffice/workspace';
export default class CustomWorkspaceAction extends UmbWorkspaceActionBase {
async execute() {
// This gets called when the button is clicked!
const context = await this.getContext(UMB_WORKSPACE_CONTEXT);
let et = context.getEntityType();
console.log("ET", et);
}
}
manifest.ts
export const manifests: any = [
{
type: 'workspaceAction',
kind: 'default',
name: 'Previous page',
alias: 'local.previousPage.action',
weight: 103,
element: () => import('./custom.element'),
api: () => import('./custom.workspace.action'),
meta: {
This file has been truncated. show original
2 Likes