diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/index.ts b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/index.ts index f851e0b3cb..11809199a6 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/index.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/index.ts @@ -4,4 +4,5 @@ export * from './workspace-action/index.js'; export * from './workspace-editor/index.js'; export * from './workspace-entity-action-menu/index.js'; export * from './workspace-footer/index.js'; +export * from './workspace-name/index.js'; export * from './workspace-split-view/index.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-name/index.ts b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-name/index.ts new file mode 100644 index 0000000000..e1aaff695b --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-name/index.ts @@ -0,0 +1 @@ +export * from './workspace-name.element.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-name/workspace-name.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-name/workspace-name.element.ts new file mode 100644 index 0000000000..4b9e80882e --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-name/workspace-name.element.ts @@ -0,0 +1,72 @@ +import { UMB_NAMABLE_WORKSPACE_CONTEXT } from '../../namable/index.js'; +import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; +import { css, html, customElement, state } from '@umbraco-cms/backoffice/external/lit'; +import { umbFocus, UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; +import type { UUIInputElement } from '@umbraco-cms/backoffice/external/uui'; +import { UUIInputEvent } from '@umbraco-cms/backoffice/external/uui'; +import { umbBindToValidation } from '@umbraco-cms/backoffice/validation'; + +@customElement('umb-workspace-name') +export class UmbWorkspaceNameElement extends UmbLitElement { + @state() + private _name = ''; + + #workspaceContext?: typeof UMB_NAMABLE_WORKSPACE_CONTEXT.TYPE; + + constructor() { + super(); + + this.consumeContext(UMB_NAMABLE_WORKSPACE_CONTEXT, (workspaceContext) => { + this.#workspaceContext = workspaceContext; + this.#observeName(); + }); + } + + #observeName() { + if (!this.#workspaceContext) return; + this.observe(this.#workspaceContext.name, (name) => { + if (name !== this._name) { + this._name = name ?? ''; + } + }); + } + + #onNameInput(event: UUIInputEvent) { + if (event instanceof UUIInputEvent) { + const target = event.composedPath()[0] as UUIInputElement; + + if (typeof target?.value === 'string') { + this.#workspaceContext?.setName(target.value); + } + } + } + + override render() { + return html``; + } + + static override styles = [ + UmbTextStyles, + css` + :host { + display: contents; + } + + #nameInput { + flex: 1 1 auto; + } + `, + ]; +} + +declare global { + interface HTMLElementTagNameMap { + 'umb-workspace-name': UmbWorkspaceNameElement; + } +}