-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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
53 changes: 53 additions & 0 deletions
53
client/src/features/CasperShowCase/TransitionCasperCardItem.tsx
This file contains 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,53 @@ | ||
import { useState } from "react"; | ||
import { CASPER_CARD_SIZE, CASPER_SIZE_OPTION } from "@/constants/CasperCustom/casper"; | ||
import useLazyLoading from "@/hooks/useLazyLoading"; | ||
import type { CasperCardType } from "@/types/casper"; | ||
import { CasperFlipCard } from "../CasperCustom/CasperFlipCard"; | ||
|
||
interface TransitionCasperCardItemProps { | ||
cardItem: CasperCardType; | ||
id: string; | ||
stopAnimation?: () => void; | ||
startAnimation?: () => void; | ||
} | ||
|
||
export function TransitionCasperCardItem({ | ||
cardItem, | ||
id, | ||
stopAnimation, | ||
startAnimation, | ||
}: TransitionCasperCardItemProps) { | ||
const [isFlipped, setIsFlipped] = useState<boolean>(false); | ||
const { isInView, cardRef } = useLazyLoading<HTMLLIElement>(); | ||
|
||
const handleMouseEnter = () => { | ||
stopAnimation && stopAnimation(); | ||
setIsFlipped(true); | ||
}; | ||
|
||
const handleMouseLeave = () => { | ||
startAnimation && startAnimation(); | ||
setIsFlipped(false); | ||
}; | ||
|
||
return ( | ||
<li | ||
ref={cardRef} | ||
key={id} | ||
onMouseEnter={handleMouseEnter} | ||
onMouseLeave={handleMouseLeave} | ||
style={{ | ||
width: CASPER_CARD_SIZE[CASPER_SIZE_OPTION.SM].CARD_WIDTH, | ||
height: CASPER_CARD_SIZE[CASPER_SIZE_OPTION.SM].CARD_HEIGHT, | ||
}} | ||
> | ||
{isInView && ( | ||
<CasperFlipCard | ||
card={cardItem} | ||
size={CASPER_SIZE_OPTION.SM} | ||
isFlipped={isFlipped} | ||
/> | ||
)} | ||
</li> | ||
); | ||
} |
This file contains 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 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,8 @@ | ||
import { SelectedCasperIdxType } from "./casperCustom"; | ||
|
||
export interface CasperCardType { | ||
id: number; | ||
casperName: string; | ||
expectations: string; | ||
selectedCasperIdx: SelectedCasperIdxType; | ||
} |