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 color picker component #5

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
54 changes: 54 additions & 0 deletions manifest-generator/components/color-picker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Component for a color picker -- a text label and a color input box.
/*
Usage:
<color-picker label="my label" placeholder-text="my placeholder text"/>
*/
class ColorPicker extends HTMLElement {
inputElement;
constructor() {
super();
this.inputElement = document.createElement('input');

// 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
this.inputElement.setAttribute("type", "color");
this.inputElement.setAttribute("class", "tableitem");

// 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(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('color-picker', ColorPicker);

Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
</body>

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

</html>