Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding page web component #9

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions manifest-generator/components/page-view-example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>PageView example page</title>
</head>

<body>
<!-- test with a label and placeholder -->
<page-view title="My Amazing Title" page-id="1">
<simple-text-input slot="my-text" label="optional label"
placeholder-text="some placeholder text"></simple-text-input>
</page-view>
</body>

<script src="page-view.js"></script>
<script src="simple-text-input.js"></script>

<script>
console.log("html ID getter got: " + document.getElementsByTagName("page-view")[0].getId());
</script>

</html>
37 changes: 37 additions & 0 deletions manifest-generator/components/page-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Component for a page wrapper -- includes an h1 for page title and a slot for each custom component.
// See page-view-example.html for usage eaxmple.
// Has a public API `getId()` that returns this page's unique ID, set via page-id attribute.

class PageView extends HTMLElement {
#id;
htalat marked this conversation as resolved.
Show resolved Hide resolved

constructor() {
super();

const pageViewTemplate = document.createElement("template");
pageViewTemplate.innerHTML = `
<style>
#title {
text-align: center;
}
</style>

<h1 id="title">${this.getAttribute("title")}</h1>
<slot name="my-text">My Default Text</slot>`;

// Create a shadow root
this.attachShadow({ mode: "open" });
this.shadowRoot.appendChild(pageViewTemplate.content.cloneNode(true));

// Set the id field based on the id attribute
this.#id = this.getAttribute("page-id");
console.log("this page's ID is = " + this.#id);
}

getId() {
return this.#id;
}
}

// Define the new element
customElements.define("page-view", PageView);
6 changes: 1 addition & 5 deletions manifest-generator/components/simple-text-input.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// Component for a simple text input field. Optional attributes for a label and placeholder text.
/*
Usage:
<simple-text-input label="my label" placeholder-text="my placeholder text"></simple-text-input>
// See simple-text-input-example.html for usage examples.

<simple-text-input></simple-text-input>
*/
class SimpleTextInput extends HTMLElement {
constructor() {
super();
Expand Down