Merge pull request #2230 from umbraco/v14/feature/readonly-multi-url-picker
Feature: Readonly mode for Multi URL Picker Property Editor UI
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
import type { UmbLinkPickerLink } from '../../link-picker-modal/types.js';
|
||||
import { UMB_LINK_PICKER_MODAL } from '../../link-picker-modal/link-picker-modal.token.js';
|
||||
import { css, customElement, html, property, repeat, state } from '@umbraco-cms/backoffice/external/lit';
|
||||
import {
|
||||
css,
|
||||
customElement,
|
||||
html,
|
||||
ifDefined,
|
||||
nothing,
|
||||
property,
|
||||
repeat,
|
||||
state,
|
||||
} from '@umbraco-cms/backoffice/external/lit';
|
||||
import { simpleHashCode } from '@umbraco-cms/backoffice/observable-api';
|
||||
import { UmbChangeEvent } from '@umbraco-cms/backoffice/event';
|
||||
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
|
||||
@@ -124,6 +133,27 @@ export class UmbInputMultiUrlElement extends UUIFormControlMixin(UmbLitElement,
|
||||
|
||||
#urls: Array<UmbLinkPickerLink> = [];
|
||||
|
||||
/**
|
||||
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
|
||||
* @type {boolean}
|
||||
* @attr
|
||||
* @default false
|
||||
*/
|
||||
@property({ type: Boolean, reflect: true })
|
||||
public get readonly() {
|
||||
return this.#readonly;
|
||||
}
|
||||
public set readonly(value) {
|
||||
this.#readonly = value;
|
||||
|
||||
if (this.#readonly) {
|
||||
this.#sorter.disable();
|
||||
} else {
|
||||
this.#sorter.enable();
|
||||
}
|
||||
}
|
||||
#readonly = false;
|
||||
|
||||
@state()
|
||||
private _modalRoute?: UmbModalRouteBuilder;
|
||||
|
||||
@@ -248,7 +278,8 @@ export class UmbInputMultiUrlElement extends UUIFormControlMixin(UmbLitElement,
|
||||
id="btn-add"
|
||||
look="placeholder"
|
||||
label=${this.localize.term('general_add')}
|
||||
.href=${this._modalRoute?.({ index: -1 })}></uui-button>
|
||||
.href=${this._modalRoute?.({ index: -1 })}
|
||||
?disabled=${this.readonly}></uui-button>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -267,24 +298,34 @@ export class UmbInputMultiUrlElement extends UUIFormControlMixin(UmbLitElement,
|
||||
|
||||
#renderItem(link: UmbLinkPickerLink, index: number) {
|
||||
const unique = this.#getUnique(link);
|
||||
const href = this._modalRoute?.({ index }) ?? '#';
|
||||
const href = this.readonly ? undefined : (this._modalRoute?.({ index }) ?? undefined);
|
||||
return html`
|
||||
<uui-ref-node
|
||||
id=${unique}
|
||||
href=${href}
|
||||
href=${ifDefined(href)}
|
||||
name=${link.name || ''}
|
||||
detail=${(link.url || '') + (link.queryString || '')}>
|
||||
detail=${(link.url || '') + (link.queryString || '')}
|
||||
?readonly=${this.readonly}>
|
||||
<umb-icon slot="icon" name=${link.icon || 'icon-link'}></umb-icon>
|
||||
<uui-action-bar slot="actions">
|
||||
<uui-button href=${href} label=${this.localize.term('general_edit')}></uui-button>
|
||||
<uui-button
|
||||
@click=${() => this.#requestRemoveItem(index)}
|
||||
label=${this.localize.term('general_remove')}></uui-button>
|
||||
${this.#renderEditAction(href)} ${this.#renderRemoveAction(index)}
|
||||
</uui-action-bar>
|
||||
</uui-ref-node>
|
||||
`;
|
||||
}
|
||||
|
||||
#renderEditAction(href?: string) {
|
||||
if (this.readonly || !href) return nothing;
|
||||
return html` <uui-button href=${href} label=${this.localize.term('general_edit')}></uui-button> `;
|
||||
}
|
||||
|
||||
#renderRemoveAction(index: number) {
|
||||
if (this.readonly) return nothing;
|
||||
return html` <uui-button
|
||||
@click=${() => this.#requestRemoveItem(index)}
|
||||
label=${this.localize.term('general_remove')}></uui-button>`;
|
||||
}
|
||||
|
||||
static override styles = [
|
||||
css`
|
||||
#btn-add {
|
||||
|
||||
@@ -181,11 +181,6 @@ export class UmbLinkPickerModalElement extends UmbModalBaseElement<UmbLinkPicker
|
||||
.open=${!this.documentExpand}></uui-symbol-expand>
|
||||
<uui-label for="document-expand">${this.localize.term('defaultdialogs_linkToPage')}</uui-label>
|
||||
<div style="${styleMap({ display: !this.documentExpand ? 'block' : 'none' })}">
|
||||
<uui-input
|
||||
disabled
|
||||
id="search-input"
|
||||
placeholder=${this.localize.term('placeholders_search')}
|
||||
label=${this.localize.term('placeholders_search')}></uui-input>
|
||||
<umb-tree
|
||||
alias=${UMB_DOCUMENT_TREE_ALIAS}
|
||||
.props=${{
|
||||
|
||||
@@ -11,6 +11,7 @@ export const manifests = [
|
||||
propertyEditorSchemaAlias: 'Umbraco.MultiUrlPicker',
|
||||
icon: 'icon-link',
|
||||
group: 'pickers',
|
||||
supportsReadOnly: true,
|
||||
settings: {
|
||||
properties: [
|
||||
{
|
||||
|
||||
@@ -27,6 +27,15 @@ export class UmbPropertyEditorUIMultiUrlPickerElement extends UmbLitElement impl
|
||||
this._overlaySize = config.getValueByAlias<UUIModalSidebarSize>('overlaySize') ?? 'small';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
|
||||
* @type {boolean}
|
||||
* @attr
|
||||
* @default false
|
||||
*/
|
||||
@property({ type: Boolean, reflect: true })
|
||||
readonly = false;
|
||||
|
||||
#parseInt(value: unknown, fallback: number): number {
|
||||
const num = Number(value);
|
||||
return !isNaN(num) && num > 0 ? num : fallback;
|
||||
@@ -74,6 +83,7 @@ export class UmbPropertyEditorUIMultiUrlPickerElement extends UmbLitElement impl
|
||||
.urls=${this.value ?? []}
|
||||
.variantId=${this._variantId}
|
||||
?hide-anchor=${this._hideAnchor}
|
||||
?readonly=${this.readonly}
|
||||
@change=${this.#onChange}>
|
||||
</umb-input-multi-url>
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user