-
Notifications
You must be signed in to change notification settings - Fork 2
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
Make LinkButton Component Responsive #51
Merged
+162
−143
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,151 @@ | ||
const css = /*css*/ ` | ||
<style> | ||
/* Default: Extra-small devices such as small phones (less than 640px) */ | ||
a { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: max-content; | ||
text-align: center; | ||
} | ||
a.secondary { | ||
color: #000; | ||
background-color: #d9d9d9; | ||
} | ||
a.small { | ||
height: 35px; | ||
padding: 10px 20px; | ||
font-size: 13px; | ||
border-radius: 7px; | ||
} | ||
a.big { | ||
height: 45px; | ||
padding: 10px 25px; | ||
font-size: 14px; | ||
border-radius: 10px; | ||
} | ||
a.ghost { | ||
border: none; | ||
border-radius: 0; | ||
height: min-content; | ||
} | ||
a.small.ghost { | ||
padding: 0; | ||
} | ||
a.big.ghost { | ||
padding: auto; | ||
color: #000; | ||
background-color: transparent; | ||
border: 1px solid #000; | ||
border-radius: 10px; | ||
} | ||
/* Medium devices such as tablets (768px and up) */ | ||
@media only screen and (min-width: 768px) { | ||
a.small { | ||
padding: 5px 25px; | ||
font-size: 14px; | ||
} | ||
a.big { | ||
padding: 16px 40px; | ||
font-size: 20px; | ||
} | ||
} | ||
/* Large devices such as laptops (1024px and up) */ | ||
@media only screen and (min-width: 1024px) { | ||
a.small { | ||
padding: 5px 30px; | ||
font-size: 16px; | ||
} | ||
} | ||
</style> | ||
`; | ||
|
||
const html = /*html*/ ` | ||
<link rel="stylesheet" href="./global-styles.css" /> | ||
<a> | ||
<slot></slot> | ||
</a> | ||
`; | ||
|
||
class ButtonLink extends HTMLElement { | ||
constructor() { | ||
super(); | ||
|
||
this.attachShadow({ | ||
mode: "open", | ||
}); | ||
this.shadowRoot.innerHTML = css + html; | ||
|
||
this.setDefaultAttributes(); | ||
this.validateAttributes(); | ||
this.updateAttributes(); | ||
} | ||
|
||
validateAttributes() { | ||
if (!this.hasAttribute("href")) { | ||
throw new Error('The "href" attribute is required.'); | ||
} | ||
|
||
if (this.hasAttribute("size")) { | ||
const size = this.getAttribute("size"); | ||
const validSizes = ["big", "small"]; | ||
|
||
if (!validSizes.includes(size)) { | ||
throw new Error( | ||
`The "size" attribute must be one of ${validSizes.join(", ")}.` | ||
); | ||
} | ||
} | ||
|
||
if (this.hasAttribute("variant")) { | ||
const variant = this.getAttribute("variant"); | ||
const validVariants = ["ghost", "secondary"]; | ||
|
||
if (!validVariants.includes(variant)) { | ||
throw new Error( | ||
`The "variant" attribute must be one of ${validVariants.join(", ")}.` | ||
); | ||
} | ||
} | ||
} | ||
|
||
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")); | ||
} | ||
} | ||
} | ||
|
||
customElements.define("ds-button-link", ButtonLink); |
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 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,6 +1,6 @@ | ||
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/button-link.js"; | ||
import "./components/review-item/review-item.js"; | ||
import "./components/seo-meta-tag/seo-meta-tag.js"; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SamTheKorean header 컴포넌트 내부에서 button link 컴포넌트를 사용하고 있습니다. 그런데 button link의 사용법에 변경이 발생하면(지금처럼 이름이 변경되거나 전달해야 하는 attribute가 달라졌을 경우), HTML 파일에서뿐만 아니라 header 안에서도 변경을 해야 합니다. 이런 컴포넌트 사용이 많아질수록 하나를 변경했을 때, 같이 변경해야 하는 지점이 많아집니다. 이는 미래에 유지보수가 힘들어질 수 있는 신호이기도 합니다. 이것은 정말 문제가 맞을지? 맞다면 어떻게 해결할 수 있을지? 천천히 생각해보아요!
cc. @DaleStudy/website