Skip to content

Commit

Permalink
Feat: HeartButton 컴포넌트 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
se0kcess committed Sep 27, 2024
1 parent 46b3fa4 commit 27d45a0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/components/HeartButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useState } from 'react';
import { faHeart as farHeart } from '@fortawesome/free-regular-svg-icons';
import { faHeart as fasHeart } from '@fortawesome/free-solid-svg-icons';
import * as S from './styles';

interface HeartButtonProps {
initialClicked?: boolean;
onClick?: (isClicked: boolean) => void;
}

export const HeartButton = ({ initialClicked = false, onClick }: HeartButtonProps) => {
const [isClicked, setIsClicked] = useState(initialClicked);

const handleClick = () => {
const newClickedState = !isClicked;
setIsClicked(newClickedState);
if (onClick) {
onClick(newClickedState);
}
};

return <S.HeartButton icon={isClicked ? fasHeart : farHeart} $isClicked={isClicked} onClick={handleClick} />;
};
9 changes: 9 additions & 0 deletions src/components/HeartButton/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { styled } from 'styled-components';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

export const HeartButton = styled(FontAwesomeIcon)<{ $isClicked: boolean }>`
color: ${({ theme, $isClicked }) => ($isClicked ? theme.colors.primary : theme.colors.gray)};
cursor: pointer;
transition: color 0.1s ease;
font-size: 18px;
`;

0 comments on commit 27d45a0

Please sign in to comment.