diff --git a/components/image.js b/components/image.js new file mode 100644 index 0000000..82109f3 --- /dev/null +++ b/components/image.js @@ -0,0 +1,62 @@ +class Image extends HTMLElement { + constructor() { + super(); + + this.validateAttributes(); + this.render(); + } + + validateAttributes() { + if (!this.hasAttribute("alt")) { + throw new Error('The "alt" attribute is required.'); + } + + const allowedAttributes = ["src", "alt", "width", "height"]; + for (const attr of this.attributes) { + if (!allowedAttributes.includes(attr.name)) { + throw new Error(`The attribute "${attr.name}" is not allowed.`); + } + } + } + + render() { + this.attachShadow({ mode: "open" }); + this.shadowRoot.innerHTML = this.createCss() + this.createHtml(); + } + + createCss() { + return ` + + `; + } + + createHtml() { + const src = this.getAttribute("src") ?? ""; + const alt = this.getAttribute("alt") ?? ""; + + let imgHtml = `${alt}`; + + return ` + ${imgHtml} + `; + } +} + +customElements.define("ds-image", Image); diff --git a/index.html b/index.html index 1cee870..002d6c9 100644 --- a/index.html +++ b/index.html @@ -248,13 +248,13 @@
- # +
- # +

지역에 관계없이 다양한 언어로 참여할 수 있어요

@@ -279,7 +279,7 @@ >
- +
diff --git a/main.js b/main.js index ca2fd53..dadf138 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,7 @@ +import "./components/button-link.js"; import "./components/footer-link/footer-link.js"; import "./components/header.js"; import "./components/hero/hero.js"; -import "./components/button-link.js"; +import "./components/image.js"; import "./components/review-item/review-item.js"; import "./components/seo-meta-tag/seo-meta-tag.js";