Files
milinda-pitch/js/icons/menu-icon.js
rubberducky 3dbe404443 feature/book-page (#4)
Co-authored-by: Tim Rijkse <trijkse@gmail.com>
Reviewed-on: #4
2026-01-16 08:46:03 +00:00

67 lines
1.4 KiB
JavaScript

/**
* Menu Icon Web Component
* A reusable menu/hamburger icon element
*/
class MenuIcon extends HTMLElement {
static get observedAttributes() {
return ["size", "color", "stroke-width"];
}
constructor() {
super();
this.attachShadow({ mode: "open" });
}
connectedCallback() {
this.render();
}
attributeChangedCallback() {
this.render();
}
get size() {
return this.getAttribute("size") || "32";
}
get color() {
return this.getAttribute("color") || "#ffffff";
}
get strokeWidth() {
return this.getAttribute("stroke-width") || "2";
}
render() {
this.shadowRoot.innerHTML = `
<style>
:host {
display: inline-flex;
align-items: center;
justify-content: center;
}
svg {
display: block;
}
</style>
<svg
xmlns="http://www.w3.org/2000/svg"
width="${this.size}"
height="${this.size}"
viewBox="0 0 24 24"
fill="none"
stroke="${this.color}"
stroke-width="${this.strokeWidth}"
stroke-linecap="round"
stroke-linejoin="round"
>
<line x1="4" x2="20" y1="12" y2="12"></line>
<line x1="4" x2="20" y1="6" y2="6"></line>
<line x1="4" x2="20" y1="18" y2="18"></line>
</svg>
`;
}
}
customElements.define("menu-icon", MenuIcon);