-
Notifications
You must be signed in to change notification settings - Fork 4
[Feat] FavoriteButton 컴포넌트 제작 #40
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
The head ref may contain hidden characters: "39-feat/FavoriteButton-\uCEF4\uD3EC\uB10C\uD2B8-\uC81C\uC791"
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
31d1ee3
feat: 하트 아웃라인 아이콘 추가
YeBeenChoi f622c6f
feat: 하트 필드 아이콘 추가
YeBeenChoi feeefd4
chore: 하트 아이콘 export 추가
YeBeenChoi a976a9b
chore: 공용 아이콘 export 정리
YeBeenChoi 3b14eb3
feat: FavoriteButton 컴포넌트 구현
YeBeenChoi 7fbbe5a
feat: FavoriteButton 스타일 variants 추가
YeBeenChoi 73a9922
chore: FavoriteButton export 추가
YeBeenChoi ada484d
feat: Playground에 FavoriteButton 예시 추가
YeBeenChoi 062c06b
chore: SearchBar export 정리
YeBeenChoi fb0064e
chore: 공용 아이콘 export 수정
YeBeenChoi 870e954
refactor: FavoriteButton Props 타입 분리
YeBeenChoi 65e84eb
chore: FavoriteButton export 추가
YeBeenChoi 6bbfc5e
refactor: 하트 아이콘 currentColor 적용
YeBeenChoi 917e64e
refactor: 하트 필드 아이콘 제거
YeBeenChoi d7339ee
chore: 하트 아이콘 export 정리
YeBeenChoi 34491c4
chore: 공용 아이콘 export 정리
YeBeenChoi 986b8f4
refactor: FavoriteButton 아이콘 색상 상태 처리 개선
YeBeenChoi 44a1922
refactor: FavoriteButton 아이콘 색상 스타일 정리
YeBeenChoi 83aa825
refactor: 하트 아이콘 변수 기반 fill/stroke 적용
YeBeenChoi a52581f
feat: FavoriteButton variant 옵션 추가
YeBeenChoi 02dd1bd
feat: FavoriteButton default/inverse 스타일 추가
YeBeenChoi 43a694e
feat: Playground에 FavoriteButton inverse 예시 추가
YeBeenChoi 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| export { CaretDownMdIcon, CheckIcon, DoneIcon, SearchMagnifyingGlassIcon } from './common'; | ||
| export { CaretDownMdIcon, CheckIcon, DoneIcon, HeartIcon, SearchMagnifyingGlassIcon } from './common'; | ||
| export { GearIcon, ShoppingIcon, SellIcon } from './banner'; |
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,47 @@ | ||
| import { HeartIcon } from '@shared/assets/icons'; | ||
| import clsx from 'clsx'; | ||
| import { useState } from 'react'; | ||
| import { favoriteButtonVariants } from './FavoriteButton.variants'; | ||
|
|
||
| export interface FavoriteButtonProps { | ||
| defaultActive?: boolean; | ||
| onToggle?: (isActive: boolean) => void; | ||
| ariaLabel?: string; | ||
| variant?: 'default' | 'inverse'; | ||
| } | ||
|
|
||
| export const FavoriteButton = ({ | ||
| defaultActive = false, | ||
| onToggle, | ||
| ariaLabel = '찜', | ||
| variant = 'default', | ||
| }: FavoriteButtonProps) => { | ||
| const [isActive, setActive] = useState<boolean>(defaultActive); | ||
|
|
||
| const styles = favoriteButtonVariants({ variant }); | ||
|
|
||
| const handleClick = () => { | ||
| const nextActive = !isActive; | ||
| setActive(nextActive); | ||
| onToggle?.(nextActive); | ||
| }; | ||
|
|
||
| const iconStateClassName = clsx( | ||
| 'fill-[var(--icon-fill)]', | ||
| 'stroke-[var(--icon-stroke)]', | ||
| isActive ? '[--icon-fill:var(--icon-fill-active)]' : '[--icon-fill:transparent]', | ||
| 'group-focus-visible:[--icon-fill:var(--icon-fill-active)]' | ||
| ); | ||
|
|
||
| return ( | ||
| <button | ||
| type="button" | ||
| className={styles.root()} | ||
| aria-pressed={isActive} | ||
| aria-label={ariaLabel} | ||
| onClick={handleClick} | ||
| > | ||
| <HeartIcon className={clsx(styles.icon(), iconStateClassName)} aria-hidden="true" /> | ||
| </button> | ||
| ); | ||
| }; |
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,23 @@ | ||
| import { tv } from 'tailwind-variants'; | ||
|
|
||
| export const favoriteButtonVariants = tv({ | ||
| slots: { | ||
| root: ['group inline-flex items-center justify-center', 'w-[44px] h-[44px]', 'transition-colors'], | ||
| icon: ['w-[33px] h-[29.26px]', 'transition-colors', '[--icon-fill-active:var(--color-green-300)]'], | ||
| }, | ||
|
|
||
| variants: { | ||
| variant: { | ||
| default: { | ||
| icon: ['[--icon-stroke:var(--color-black)]'], | ||
| }, | ||
| inverse: { | ||
| icon: ['[--icon-stroke:var(--color-white)]'], | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| defaultVariants: { | ||
| variant: 'default', | ||
| }, | ||
| }); |
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,2 @@ | ||
| export { FavoriteButton } from './FavoriteButton'; | ||
| export type { FavoriteButtonProps } from './FavoriteButton'; |
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 |
|---|---|---|
| @@ -1,2 +1 @@ | ||
| export { SearchBar } from './SearchBar'; | ||
| export type { SearchBarProps } from './SearchBar'; |
Oops, something went wrong.
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.
variant 속성이 없는 경우 tva 의존성을 주입할 필요가 없다고 저는 개인적으로 생각해서 Styles.ts로 분리했을 것 같습니다! 제 개인적인 생각이니 참고는 해보시는 것도 좋을 것 같아요!
Uh oh!
There was an error while loading. Please reload this page.
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.
의견 감사합니다! 피그마를 다시 살펴 보니 수리점 내역 화면에서도 테두리 색상이 반전된 FavoriteButton이 사용되고 있어서, default/inverse variant를 추가하면서 tv를 유지했습니다 또한 추후 카드 컴포넌트에 FavoriteButton이 추가될 경우 사이즈가 달라질 가능성도 있다고 생각해, 확장성을 고려하여 현재 구조를 유지했습니다! 필요하다면 styles로 분리하는 방향으로 수정해 보겠습니다 😀