Skip to content
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 @@ -30,6 +30,9 @@
@state()
private _colorList = umbracoColors.filter((color) => !color.legacy);

@state()
private _isSearching = false;

constructor() {
super();
this.consumeContext(UMB_ICON_REGISTRY_CONTEXT, (context) => {
Expand All @@ -44,8 +47,10 @@
if (!this.#icons) return;
const value = this._searchInput?.value;
if (value) {
this._isSearching = value.length > 0;
this._iconsFiltered = this.#icons.filter((icon) => icon.name.toLowerCase().includes(value.toLowerCase()));
} else {
this._isSearching = false;
this._iconsFiltered = this.#icons;
}
}
Expand All @@ -54,8 +59,12 @@
const isActivate = e.type === 'click' || (e.type === 'keyup' && (e as KeyboardEvent).key === 'Enter');
if (!isActivate) return;

const nextIcon = this.value.icon === iconName ? '' : iconName;
this.modalContext?.updateValue({ icon: nextIcon });
if (this.data?.showEmptyOption) {
const nextIcon = this.value.icon === iconName ? '' : iconName;
this.modalContext?.updateValue({ icon: nextIcon });
} else {
this.modalContext?.updateValue({ icon: iconName });
}

Check warning on line 67 in src/Umbraco.Web.UI.Client/src/packages/core/icon-registry/icon-picker-modal/icon-picker-modal.element.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Complex Method

UmbIconPickerModalElement.changeIcon has a cyclomatic complexity of 9, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
}

#onColorChange(e: UUIColorSwatchesEvent) {
Expand Down Expand Up @@ -93,16 +102,21 @@
</uui-color-swatches>
<hr />
<uui-scroll-container id="icons">
<uui-button
class=${!this.value.icon ? 'selected' : ''}
label=${this.localize.term('defaultdialogs_noIcon')}
title=${this.localize.term('defaultdialogs_noIcon')}
@click=${this.#clearIcon}
@keyup=${(e: KeyboardEvent) => {
if (e.key === 'Enter' || e.key === ' ') this.#clearIcon();
}}>
<uui-icon style="opacity:.35" name=${ifDefined(this.data?.placeholder)}></uui-icon> </uui-button
>${this.renderIcons()}</uui-scroll-container
${this.data?.showEmptyOption && !this._isSearching
? html`
<uui-button
class=${!this.value.icon ? 'selected' : ''}
label=${this.localize.term('defaultdialogs_noIcon')}
title=${this.localize.term('defaultdialogs_noIcon')}
@click=${this.#clearIcon}
@keyup=${(e: KeyboardEvent) => {
if (e.key === 'Enter' || e.key === ' ') this.#clearIcon();
}}>
<uui-icon style="opacity:.35" name=${ifDefined(this.data?.placeholder)}></uui-icon>
</uui-button>
`
: nothing}
${this.renderIcons()}</uui-scroll-container
>
</div>
<uui-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { UmbModalToken } from '@umbraco-cms/backoffice/modal';

export interface UmbIconPickerModalData {
placeholder?: string;
showEmptyOption?: boolean;
}

export interface UmbIconPickerModalValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,45 @@ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { extractUmbColorVariable } from '@umbraco-cms/backoffice/resources';
import { UmbChangeEvent } from '@umbraco-cms/backoffice/event';

import { UmbFormControlMixin } from '@umbraco-cms/backoffice/validation';

/**
* @element umb-property-editor-ui-icon-picker
*/
@customElement('umb-property-editor-ui-icon-picker')
export class UmbPropertyEditorUIIconPickerElement extends UmbLitElement implements UmbPropertyEditorUiElement {
//
export class UmbPropertyEditorUIIconPickerElement
extends UmbFormControlMixin<string, typeof UmbLitElement, undefined>(UmbLitElement, undefined)
implements UmbPropertyEditorUiElement
{
@property({ type: Boolean })
mandatory = false;

protected override firstUpdated(): void {
this.addValidator(
'valueMissing',
() => 'Icon is required',
() => this.mandatory && !this._icon,
);
}

@property()
public set value(v: string) {
this._value = v ?? '';
const parts = this._value.split(' ');
public override set value(v: string) {
const val = v ?? '';
super.value = val;

const parts = val.split(' ');
if (parts.length === 2) {
this._icon = parts[0];
this._color = parts[1].replace('color-', '');
} else {
this._icon = this._value;
this._icon = val;
this._color = '';
}
}
public get value() {
return this._value;

public override get value() {
return (super.value as string) ?? '';
}
private _value = '';

@state()
private _icon = '';
Expand All @@ -53,7 +70,7 @@ export class UmbPropertyEditorUIIconPickerElement extends UmbLitElement implemen
icon: this._icon,
color: this._color,
},
data: { placeholder: this._placeholderIcon },
data: { placeholder: this._placeholderIcon, showEmptyOption: !this.mandatory },
}).catch(() => undefined);

if (!data) return;
Expand Down
Loading