Skip to content

Commit

Permalink
Merge pull request #54 from DaleStudy/helena/review-item-component
Browse files Browse the repository at this point in the history
refactor: modify review item component
  • Loading branch information
yolophg authored Jun 26, 2024
2 parents da6ae46 + 6f340f1 commit 2305bf2
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 80 deletions.
91 changes: 91 additions & 0 deletions components/review-item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
class ReviewItem extends HTMLElement {
constructor() {
super();
}

// initial render in here to ensure the element is fully connected to the DOM.
connectedCallback() {
this.attachShadow({ mode: "open" });
this.render();
}

// getter to make it clean to access the attribute value and ensure a default empty string if the attribute is missing.
get text() {
return this.getAttribute("text") || "";
}

get name() {
return this.getAttribute("name") || "";
}

get img() {
return this.getAttribute("img") || "";
}

render() {
try {
this.shadowRoot.innerHTML = `
<style>
.review-item {
display: flex;
flex-direction: column;
align-items: center;
border-radius: 10px;
padding: 41px 51px 31px;
background-color: #efefef;
max-width: 568px;
}
.review-item blockquote,
figure {
margin: 0;
}
.review-content {
display: flex;
align-items: center;
}
.review-content figure {
width: 104px;
height: 104px;
flex-shrink: 0;
object-fit: cover;
margin-right: 31px;
}
.review-content figure > img {
width: 100%;
height: 100%;
padding-top: 7px;
border-radius: 48%;
background-color: #ffffff;
}
.review-content blockquote {
font-size: 14px;
}
.review-footer {
width: 100%;
margin-top: 14px;
}
.review-footer figcaption {
font-size: 16px;
text-align: right;
}
</style>
<article class="review-item">
<section class="review-content">
<figure>
<img src="${this.img}" alt="Reviewer">
</figure>
<blockquote>${this.text}</blockquote>
</section>
<footer class="review-footer">
<figcaption>${this.name}</figcaption>
</footer>
</article>
`;
} catch (error) {
// log any rendering errors.
console.error("Error during render:", error);
}
}
}

customElements.define("review-item", ReviewItem);
34 changes: 0 additions & 34 deletions components/review-item/review-item.css

This file was deleted.

46 changes: 0 additions & 46 deletions components/review-item/review-item.js

This file was deleted.

4 changes: 4 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import "./components/button-link.js";
import "./components/footer-link/footer-link.js";
import "./components/header.js";
import "./components/hero/hero.js";
import "./components/link-button/link-button.js";
import "./components/review-item.js";
import "./components/button-link.js";
import "./components/hero.js";
import "./components/image.js";
import "./components/review-item/review-item.js";
Expand Down

0 comments on commit 2305bf2

Please sign in to comment.