-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/button component #16
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
Changes from all commits
399e637
f4caccf
b6431f8
e589f6c
9e2fb1b
bb3ff56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| import Blur from "@/components/common/Blur"; | ||
| import Button from "@/components/ui/Button"; | ||
|
|
||
| export default function Home() { | ||
| return ( | ||
| <main> | ||
| <Blur /> | ||
| <Button fixed={true}>안녕하세요</Button> | ||
| </main> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,99 @@ | ||||||
| import React from "react"; | ||||||
| import { cn } from "@/lib/utils"; | ||||||
|
|
||||||
| interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||||||
| children: React.ReactNode; | ||||||
| backgroundColor?: string; | ||||||
| width?: string; | ||||||
| height?: string; | ||||||
| fixed?: boolean; | ||||||
| bottom?: number; // 하단 여백 (px) | ||||||
| sideGap?: number; // 좌우 여백 (px) | ||||||
| maxWidth?: number; // fixed일 때 최대 너비 (px) | ||||||
| textColor?: string; | ||||||
| fontSize?: string; | ||||||
| safeArea?: boolean; // safe-area-inset-bottom 적용 여부 | ||||||
| ref?: React.Ref<HTMLButtonElement>; | ||||||
| } | ||||||
|
|
||||||
| export default function Button({ | ||||||
| children, | ||||||
| backgroundColor = "bg-button-primary", | ||||||
| width = "w-full", | ||||||
| height = "h-12", | ||||||
| fixed = false, | ||||||
| bottom = 0, | ||||||
| sideGap = 16, | ||||||
| maxWidth = 430, | ||||||
| textColor = "text-button-primary-text-default", | ||||||
| fontSize = "typo-20-600", | ||||||
| safeArea = true, | ||||||
| disabled = false, | ||||||
| className, | ||||||
| ref, | ||||||
| type = "button", | ||||||
| ...props | ||||||
| }: ButtonProps) { | ||||||
| // disabled 상태에 따른 배경색/텍스트색 결정 | ||||||
| const finalBackgroundColor = disabled | ||||||
| ? "bg-button-background-disabled" | ||||||
| : backgroundColor; | ||||||
| const finalTextColor = disabled | ||||||
| ? "text-button-primary-text-disabled" | ||||||
| : textColor; | ||||||
|
|
||||||
| // bg-button-primary일 때 border와 shadow 추가 | ||||||
| const isPrimaryButton = finalBackgroundColor === "bg-button-primary"; | ||||||
|
|
||||||
| // fixed일 때 bottom 계산 (safeArea 적용) | ||||||
| const getBottomValue = () => { | ||||||
| if (!fixed) return undefined; | ||||||
|
|
||||||
| if (safeArea) { | ||||||
| return `calc(${bottom}px + env(safe-area-inset-bottom))`; | ||||||
| } | ||||||
|
|
||||||
| return `${bottom}px`; | ||||||
| }; | ||||||
|
|
||||||
| return ( | ||||||
| <button | ||||||
| ref={ref} | ||||||
| type={type} | ||||||
| disabled={disabled} | ||||||
| className={cn( | ||||||
| // 기본 스타일 | ||||||
| "flex items-center justify-center rounded-[12px] transition-colors duration-100", | ||||||
| finalBackgroundColor, | ||||||
| height, | ||||||
| finalTextColor, | ||||||
| fontSize, | ||||||
| // fixed 속성에 따른 분기 | ||||||
| fixed ? "fixed z-50 mx-auto" : width, | ||||||
| // disabled 상태에 따른 커서 | ||||||
| disabled ? "cursor-not-allowed" : "cursor-pointer", | ||||||
| className, | ||||||
| )} | ||||||
| style={{ | ||||||
| ...(fixed | ||||||
| ? { | ||||||
| bottom: getBottomValue(), | ||||||
| left: `${sideGap}px`, | ||||||
| right: `${sideGap}px`, | ||||||
| maxWidth: `${maxWidth}px`, | ||||||
| } | ||||||
| : undefined), | ||||||
| ...(isPrimaryButton | ||||||
| ? { | ||||||
| border: "0.8px solid rgba(255, 255, 255, 0.3)", | ||||||
| boxShadow: | ||||||
| "0px 4px 8px rgba(0, 0, 0, 0.08), 0px 0px 16px rgba(0, 0, 0, 0.16)", | ||||||
| } | ||||||
| : undefined), | ||||||
dasosann marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| }} | ||||||
| {...props} | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 웹 표준(스타일 가이드 규칙 80)을 준수하고 예기치 않은 동작을 방지하기 위해 버튼의
Suggested change
References
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type의 기본값을 button으로 설정완료 |
||||||
| > | ||||||
| {children} | ||||||
| </button> | ||||||
| ); | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.