import { html, customElement, LitElement, css, state, repeat } from '@umbraco-cms/backoffice/external/lit';
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
import {
UMB_SECTION_SIDEBAR_MENU_GLOBAL_CONTEXT,
UMB_SECTION_SIDEBAR_MENU_SECTION_CONTEXT,
type UmbSectionMenuItemExpansionEntryModel,
} from '@umbraco-cms/backoffice/menu';
@customElement('example-section-sidebar-menu-playground-dashboard')
export class ExampleSectionSidebarMenuPlaygroundDashboard extends UmbElementMixin(LitElement) {
#globalContext?: typeof UMB_SECTION_SIDEBAR_MENU_GLOBAL_CONTEXT.TYPE;
#sectionContext?: typeof UMB_SECTION_SIDEBAR_MENU_SECTION_CONTEXT.TYPE;
@state()
private _globalExpansion: Array = [];
@state()
private _sectionExpansion: Array = [];
constructor() {
super();
this.consumeContext(UMB_SECTION_SIDEBAR_MENU_GLOBAL_CONTEXT, (section) => {
this.#globalContext = section;
this.#observeGlobalExpansion();
});
this.consumeContext(UMB_SECTION_SIDEBAR_MENU_SECTION_CONTEXT, (section) => {
this.#sectionContext = section;
this.#observeSectionExpansion();
});
}
#observeGlobalExpansion() {
this.observe(this.#globalContext?.expansion.expansion, (items) => {
this._globalExpansion = items || [];
});
}
#observeSectionExpansion() {
this.observe(this.#sectionContext?.expansion.expansion, (items) => {
this._sectionExpansion = items || [];
});
}
#onCloseItem(event: PointerEvent, item: UmbSectionMenuItemExpansionEntryModel) {
event.stopPropagation();
this.#sectionContext?.expansion.collapseItem(item);
}
#onCollapseSection() {
this.#sectionContext?.expansion.collapseAll();
}
override render() {
return html`
Collapse All
${repeat(
this._sectionExpansion,
(item) => item.entityType + item.unique,
(item) => this.#renderItem(item),
)}
${repeat(
this._globalExpansion,
(item) => item.entityType + item.unique,
(item) => this.#renderItem(item),
)}
`;
}
#renderItem(item: UmbSectionMenuItemExpansionEntryModel) {
return html`
this.#onCloseItem(event, item)}>Close
`;
}
static override styles = [
css`
:host {
display: block;
padding: var(--uui-size-layout-1);
}
`,
];
}
export { ExampleSectionSidebarMenuPlaygroundDashboard as element };
declare global {
interface HTMLElementTagNameMap {
'example-section-sidebar-menu-playground-dashboard': ExampleSectionSidebarMenuPlaygroundDashboard;
}
}