diff --git a/components/image.js b/components/image.js index cc24d35..0ca9eab 100644 --- a/components/image.js +++ b/components/image.js @@ -1,4 +1,13 @@ -class ImageComponent extends HTMLElement { +const css = ` + +`; + +class DsImage extends HTMLElement { constructor() { super(); this.attachShadow({ mode: "open" }); @@ -6,7 +15,15 @@ class ImageComponent extends HTMLElement { this.validateAttributes(); this.setDefaultAttributes(); - this.render(); + const src = this.getAttribute("src") || ""; + const alt = this.getAttribute("alt") || ""; + const width = this.getAttribute("width") || ""; + const height = this.getAttribute("height") || ""; + + const html = ` + + `; + this.shadowRoot.innerHTML = css + html; // Direct assignment } validateAttributes() { @@ -23,33 +40,6 @@ class ImageComponent extends HTMLElement { } } } - - setDefaultAttributes() { - if (!this.hasAttribute("width")) { - this.setAttribute("width", "100%"); - } - if (!this.hasAttribute("height")) { - this.setAttribute("height", "auto"); - } - } - - render() { - const src = this.getAttribute("src"); - const alt = this.getAttribute("alt"); - const width = this.getAttribute("width"); - const height = this.getAttribute("height"); - - this.shadowRoot.innerHTML = ` - - - `; - } } -customElements.define("image-component", ImageComponent); +customElements.define("ds-image", DsImage); diff --git a/index.html b/index.html index e2b4f2b..e866ee3 100644 --- a/index.html +++ b/index.html @@ -243,13 +243,13 @@
지역에 관계없이 다양한 언어로 참여할 수 있어요
@@ -263,7 +263,7 @@