Skip to content

Commit 986a69a

Browse files
committed
Add WCOPage base class for all page elements
1 parent f4a13a0 commit 986a69a

File tree

3 files changed

+75
-28
lines changed

3 files changed

+75
-28
lines changed

packages/site-client/src/components/wco-catalog-page.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {html, css, LitElement} from 'lit';
7+
import {html} from 'lit';
88
import {customElement} from 'lit/decorators.js';
99
import './wco-catalog-search.js';
10+
import {WCOPage} from './wco-page.js';
1011

1112
@customElement('wco-catalog-page')
12-
export class WCOCatalogPage extends LitElement {
13-
static styles = css`
14-
:host {
15-
display: block;
16-
}
17-
`;
18-
19-
render() {
13+
export class WCOCatalogPage extends WCOPage {
14+
renderContent() {
2015
return html`
2116
<h1>Catalog</h1>
2217
<wco-catalog-search></wco-catalog-search>

packages/site-client/src/components/wco-element-page.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {html, css, LitElement} from 'lit';
7+
import {html, css} from 'lit';
88
import {customElement, property} from 'lit/decorators.js';
9+
import {WCOPage} from './wco-page.js';
910

1011
import type {Package, Reference} from 'custom-elements-manifest/schema.js';
1112
import {
@@ -24,27 +25,30 @@ export interface ElementData {
2425
}
2526

2627
@customElement('wco-element-page')
27-
export class WCOElementPage extends LitElement {
28-
static styles = css`
29-
:host {
30-
display: flex;
31-
flex-direction: column;
32-
}
33-
34-
.full-screen-error {
35-
display: flex;
36-
flex: 1;
37-
align-items: center;
38-
justify-items: center;
39-
}
40-
`;
28+
export class WCOElementPage extends WCOPage {
29+
static styles = [
30+
WCOPage.styles,
31+
css`
32+
:host {
33+
display: flex;
34+
flex-direction: column;
35+
}
36+
37+
.full-screen-error {
38+
display: flex;
39+
flex: 1;
40+
align-items: center;
41+
justify-items: center;
42+
}
43+
`,
44+
];
4145

4246
@property({attribute: false})
4347
elementData?: ElementData;
4448

4549
render() {
4650
if (this.elementData === undefined) {
47-
return html` <div class="full-screen-error">No element to display</div> `;
51+
return html`<div class="full-screen-error">No element to display</div>`;
4852
}
4953
const {
5054
packageName,
@@ -65,9 +69,9 @@ export class WCOElementPage extends LitElement {
6569
: resolveReference(manifest, module, declarationRef, packageName, '');
6670

6771
if (declaration === undefined || declaration.kind !== 'class') {
68-
return html`
69-
<div class="full-screen-error">Could not find element declaration</div>
70-
`;
72+
return html`<div class="full-screen-error">
73+
Could not find element declaration
74+
</div>`;
7175
}
7276

7377
const fields = declaration.members?.filter((m) => m.kind === 'field');
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import {html, css, LitElement, CSSResultGroup} from 'lit';
8+
import {customElement} from 'lit/decorators.js';
9+
import './wco-top-bar.js';
10+
11+
/**
12+
* The base class for all pages. Includes a top bar and <main> element.
13+
*/
14+
@customElement('wco-page')
15+
export class WCOPage extends LitElement {
16+
static styles: CSSResultGroup = css`
17+
:host {
18+
display: flex;
19+
flex-direction: column;
20+
min-height: 100vh;
21+
}
22+
23+
main {
24+
flex: 1;
25+
}
26+
`;
27+
28+
render() {
29+
return html`
30+
<wco-top-bar></wco-top-bar>
31+
<main>${this.renderMain()}</main>
32+
`;
33+
}
34+
35+
protected renderMain() {
36+
return this.renderContent();
37+
}
38+
39+
protected renderContent() {
40+
return html`<slot></slot>`;
41+
}
42+
}
43+
44+
declare global {
45+
interface HTMLElementTagNameMap {
46+
'wco-page': WCOPage;
47+
}
48+
}

0 commit comments

Comments
 (0)