diff --git a/src/common/pages/BasePageElement/BasePageElement.ts b/src/common/pages/BasePageElement/BasePageElement.ts index 4318497..81ac3a2 100644 --- a/src/common/pages/BasePageElement/BasePageElement.ts +++ b/src/common/pages/BasePageElement/BasePageElement.ts @@ -1,5 +1,45 @@ +import { attr } from "@github/catalyst"; +import { html, render } from "@github/jtml"; import { BaseElement } from "common/"; +import { isTrue } from "core/utils"; -class BasePageElement extends BaseElement {} +class BasePageElement extends BaseElement { + public pageTitle: string = ""; + @attr hidetitle: string; + @attr customtitle: string; + constructor(options: OptionType) { + super(); + if (options?.title) { + this.pageTitle = options?.title; + } + this.connectedCallback = this.connectedCallback.bind(this); + this.disconnectedCallback = this.disconnectedCallback.bind(this); + } + + public renderTitle = () => { + if (!isTrue(this.hidetitle)) { + return html`
+ ${this.customtitle ? this.customtitle : this.pageTitle} +
`; + } + return html``; + }; + + update = (): void => { + const _render = () => html` ${this.renderTitle()} ${this.render()} `; + render(_render(), this); + this.bindEvents(); + this.updateCallback(); + }; + + connectedCallback() { + this.appMain.setTitle(this.pageTitle); + super.connectedCallback(); + } +} export default BasePageElement; + +export type OptionType = { + title?: string; +}; diff --git a/src/components/app-form/AppFormElement.ts b/src/components/app-form/AppFormElement.ts index 498f59e..a22c6b4 100644 --- a/src/components/app-form/AppFormElement.ts +++ b/src/components/app-form/AppFormElement.ts @@ -23,12 +23,6 @@ class AppFormElement extends BaseComponentElement { this.update(); }; - public keyUp = (e) => { - if (e.keyCode === 13) { - this.onSubmit(e); - } - }; - public onSubmit = (e) => { e.preventDefault(); if (!this.valid) { diff --git a/src/components/app-link/AppLinkElement.ts b/src/components/app-link/AppLinkElement.ts index 5bde65b..af08f85 100644 --- a/src/components/app-link/AppLinkElement.ts +++ b/src/components/app-link/AppLinkElement.ts @@ -44,7 +44,10 @@ class AppLinkElement extends BaseComponentElement { }; get disabled(): boolean { - return isTrue(this.goBack) && this.routerService.emptyState; + if (isTrue(this.goBack)) { + return this.routerService.emptyState; + } + return false; } render = (): TemplateResult => { @@ -56,7 +59,7 @@ class AppLinkElement extends BaseComponentElement { >${this.title}` : html` { + if (!title) title = __CONFIG__.appName; + window.document.title = title; + }; + private createAppModal = () => { const _appModal = document.createElement("app-modal"); _appModal.setAttribute("data-target", "app-main.appModal"); diff --git a/src/components/app-pagination/AppPaginationElement.ts b/src/components/app-pagination/AppPaginationElement.ts index ba686bb..44dde30 100644 --- a/src/components/app-pagination/AppPaginationElement.ts +++ b/src/components/app-pagination/AppPaginationElement.ts @@ -120,7 +120,7 @@ class AppPaginationElement extends BaseComponentElement { return html`