Skip to content

Commit f9c2b95

Browse files
authored
Label property-editor, adds UFM template support (#19610)
* Adds `labelTemplate` config to Label editor * Code tidyup for Label editor element * Adds "format-bytes" UFM filter * Renamed "format-bytes" to "bytes" * Label element tidy-up + copilot amends * Added `formatBytes` options * Simplified condition, thanks CodeScene * Reverted element export
1 parent 1f28f10 commit f9c2b95

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

src/Umbraco.Web.UI.Client/src/packages/property-editors/label/manifests.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ export const manifests: Array<UmbExtensionManifest> = [
1212
group: 'common',
1313
propertyEditorSchemaAlias: 'Umbraco.Label',
1414
supportsReadOnly: true,
15+
settings: {
16+
properties: [
17+
{
18+
alias: 'labelTemplate',
19+
label: 'Label template',
20+
description: 'Enter a template for the label.',
21+
propertyEditorUiAlias: 'Umb.PropertyEditorUi.TextBox',
22+
},
23+
],
24+
},
1525
},
1626
},
1727
labelSchemaManifest,

src/Umbraco.Web.UI.Client/src/packages/property-editors/label/property-editor-ui-label.element.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
1-
import { html, customElement, property } from '@umbraco-cms/backoffice/external/lit';
2-
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
1+
import { customElement, html, property, state, when } from '@umbraco-cms/backoffice/external/lit';
2+
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
33
import type {
44
UmbPropertyEditorUiElement,
55
UmbPropertyEditorConfigCollection,
66
} from '@umbraco-cms/backoffice/property-editor';
7-
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
87

98
/**
109
* @element umb-property-editor-ui-label
1110
*/
1211
@customElement('umb-property-editor-ui-label')
1312
export class UmbPropertyEditorUILabelElement extends UmbLitElement implements UmbPropertyEditorUiElement {
14-
@property()
15-
value = '';
13+
@state()
14+
private _labelTemplate?: string;
1615

1716
@property()
18-
description = '';
17+
value = '';
1918

2019
@property({ attribute: false })
21-
public config?: UmbPropertyEditorConfigCollection;
20+
public set config(config: UmbPropertyEditorConfigCollection | undefined) {
21+
this._labelTemplate = config?.getValueByAlias('labelTemplate');
22+
}
2223

2324
override render() {
24-
return html`${this.value ?? ''}`;
25+
return when(
26+
this._labelTemplate?.length,
27+
() => html`<umb-ufm-render inline .markdown=${this._labelTemplate} .value=${this.value}></umb-ufm-render>`,
28+
() => html`${this.value ?? ''}`,
29+
);
2530
}
26-
27-
static override styles = [UmbTextStyles];
2831
}
2932

3033
export default UmbPropertyEditorUILabelElement;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { UmbUfmFilterBase } from './base.filter.js';
2+
import { formatBytes } from '@umbraco-cms/backoffice/utils';
3+
4+
class UmbUfmBytesFilterApi extends UmbUfmFilterBase {
5+
filter(str?: string, decimals?: number, kilo?: number, culture?: string): string {
6+
if (!str?.length) return '';
7+
return formatBytes(Number(str), { decimals, kilo, culture });
8+
}
9+
}
10+
11+
export { UmbUfmBytesFilterApi as api };

src/Umbraco.Web.UI.Client/src/packages/ufm/filters/manifests.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ export const manifests: Array<ManifestUfmFilter> = [
88
api: () => import('./fallback.filter.js'),
99
meta: { alias: 'fallback' },
1010
},
11+
{
12+
type: 'ufmFilter',
13+
alias: 'Umb.Filter.Bytes',
14+
name: 'Bytes UFM Filter',
15+
api: () => import('./bytes.filter.js'),
16+
meta: { alias: 'bytes' },
17+
},
1118
{
1219
type: 'ufmFilter',
1320
alias: 'Umb.Filter.Lowercase',

0 commit comments

Comments
 (0)