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

add long text input component #13

Merged
merged 2 commits into from
Sep 12, 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
18 changes: 18 additions & 0 deletions manifest-generator/components/long-text-input-example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Simple word count web component</title>
</head>

<body>
<!-- test with a label and placeholder -->
<long-text-input
label="an optional label"
placeholder-text="Placeholder text"
></long-text-input>
<long-text-input></long-text-input>
</body>

<script src="long-text-input.js"></script>
</html>
60 changes: 60 additions & 0 deletions manifest-generator/components/long-text-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Component for a long text input box. Optional attributes for a label and placeholder text.
// See long-text-input-example.html for usage examples.

class LongTextInput extends HTMLElement {
#inputElement;
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", "table-item");
if (this.getAttribute("label")) {
inputLabel.textContent = `${this.getAttribute("label")}`;
} else {
inputLabel.setAttribute("hidden", true);
}

// Create the input element
this.#inputElement = document.createElement("textarea");
this.#inputElement.setAttribute("class", "table-item");
if (this.getAttribute("placeholder-text")) {
this.#inputElement.setAttribute(
"placeholder",
`${this.getAttribute("placeholder-text")}`
);∏
}

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

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

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

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

getUserInput() {
return this.#inputElement.value;
}
}

// Define the new element
customElements.define("long-text-input", LongTextInput);