diff --git a/src/pages/playground.tsx b/src/pages/playground.tsx index a8a96b04..c9e29554 100644 --- a/src/pages/playground.tsx +++ b/src/pages/playground.tsx @@ -2,6 +2,7 @@ import { BannerCard } from '@shared/ui/BannerCard/BannerCard'; import { Button } from '@shared/ui/Button/Button'; import { Card } from '@shared/ui/Card/Card'; import { Checkbox } from '@shared/ui/Checkbox/Checkbox'; +import { FavoriteButton } from '@shared/ui/FavoriteButton'; import { Header } from '@shared/ui/Header/Header'; import { Modal } from '@shared/ui/Modal/Modal'; import { Profile } from '@shared/ui/Profile/Profile'; @@ -121,6 +122,16 @@ export default function Playground() {

SearchBar

{}} /> + {/* Favorite Button */} +
+

FavoriteButton

+
+ +
+ +
+
+
{/* BannerCard */}

Banner Card

diff --git a/src/shared/assets/icons/common/heart-outline.svg b/src/shared/assets/icons/common/heart-outline.svg new file mode 100644 index 00000000..514dd178 --- /dev/null +++ b/src/shared/assets/icons/common/heart-outline.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/shared/assets/icons/common/index.ts b/src/shared/assets/icons/common/index.ts index 562fe5b9..648a0528 100644 --- a/src/shared/assets/icons/common/index.ts +++ b/src/shared/assets/icons/common/index.ts @@ -2,3 +2,4 @@ export { default as CaretDownMdIcon } from './caret-down-md.svg?react'; export { default as CheckIcon } from './check.svg?react'; export { default as DoneIcon } from './done.svg?react'; export { default as SearchMagnifyingGlassIcon } from './search-magnifying-glass.svg?react'; +export { default as HeartIcon } from './heart-outline.svg?react'; diff --git a/src/shared/assets/icons/index.ts b/src/shared/assets/icons/index.ts index ca17fbf0..1ebdd8ce 100644 --- a/src/shared/assets/icons/index.ts +++ b/src/shared/assets/icons/index.ts @@ -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'; diff --git a/src/shared/ui/FavoriteButton/FavoriteButton.tsx b/src/shared/ui/FavoriteButton/FavoriteButton.tsx new file mode 100644 index 00000000..515fc547 --- /dev/null +++ b/src/shared/ui/FavoriteButton/FavoriteButton.tsx @@ -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(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 ( + + ); +}; diff --git a/src/shared/ui/FavoriteButton/FavoriteButton.variants.ts b/src/shared/ui/FavoriteButton/FavoriteButton.variants.ts new file mode 100644 index 00000000..b5289464 --- /dev/null +++ b/src/shared/ui/FavoriteButton/FavoriteButton.variants.ts @@ -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', + }, +}); diff --git a/src/shared/ui/FavoriteButton/index.ts b/src/shared/ui/FavoriteButton/index.ts new file mode 100644 index 00000000..b4c3a39e --- /dev/null +++ b/src/shared/ui/FavoriteButton/index.ts @@ -0,0 +1,2 @@ +export { FavoriteButton } from './FavoriteButton'; +export type { FavoriteButtonProps } from './FavoriteButton'; diff --git a/src/shared/ui/SearchBar/index.ts b/src/shared/ui/SearchBar/index.ts index 87859903..8c193316 100644 --- a/src/shared/ui/SearchBar/index.ts +++ b/src/shared/ui/SearchBar/index.ts @@ -1,2 +1 @@ export { SearchBar } from './SearchBar'; -export type { SearchBarProps } from './SearchBar';