-
Notifications
You must be signed in to change notification settings - Fork 4
[feat] 버튼 컴포넌트 생성 #25
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8d2496a
feat: 버튼 컴포넌트 생성
almighty55555 4d44a91
Merge branch 'dev' of https://github.com/CodeitPart3/thejulge into CO…
almighty55555 f6d18c7
refactor: disabled 상태와 variantClass 코드 개선
almighty55555 1617d13
Merge branch 'dev' of https://github.com/CodeitPart3/thejulge into CO…
almighty55555 8141fc0
refactor: 버튼 컴포넌트에 clsx 반영
almighty55555 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 hidden or 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,61 @@ | ||||||||||||||||||||||||||||||||
| import React from "react"; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| type ButtonVariant = "primary" | "white" | "disabled"; | ||||||||||||||||||||||||||||||||
| type ButtonTextSize = "lg" | "md" | "sm"; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||||||||||||||||||||||||||||||||
| variant?: ButtonVariant; | ||||||||||||||||||||||||||||||||
| textSize?: ButtonTextSize; | ||||||||||||||||||||||||||||||||
| fullWidth?: boolean; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const textSizeClassMap: Record<ButtonTextSize, string> = { | ||||||||||||||||||||||||||||||||
| lg: "text-base font-bold leading-5", | ||||||||||||||||||||||||||||||||
| md: "text-sm font-bold leading-none", | ||||||||||||||||||||||||||||||||
| sm: "text-xs font-normal leading-4", | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| export default function Button({ | ||||||||||||||||||||||||||||||||
| variant = "primary", | ||||||||||||||||||||||||||||||||
| textSize = "md", | ||||||||||||||||||||||||||||||||
| fullWidth = false, | ||||||||||||||||||||||||||||||||
| className, | ||||||||||||||||||||||||||||||||
| children, | ||||||||||||||||||||||||||||||||
| ...props | ||||||||||||||||||||||||||||||||
| }: ButtonProps) { | ||||||||||||||||||||||||||||||||
| const baseClasses = "rounded-md"; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| let variantClass = ""; | ||||||||||||||||||||||||||||||||
| if (variant === "primary") { | ||||||||||||||||||||||||||||||||
| variantClass = | ||||||||||||||||||||||||||||||||
| "bg-[#EA3C12] text-white hover:bg-[#ca3f2a] active:bg-[#aa3523]"; | ||||||||||||||||||||||||||||||||
| } else if (variant === "white") { | ||||||||||||||||||||||||||||||||
| variantClass = | ||||||||||||||||||||||||||||||||
| "bg-white text-[#EA3C12] border border-[#EA3C12] hover:bg-[#fff5f3] active:bg-[#ffe5e0]"; | ||||||||||||||||||||||||||||||||
| } else if (variant === "disabled") { | ||||||||||||||||||||||||||||||||
| variantClass = "bg-gray-40 text-white cursor-not-allowed"; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| if (variant === "primary") { | |
| variantClass = | |
| "bg-[#EA3C12] text-white hover:bg-[#ca3f2a] active:bg-[#aa3523]"; | |
| } else if (variant === "white") { | |
| variantClass = | |
| "bg-white text-[#EA3C12] border border-[#EA3C12] hover:bg-[#fff5f3] active:bg-[#ffe5e0]"; | |
| } else if (variant === "disabled") { | |
| variantClass = "bg-gray-40 text-white cursor-not-allowed"; | |
| } | |
| const variantClassMap: Record<ButtonVariant, string> = { | |
| primary: "bg-[#EA3C12] text-white hover:bg-[#ca3f2a] active:bg-[#aa3523]", | |
| white: | |
| "bg-white text-[#EA3C12] border border-[#EA3C12] hover:bg-[#fff5f3] active:bg-[#ffe5e0]", | |
| disabled: "bg-gray-400 text-white cursor-not-allowed", | |
| }; |
...
const finalClassName = [
...
variantClassMap[variant]
...
] ...
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.
disabled는 버튼의 상태를 나타내는 속성으로 봐도 좋을 것 같습니다 !
그래서 속성값으로 넣어도 좋을 것 같아요 !