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 a simple-text-input web component #3

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions manifest-generator/components/simple-text-input-example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Simple word count web component</title>
</head>

<body>
<simple-text-input label="hello world" placeholder-text="Placeholder app name" />

</body>

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

</html>
49 changes: 49 additions & 0 deletions manifest-generator/components/simple-text-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Component for a simple text input page -- a text label and a text input box.
/*
Usage:
<simple-text-input label="my label" placeholder-text="my placeholder text"/>
*/
class SimpleTextInput extends HTMLElement {
constructor() {
super();

// Create a shadow root
const shadow = this.attachShadow({mode: 'open'});

const tableWrapper = document.createElement('div');
tableWrapper.setAttribute("class", "table");

// Create the page label
const inputLabel = document.createElement('p');
inputLabel.setAttribute("class", "tableitem");
inputLabel.textContent = `${this.getAttribute("label")}`;

// Create the input element
const inputElement = document.createElement('input');
inputElement.setAttribute("class", "tableitem");
inputElement.setAttribute("placeholder", `${this.getAttribute("placeholder-text")}`);

// Style the elements
const style = document.createElement("style");
style.textContent = `.tableitem {
align-self: center;
}

.table {
display: flex;
flex-direction: column;
}`;

// Append the text and input elements to the table
tableWrapper.append(inputLabel);
tableWrapper.append(inputElement);

// Append the table and style to the shadow DOM
shadow.append(tableWrapper);
shadow.append(style);
}
}

// Define the new element
customElements.define('simple-text-input', SimpleTextInput);