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

feat : create image component #47

Merged
merged 2 commits into from
Jun 26, 2024
Merged

feat : create image component #47

merged 2 commits into from
Jun 26, 2024

Conversation

SamTheKorean
Copy link
Contributor

@SamTheKorean SamTheKorean commented Jun 14, 2024

  • Link an issue with the pull request
  • Ensure no errors or warnings on the browser console
  • Avoid additional major pushes after approval (if necessary, request a new review)

@SamTheKorean SamTheKorean linked an issue Jun 14, 2024 that may be closed by this pull request
@SamTheKorean SamTheKorean marked this pull request as ready for review June 14, 2024 07:28
Copy link
Contributor

@DaleSeo DaleSeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

웹 컴포넌트의 능력에 감탄하며, 코드를 흥미롭게 잘 일었네요. 피드백 확인 부탁드리겠습니다.

components/image.js Show resolved Hide resolved
components/image.js Outdated Show resolved Hide resolved
components/image.js Outdated Show resolved Hide resolved
components/image.js Outdated Show resolved Hide resolved
components/image.js Outdated Show resolved Hide resolved
components/image.js Outdated Show resolved Hide resolved
components/image.js Outdated Show resolved Hide resolved
const width = this.getAttribute("width") || "";
const height = this.getAttribute("height") || "";

const html = `
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 경우엔 html를 상단에 넣으면 속성 값을 가져올 수 없어서 consturctor 안에서 선언했습니다!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaleSeo 여기서 언급하신 코멘트가 떠오르네요! 이런 경우에는 처음에 생각했던 html 코드 위치에 대한 이점이 사라지는 것 같습니다...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 맞습니다! 처음에 우려했던 부분이 나타나더라고요..!

@SamTheKorean
Copy link
Contributor Author

피드백 반영 및 합의된 컴포넌트 코딩 방식 반영하고 다시 커밋하였습니다! 리뷰 부탁드리겠습니다!

components/image.js Outdated Show resolved Hide resolved
const height = this.getAttribute("height") || "";

const html = `
<img src="${src}" alt="${alt}" width="${width}" height="${height}">
Copy link
Contributor

@DaleSeo DaleSeo Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<img width="" height="" /><img />와 동일할까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

height가 없을 때 img 엘리먼트 기본 값을 넣어줘야하는데 이 로직으로는 ""값이 들어가겠군요.. 피드백 감사합니다!

@SamTheKorean SamTheKorean force-pushed the sam/33 branch 4 times, most recently from 06a22ae to 7e8b0b5 Compare June 24, 2024 12:42
@@ -1,6 +1,7 @@
import "./components/button-link.js";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

알파벳순에 맞게 위로 올렸습니다.

@SamTheKorean
Copy link
Contributor Author

피드백 및 정해진 컴포넌트 스타일 반영하고 커밋했습니다!

Comment on lines 16 to 15
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.`);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다음에는 특정 attribute만 허용하기 보다, 필요한 attribute를 전달하지 않았을 때 에러를 던지면 어떨까요?

예를 들어 웹 접근성을 위해 aria-label 같은 image의 주요 스타일과 논리와 상관 없는 attribute를 전달하거나 제거하고 싶을 때
현재 구현으로는 매번 image component 구현을 바꿔야 하는 불편함이 있을 수 있습니다.
물론 그만큼 외부에서 주입하는 변화에 컴포넌트가 취약해질 수도 있겠죠?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감사합니다! 피드백 반영해서 수정해보겠습니다!

Comment on lines 42 to 47
let imgHtml = `<img src="${src}" alt="${alt}"`;

if (this.hasAttribute("width")) {
const width = this.getAttribute("width");
imgHtml += ` width="${width}"`;
}

if (this.hasAttribute("height")) {
const height = this.getAttribute("height");
imgHtml += ` height="${height}"`;
}

imgHtml += `>`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아, 이거 코드가 너무 읽기 어려운 것 같은데요... 😅
나중에 수정하시는 분이 실수할 가능성이 높아 보입니다.

@SamTheKorean SamTheKorean merged commit da6ae46 into main Jun 26, 2024
@SamTheKorean SamTheKorean deleted the sam/33 branch June 26, 2024 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create Image Component
3 participants