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: Readonly mode for Member Picker Property Editor UI #2228

Merged
merged 8 commits into from
Aug 27, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,27 @@ export class UmbInputMemberElement extends UmbFormControlMixin<string | undefine
@property({ type: Object, attribute: false })
public filter: (member: UmbMemberItemModel) => boolean = () => true;

/**
* 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 _editMemberPath = '';

Expand Down Expand Up @@ -180,28 +201,22 @@ export class UmbInputMemberElement extends UmbFormControlMixin<string | undefine
id="btn-add"
look="placeholder"
@click=${this.#openPicker}
label=${this.localize.term('general_choose')}></uui-button>
label=${this.localize.term('general_choose')}
?disabled=${this.readonly}></uui-button>
`;
}

#renderItem(item: UmbMemberItemModel) {
if (!item.unique) return nothing;
return html`
<uui-ref-node name=${item.name} id=${item.unique}>
${this.#renderIcon(item)}
<uui-ref-node-member name=${item.name} id=${item.unique} ?readonly=${this.readonly}>
<uui-action-bar slot="actions">
${this.#renderOpenButton(item)}
<uui-button @click=${() => this.#onRemove(item)} label=${this.localize.term('general_remove')}></uui-button>
${this.#renderOpenButton(item)} ${this.#renderRemoveButton(item)}
</uui-action-bar>
</uui-ref-node>
</uui-ref-node-member>
`;
}

#renderIcon(item: UmbMemberItemModel) {
if (!item.memberType.icon) return;
return html`<umb-icon slot="icon" name=${item.memberType.icon}></umb-icon>`;
}

#renderOpenButton(item: UmbMemberItemModel) {
if (!this.showOpenButton) return nothing;
return html`
Expand All @@ -213,6 +228,13 @@ export class UmbInputMemberElement extends UmbFormControlMixin<string | undefine
`;
}

#renderRemoveButton(item: UmbMemberItemModel) {
if (this.readonly) return nothing;
return html`
<uui-button @click=${() => this.#onRemove(item)} label=${this.localize.term('general_remove')}></uui-button>
`;
}

static override styles = [
css`
#btn-add {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const manifests: Array<ManifestTypes> = [
propertyEditorSchemaAlias: 'Umbraco.MemberPicker',
icon: 'icon-user',
group: 'people',
supportsReadOnly: true,
},
},
memberPickerSchemaManifest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,27 @@ export class UmbPropertyEditorUIMemberPickerElement extends UmbLitElement implem
@property({ attribute: false })
public config?: UmbPropertyEditorConfigCollection;

/**
* 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;

#onChange(event: CustomEvent & { target: UmbInputMemberElement }) {
this.value = event.target.value;
this.dispatchEvent(new UmbPropertyValueChangeEvent());
}

override render() {
return html`<umb-input-member min="0" max="1" .value=${this.value} @change=${this.#onChange}></umb-input-member>`;
return html`<umb-input-member
min="0"
max="1"
.value=${this.value}
@change=${this.#onChange}
?readonly=${this.readonly}></umb-input-member>`;
}
}

Expand Down
Loading