-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into helena/review-item-component
- Loading branch information
Showing
4 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |