-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT/#13] 버튼 컴포넌트 구현 #14
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -41,3 +41,8 @@ app-example | |
| # generated native folders | ||
| /ios | ||
| /android | ||
|
|
||
| # claude | ||
| .claudeignore | ||
| CLAUDE.md | ||
| CONVENTION.md | ||
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
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,22 @@ | ||
| import type { ReactNode } from "react"; | ||
| import { Pressable, type PressableProps, Text } from "react-native"; | ||
|
|
||
| interface Props extends PressableProps { | ||
| //PressableProps: 버튼 컴포넌트의 속성을 정의 | ||
| children: ReactNode; // ReactNode: 모든 타입의 자식 요소를 허용 | ||
| } | ||
|
|
||
| const SmallButton = ({ children, ...props }: Props) => { | ||
| return ( | ||
| <Pressable | ||
| {...props} | ||
| className="w-[11.4rem] h-[4.1rem] rounded-lg p-[0.625rem] justify-center items-center gap-[0.625rem] bg-neutral" | ||
| > | ||
| <Text className="text-[0.8125rem] leading-[1.3125rem] tracking-[-0.02rem] text-content-secondary font-semibold"> | ||
| {children} | ||
| </Text> | ||
| </Pressable> | ||
| ); | ||
| }; | ||
|
|
||
| export { SmallButton }; | ||
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,48 @@ | ||
| import { Pressable, Text } from "react-native"; | ||
|
|
||
| interface Props { | ||
| title: string; | ||
| description: string; | ||
| isSelected: boolean; | ||
| onPress: () => void; | ||
| } | ||
|
|
||
| const BenefitSelectButton = ({ | ||
| title, | ||
| description, | ||
| isSelected, | ||
| onPress, | ||
| }: Props) => { | ||
| return ( | ||
| <Pressable | ||
| onPress={onPress} | ||
| className={` | ||
| w-[21.5625rem] py-[0.6875rem] flex flex-col items-center rounded-[0.625rem] border-[0.5px] | ||
| ${ | ||
| isSelected | ||
| ? "border-primary bg-primary-tint" | ||
| : "border-content-secondary bg-neutral" | ||
| } | ||
| `} | ||
| > | ||
| <Text | ||
| className={` | ||
| self-stretch text-center text-[0.875rem] leading-[1.6875rem] tracking-[0.01563rem] font-semibold | ||
| ${isSelected ? "text-primary" : "text-content-primary"} | ||
| `} | ||
| > | ||
| {title} | ||
| </Text> | ||
| <Text | ||
| className={` | ||
| self-stretch text-center text-[0.875rem] leading-[1.3125rem] tracking-[-0.02rem] font-regular | ||
| ${isSelected ? "text-primary" : "text-content-secondary"} | ||
| `} | ||
| > | ||
| {description} | ||
| </Text> | ||
| </Pressable> | ||
| ); | ||
| }; | ||
|
|
||
| export { BenefitSelectButton }; |
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,42 @@ | ||
| import { useState } from "react"; | ||
| import { View } from "react-native"; | ||
| import { BenefitSelectButton } from "./BenefitSelectButton"; | ||
|
|
||
| interface BenefitOption { | ||
| title: string; | ||
| description: string; | ||
| } | ||
|
|
||
| interface Props { | ||
| options: BenefitOption[]; | ||
| onSelect?: (index: number) => void; | ||
| } | ||
|
|
||
| const BenefitSelectionGroup = ({ options, onSelect }: Props) => { | ||
| const [selectedIndex, setSelectedIndex] = useState<number | null>(null); | ||
|
|
||
| const handlePress = (index: number) => { | ||
| const nextIndex = selectedIndex === index ? null : index; | ||
| setSelectedIndex(nextIndex); | ||
| if (nextIndex !== null) { | ||
| onSelect?.(nextIndex); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <View className="items-center gap-[0.625rem]"> | ||
| {options.map((option, index) => ( | ||
| <BenefitSelectButton | ||
| key={`${option.title}-${index}`} | ||
| title={option.title} | ||
| description={option.description} | ||
| isSelected={selectedIndex === index} | ||
| onPress={() => handlePress(index)} | ||
| /> | ||
| ))} | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| export { BenefitSelectionGroup }; | ||
| export type { BenefitOption }; |
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,21 @@ | ||
| import type { ReactNode } from "react"; | ||
| import { Pressable, type PressableProps, Text } from "react-native"; | ||
|
|
||
| interface Props extends PressableProps { | ||
| children: ReactNode; | ||
| } | ||
|
|
||
| const MediumButton = ({ children, ...props }: Props) => { | ||
| return ( | ||
| <Pressable | ||
| {...props} | ||
| className="w-[21.5625rem] px-[6.25rem] py-[1.12rem] justify-center items-center gap-[0.625rem] rounded-[0.75rem] bg-primary" | ||
| > | ||
| <Text className="text-center text-[1.25rem] leading-[1.25rem] tracking-[0.01563rem] font-bold text-content-inverse"> | ||
| {children} | ||
| </Text> | ||
| </Pressable> | ||
| ); | ||
| }; | ||
|
|
||
| export { MediumButton }; |
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,172 @@ | ||
| # Button Components | ||
|
|
||
| --- | ||
|
|
||
| ## SmallButton | ||
|
|
||
| 회색 배경의 소형 버튼입니다. | ||
|
|
||
| | 속성 | 값 | | ||
| | ------ | ----------------------------------------------- | | ||
| | 너비 | 11.4rem | | ||
| | 높이 | 4.1rem | | ||
| | 배경 | `bg-neutral` | | ||
| | 텍스트 | `text-content-secondary` / 0.8125rem / SemiBold | | ||
|
|
||
| **Props** — `PressableProps` 확장 (`onPress`, `disabled`, `style` 등 사용 가능) | ||
|
|
||
| ### 사용 예시 | ||
|
|
||
| ```tsx | ||
| import { SmallButton } from "@/shared/ui/buttons/ActionButton"; | ||
|
|
||
| export default function MyScreen() { | ||
| return ( | ||
| <SmallButton onPress={() => console.log("pressed")}> | ||
| 제휴 리뷰 작성하기 | ||
| </SmallButton> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| 비활성화: | ||
|
|
||
| ```tsx | ||
| <SmallButton disabled>제휴 리뷰 작성하기</SmallButton> | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## MediumButton | ||
|
|
||
| 파란색 배경의 중형 액션 버튼입니다. | ||
|
|
||
| | 속성 | 값 | | ||
| | ------ | --------------------------------------- | | ||
| | 너비 | 21.5625rem | | ||
| | 패딩 | 1.12rem (상하) / 6.25rem (좌우) | | ||
| | 배경 | `bg-primary` | | ||
| | 텍스트 | `text-content-inverse` / 1.25rem / Bold | | ||
|
|
||
| **Props** — `PressableProps` 확장 (`onPress`, `disabled`, `style` 등 사용 가능) | ||
|
|
||
| ### 사용 예시 | ||
|
|
||
| ```tsx | ||
| import { MediumButton } from "@/shared/ui/buttons/SubmitButton"; | ||
|
|
||
| export default function MyScreen() { | ||
| return ( | ||
| <MediumButton onPress={() => console.log("pressed")}>인증완료</MediumButton> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| 비활성화: | ||
|
|
||
| ```tsx | ||
| <MediumButton disabled>인증완료</MediumButton> | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## BenefitSelectButton | ||
|
|
||
| 제목 + 설명을 포함하는 혜택 선택 버튼입니다. **개별 버튼 컴포넌트**로, 선택 상태를 외부에서 관리받습니다. | ||
|
|
||
| | 상태 | 테두리 | 배경 | | ||
| | ---- | -------------------------- | ----------------- | | ||
| | 기본 | `border-content-secondary` | `bg-neutral` | | ||
| | 선택 | `border-primary` | `bg-primary-tint` | | ||
|
|
||
| **Props** | ||
|
|
||
| | prop | 타입 | 필수 | 설명 | | ||
| | ------------- | ------------ | ---- | ----------- | | ||
| | `title` | `string` | ✓ | 버튼 제목 | | ||
| | `description` | `string` | ✓ | 버튼 설명 | | ||
| | `isSelected` | `boolean` | ✓ | 선택 여부 | | ||
| | `onPress` | `() => void` | ✓ | 클릭 핸들러 | | ||
|
|
||
| ### 사용 예시 | ||
|
|
||
| ```tsx | ||
| import { BenefitSelectButton } from "@/shared/ui/buttons/BenefitSelectButton"; | ||
| import { useState } from "react"; | ||
|
|
||
| export default function MyScreen() { | ||
| const [isSelected, setIsSelected] = useState(false); | ||
|
|
||
| return ( | ||
| <BenefitSelectButton | ||
| title="IT대학 학생회" | ||
| description="IT대학 학생인증 시, 10% 할인" | ||
| isSelected={isSelected} | ||
| onPress={() => setIsSelected(!isSelected)} | ||
| /> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| > **주의**: `BenefitSelectButton`은 개별 버튼 컴포넌트이므로 상태 관리가 필요합니다. | ||
| > 여러 버튼을 함께 사용할 때는 **`BenefitSelectionGroup`** 사용을 권장합니다. | ||
|
|
||
| --- | ||
|
|
||
| ## BenefitSelectionGroup | ||
|
|
||
| 여러 개의 혜택 옵션 중 하나를 선택하는 **라디오 버튼 그룹 컴포넌트**입니다. | ||
| 옵션 배열만 전달하면 자동으로 `BenefitSelectButton`들을 렌더링하고, 라디오 버튼처럼 동작하여 **한 번에 하나의 버튼만 선택**됩니다. | ||
|
|
||
| **Props** | ||
|
|
||
| | prop | 타입 | 필수 | 설명 | | ||
| | ---------- | ------------------------- | ---- | --------------------------------- | | ||
| | `options` | `BenefitOption[]` | ✓ | 혜택 옵션 배열 | | ||
| | `onSelect` | `(index: number) => void` | | 옵션 선택 시 콜백 (선택된 인덱스) | | ||
|
|
||
| **BenefitOption 타입** | ||
|
|
||
| ```tsx | ||
| interface BenefitOption { | ||
| title: string; // 버튼 제목 | ||
| description: string; // 버튼 설명 | ||
| } | ||
| ``` | ||
|
|
||
| ### 사용 예시 | ||
|
|
||
| ```tsx | ||
| import { BenefitSelectionGroup } from "@/shared/ui/buttons/BenefitSelectionGroup"; | ||
|
|
||
| export default function BenefitScreen() { | ||
| const benefits = [ | ||
| { | ||
| title: "컴퓨터학부 학생회", | ||
| description: "4인이상 식사시, 캔 음료 제공", | ||
| }, | ||
| { | ||
| title: "IT대학 학생회", | ||
| description: "4인이상 식사시, 캔 음료 제공", | ||
| }, | ||
| { | ||
| title: "IT대학 학생회", | ||
| description: "15,000원 이상 주문시 파인애플 샤베트 제공", | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <BenefitSelectionGroup | ||
| options={benefits} | ||
| onSelect={(index) => console.log(`선택된 혜택: ${index}`)} | ||
| /> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ### 동작 설명 | ||
|
|
||
| - 옵션을 클릭하면 해당 버튼이 선택 상태로 변경됩니다. | ||
| - 이미 선택된 버튼을 다시 클릭하면 선택이 해제됩니다. | ||
| - 다른 버튼을 클릭하면 이전 선택이 자동으로 해제되고 새 버튼이 선택됩니다. | ||
| - `onSelect` 콜백으로 선택된 버튼의 인덱스를 받을 수 있습니다.. |
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
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.
PressableProps와ReactNode에 대한 주석은 불필요하게 코드를 복잡하게 만들 수 있습니다. 이들은 일반적으로 TypeScript 개발자들에게 익숙한 표준 타입이므로, 주석 없이도 충분히 이해할 수 있습니다. 코드를 더 간결하게 유지하기 위해 제거하는 것을 고려해 보세요.