Skip to content

Commit

Permalink
Merge branch 'main' into helena/review-item-component
Browse files Browse the repository at this point in the history
  • Loading branch information
yolophg authored Jun 26, 2024
2 parents 8eead56 + da6ae46 commit 6f340f1
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 6 deletions.
48 changes: 48 additions & 0 deletions components/hero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { css, html } from "../html-css-utils.js";

class Hero extends HTMLElement {
constructor() {
super();
this.render();
}

render() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = this.createCss() + this.createHtml();
}

createCss() {
return css`
:host {
font-weight: 500;
}
h2 {
font-weight: inherit;
font-size: 30px;
}
@media only screen and (min-width: 768px) {
h2 {
font-size: 40px;
}
}
@media only screen and (min-width: 1024px) {
h2 {
font-size: 50px;
}
}
`;
}

createHtml() {
return html`
<h2>
<slot></slot>
</h2>
`;
}
}

customElements.define('ds-hero', Hero);
53 changes: 53 additions & 0 deletions components/image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { css, html } from "../html-css-utils.js";

class Image extends HTMLElement {
constructor() {
super();

this.validateAttributes();
this.render();
}

validateAttributes() {
if (!this.hasAttribute("alt")) {
throw new Error('The "alt" attribute is required.');
}
}

render() {
this.attachShadow({ mode: "open" });
this.shadowRoot.innerHTML = this.createCss() + this.createHtml();
}

createCss() {
return css`
img {
display: block;
max-width: 100%;
}
`;
}

createHtml() {
const src = this.getAttribute("src") || "";
const alt = this.getAttribute("alt") || "";
const width = this.getAttribute("width");
const height = this.getAttribute("height");

let imgHtml = `<img src="${src}" alt="${alt}"`;

if (width) {
imgHtml += ` width="${width}"`;
}

if (height) {
imgHtml += ` height="${height}"`;
}

imgHtml += `>`;

return imgHtml;
}
}

customElements.define("ds-image", Image);
12 changes: 6 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@

<div id="intro-container">
<div class="hero">
<p>해외취업을 위한 커뮤니티 기반 알고리즘 스터디</p>
<ds-hero>해외취업을 위한 커뮤니티 기반 알고리즘 스터디</ds-hero>
<ds-button-link
size="big"
variant="primary"
Expand All @@ -248,16 +248,16 @@
</div>

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

<div id="language-container">
<div class="language-image">
<img src="images/languages.png" alt="#" />
<ds-image src="images/languages.png" alt="languages"></ds-image>
</div>
<div class="hero">
<p>지역에 관계없이 다양한 언어로 참여할 수 있어요</p>
<ds-hero>지역에 관계없이 다양한 언어로 참여할 수 있어요</ds-hero>
<ds-button-link
size="big"
variant="ghost"
Expand All @@ -270,7 +270,7 @@

<div id="review-container">
<div class="hero">
<p>코드리뷰를 통해 새로운 관점을 배울 수 있어요</p>
<ds-hero>코드리뷰를 통해 새로운 관점을 배울 수 있어요</ds-hero>
<ds-button-link
size="big"
variant="primary"
Expand All @@ -279,7 +279,7 @@
>
</div>
<div class="review-image">
<img src="images/review.png" />
<ds-image src="images/review.png" alt="review"></ds-image>
</div>
</div>

Expand Down
3 changes: 3 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
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";
import "./components/seo-meta-tag/seo-meta-tag.js";

0 comments on commit 6f340f1

Please sign in to comment.