Skip to content

Commit

Permalink
feat(element): AlwatrRootElement
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Dec 26, 2022
1 parent bb71627 commit 3b4e59f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ui/element/src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {LitElement} from 'lit';

import {LoggerMixin} from './mixins/logging.js';
import {SignalMixin} from './mixins/signal.js';
import {AlwatrRootElement} from './root.js';

export * from './mixins/logging.js';
export * from './mixins/signal.js';
export {LoggerMixin, SignalMixin, AlwatrRootElement};

export * from 'lit';
export * from 'lit/decorators.js';
Expand All @@ -22,4 +22,4 @@ alwatrRegisteredList.push({
});

export const AlwatrDummyElement = LoggerMixin(LitElement);
export const AlwatrElement = SignalMixin(LoggerMixin(LitElement));
export const AlwatrSmartElement = SignalMixin(LoggerMixin(LitElement));
64 changes: 64 additions & 0 deletions ui/element/src/root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {l10n} from '@alwatr/i18n';
import {router} from '@alwatr/router';
import {LitElement, css, CSSResultGroup, html} from 'lit';

import {LoggerMixin} from './mixins/logging.js';

import type {TemplateResult} from '@alwatr/element';
import type {RoutesConfig} from '@alwatr/router';


/**
* Alwatr Root Base Element
*/
export class AlwatrRootElement extends LoggerMixin(LitElement) {
static override styles: CSSResultGroup = css`
:host {
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
overflow: clip;
contain: layout size style;
}
.page-container {
flex-grow: 1;
contain: size layout style;
}
`;

protected _routes: RoutesConfig = {
map: (route) => route.sectionList[0]?.toString(),
list: {
home: {
render: () => html`<h1>Page Home ;)</h1>`,
},
},
};

constructor() {
super();
this._initRouter();
}

protected _initRouter(): void {
l10n.config.defaultLocale = {
code: 'fa-IR',
direction: 'rtl',
language: 'fa',
};
l10n.setLocal();

router.signal.addListener((route) => {
this._logger.logMethodArgs('routeChanged', {route});
this.requestUpdate();
});

router.initial();
}

override render(): TemplateResult {
return html`<div class="page-container">${cache(router.outlet(this._routes))}</div>`;
}
}

0 comments on commit 3b4e59f

Please sign in to comment.