-
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.
- Loading branch information
Showing
6 changed files
with
148 additions
and
144 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
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,120 @@ | ||
const template = document.createElement("template"); | ||
|
||
template.innerHTML = /*html*/ ` | ||
<style> | ||
a { | ||
text-decoration: none; | ||
color: inherit; | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
cursor: pointer; | ||
border-radius: 5px; | ||
display: inline-block; | ||
margin: 5px; | ||
background-color: #f0f0f0; | ||
} | ||
a:hover { | ||
background-color: #e0e0e0; | ||
} | ||
/* Outline style */ | ||
a.outline { | ||
border: 1px solid #000; | ||
} | ||
/* Size variants */ | ||
a.small { | ||
padding: 5px 10px; | ||
font-size: 14px; | ||
} | ||
a.big { | ||
padding: 15px 30px; | ||
font-size: 18px; | ||
} | ||
/* Style variants */ | ||
a.ghost { | ||
background-color: transparent; | ||
border: none; | ||
color: #000; | ||
} | ||
a.ghost:hover { | ||
background-color: rgba(0, 0, 0, 0.1); | ||
} | ||
/* Combined ghost and outline styles */ | ||
a.ghost.outline { | ||
border: 1px solid #000; | ||
} | ||
a.secondary { | ||
background-color: #d9d9d9; | ||
border: 1px solid #d9d9d9; | ||
color: #000; | ||
} | ||
a.secondary:hover { | ||
background-color: #b0b0b0; | ||
border: 1px solid #b0b0b0; | ||
} | ||
</style> | ||
<a href="#"> | ||
<slot></slot> | ||
</a> | ||
`; | ||
|
||
class LinkButton extends HTMLElement { | ||
constructor() { | ||
super(); | ||
|
||
this.attachShadow({ | ||
mode: "open", | ||
}); | ||
this.shadowRoot.appendChild(template.content.cloneNode(true)); | ||
|
||
this.validateAttributes(); | ||
this.setDefaultAttributes(); | ||
this.updateAttributes(); | ||
} | ||
|
||
validateAttributes() { | ||
if (!this.hasAttribute("href")) { | ||
throw new Error('The "href" attribute is required.'); | ||
} | ||
} | ||
|
||
setDefaultAttributes() { | ||
if (!this.hasAttribute("size")) { | ||
this.setAttribute("size", "small"); | ||
} | ||
if (!this.hasAttribute("variant")) { | ||
this.setAttribute("variant", "ghost"); | ||
} | ||
} | ||
|
||
updateAttributes() { | ||
const link = this.shadowRoot.querySelector("a"); | ||
link.setAttribute("href", this.getAttribute("href")); | ||
|
||
// Set target to "_blank" only for external links | ||
if (!this.getAttribute("href").startsWith("#")) { | ||
link.setAttribute("target", "_blank"); | ||
} | ||
|
||
if (this.hasAttribute("size")) { | ||
link.classList.add(this.getAttribute("size")); | ||
} | ||
if (this.hasAttribute("variant")) { | ||
link.classList.add(this.getAttribute("variant")); | ||
} | ||
if (this.hasAttribute("outline")) { | ||
link.classList.add("outline"); | ||
} | ||
} | ||
} | ||
|
||
customElements.define("link-button", LinkButton); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
import "./components/divider/divider.js"; | ||
import "./components/footer-link/footer-link.js"; | ||
import "./components/header.js" | ||
import "./components/header.js"; | ||
import "./components/hero/hero.js"; | ||
import "./components/link-button/link-button.js"; | ||
import "./components/link-button.js"; | ||
import "./components/review-item/review-item.js"; | ||
import "./components/seo-meta-tag/seo-meta-tag.js"; | ||
|