-
Notifications
You must be signed in to change notification settings - Fork 5
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
the card component #84
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React, { forwardRef } from 'react'; | ||
|
||
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||
|
||
} | ||
|
||
const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => { | ||
const { className, children, ...rest } = props; | ||
|
||
const buttonClasses = `bg-blue-500 hover:md:bg-opacity-80 text-white font-bold py-2 px-4 rounded ${className}`; | ||
|
||
return ( | ||
<button ref={ref} className={buttonClasses} {...rest}> | ||
{children} | ||
</button> | ||
); | ||
}); | ||
|
||
Button.displayName = 'Button'; | ||
|
||
export default Button; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { useState } from 'react'; | ||
import { PiSpeakerHighFill } from "react-icons/pi"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have fontawesome installed as a dependency - can we use an icon from there? |
||
|
||
const Card: React.FC<{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can import this in line 1 similar to how you did There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same with React.MouseEvent below |
||
Word: string; | ||
TranslatedWord: string; | ||
Pronunciation: string; | ||
DevenagiriSpelling: string; | ||
ImageUrl: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These types look great! A few things to account for - the ImageUrl and PronounciationUrl should be optional because not all words from the API have them available. |
||
PronounciationUrl: string; | ||
}> = ({ Word, TranslatedWord, Pronunciation, DevenagiriSpelling, ImageUrl, PronounciationUrl }) => { | ||
const [isFlipped, setIsFlipped] = useState(false); | ||
const [audio, setAudio] = useState<HTMLAudioElement | null>(null); | ||
|
||
const handleFlip = () => { | ||
setIsFlipped(!isFlipped); | ||
}; | ||
|
||
const handlePronunciation = (event: React.MouseEvent) => { | ||
event.stopPropagation(); // Prevent the card from flipping | ||
if (audio) { | ||
if (!audio.paused) { | ||
audio.pause(); | ||
audio.currentTime = 0; | ||
} else { | ||
audio.play(); | ||
} | ||
} else { | ||
const newAudio = new Audio(PronounciationUrl); | ||
setAudio(newAudio); | ||
newAudio.play(); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className={`border-2 border-slate-400 relative w-96 h-72 ${isFlipped ? 'flipped' : ''}`} onClick={handleFlip} style={{ perspective: '1000px' }}> | ||
<div className="text-4xl font-bold absolute inset-0 text-black flex justify-center items-center backface-hidden" style={{ transform: isFlipped ? 'rotateY(180deg)' : 'rotateY(0deg)', transition: 'transform 0.6s' }}> | ||
{!isFlipped && <div>{Word}</div>} | ||
</div> | ||
<div className="absolute inset-0 bg-white text-black flex justify-center items-center backface-hidden transform rotateY-180 font-bold" style={{ transform: isFlipped ? 'rotateY(0deg)' : 'rotateY(-180deg)', transition: 'transform 0.6s' }}> | ||
<div className="flex flex-col items-start justify-center"> | ||
<img src={ImageUrl} alt={Word} className="absolute left-2 top-1/2 transform -translate-y-1/2 object-cover w-40 h-60" /> | ||
<p className="absolute right-10 top-16 text-2xl font-bold">{TranslatedWord}</p> | ||
<p className="absolute right-10 top-28 text-sm">{DevenagiriSpelling}</p> | ||
<p className="absolute right-10 top-36 text-xs">{Pronunciation}</p> | ||
<button onClick={handlePronunciation} className="absolute right-10 bottom-10"> | ||
<PiSpeakerHighFill /> | ||
|
||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Card; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
@tailwind base; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you make sure that lint runs on this file - the spacing looks a bit off There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the lint catches formatting issues like this, but try to get rid of the extra spaces in this file. Fix any errors that appear for your files, you can ignore the errors that appear related to |
||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
.backface-hidden { | ||
backface-visibility: hidden; | ||
} | ||
|
||
.flipped .rotateY-180 { | ||
transform: rotateY(0deg); | ||
} | ||
|
||
.flipped .rotateY-0 { | ||
transform: rotateY(-180deg); | ||
} | ||
|
||
.rotateY-180 { | ||
transform: rotateY(180deg); | ||
} | ||
|
||
.rotateY-0 { | ||
transform: rotateY(0deg); | ||
} |
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.
did you also delete the old
button.tsx
file?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.
I don't think so, i think i just renamed the old botton.tsx