Skip to content

Commit

Permalink
fix : Adjust to new component styles and apply the feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTheKorean committed Jun 20, 2024
1 parent 703cbe1 commit 01eb609
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
50 changes: 20 additions & 30 deletions components/image.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
class ImageComponent extends HTMLElement {
const css = `
<style>
img {
display: block;
max-width: 100%;
}
</style>
`;

class DsImage extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });

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 = `
<img src="${src}" alt="${alt}" width="${width}" height="${height}">
`;
this.shadowRoot.innerHTML = css + html; // Direct assignment
}

validateAttributes() {
Expand All @@ -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 = `
<style>
img {
display: block;
max-width: 100%;
height: auto;
}
</style>
<img src="${src}" alt="${alt}" width="${width}" height="${height}">
`;
}
}

customElements.define("image-component", ImageComponent);
customElements.define("ds-image", DsImage);
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@
</div>

<div class="intro-image">
<image-component src="images/roadmap.png" alt="Study roadmap"></image-component>
<ds-image src="images/roadmap.png" alt="Study roadmap"></ds-image>
</div>
</div>

<div id="language-container">
<div class="language-image">
<image-component src="images/languages.png" alt="Languages"></image-component>
<ds-image src="images/languages.png" alt="Languages"></ds-image>
</div>
<div class="hero">
<p>์ง€์—ญ์— ๊ด€๊ณ„์—†์ด ๋‹ค์–‘ํ•œ ์–ธ์–ด๋กœ ์ฐธ์—ฌํ•  ์ˆ˜ ์žˆ์–ด์š”</p>
Expand All @@ -263,7 +263,7 @@
<link-button size="big" variant="secondary" href="https://discord.gg/43UkheRV">๋””์Šค์ฝ”๋“œ ์ฐธ์—ฌํ•˜๊ธฐ</link-button>
</div>
<div class="review-image">
<image-component src="images/review.png" alt="Review image"></image-component>
<ds-image src="images/review.png" alt="Review image"></ds-image>
</div>
</div>

Expand Down

0 comments on commit 01eb609

Please sign in to comment.