-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add hide/reveal logic on words
- Loading branch information
1 parent
875f3b2
commit ccd8047
Showing
8 changed files
with
115 additions
and
26 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
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,65 @@ | ||
import React, { useState } from "react" | ||
import { Eye, EyeOff, BookOpen, Check, X } from "lucide-react" | ||
import { | ||
Card, | ||
CardContent, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from "@ui/components/ui/card" | ||
import { Button } from "@ui/components/ui/button" | ||
import { Word } from "@repo/types/words.ts" | ||
|
||
type WordCardProps = { | ||
word: Word | ||
} | ||
|
||
export const WordCard: React.FC<WordCardProps> = ({ word }) => { | ||
const [showMeaning, setShowMeaning] = useState(false) | ||
|
||
const handleCardClick = (e: React.MouseEvent<HTMLDivElement>) => { | ||
if (!(e.target as HTMLElement).closest("button")) { | ||
setShowMeaning(!showMeaning) | ||
} | ||
} | ||
return ( | ||
<Card onClick={handleCardClick} className="w-full max-w-md"> | ||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2"> | ||
<CardTitle className="text-2xl font-bold">{word.word}</CardTitle> | ||
<div className="flex items-center space-x-2"> | ||
<Button | ||
variant="ghost" | ||
size="icon" | ||
onClick={() => setShowMeaning(!showMeaning)} | ||
aria-label={showMeaning ? "Hide meaning" : "Show meaning"} | ||
> | ||
{showMeaning ? ( | ||
<EyeOff className="h-4 w-4" /> | ||
) : ( | ||
<Eye className="h-4 w-4" /> | ||
)} | ||
</Button> | ||
<Button variant="ghost" size="icon" aria-label="Ignore word"> | ||
<X className="h-4 w-4" /> | ||
</Button> | ||
</div> | ||
</CardHeader> | ||
{showMeaning && ( | ||
<CardContent> | ||
<p className="text-muted-foreground mb-1">{word.translation}</p> | ||
<p className="font-medium">{word.meaning}</p> | ||
</CardContent> | ||
)} | ||
<CardFooter className="flex justify-between"> | ||
<Button variant="secondary" size="sm"> | ||
<BookOpen className="mr-2 h-4 w-4" /> | ||
Learn | ||
</Button> | ||
<Button variant="outline" size="sm"> | ||
<Check className="mr-2 h-4 w-4" /> | ||
Known word | ||
</Button> | ||
</CardFooter> | ||
</Card> | ||
) | ||
} |
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
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
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,36 @@ | ||
import * as React from "react" | ||
import { cva, type VariantProps } from "class-variance-authority" | ||
|
||
import { cn } from "@ui/lib/utils" | ||
|
||
const badgeVariants = cva( | ||
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", | ||
{ | ||
variants: { | ||
variant: { | ||
default: | ||
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80", | ||
secondary: | ||
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", | ||
destructive: | ||
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80", | ||
outline: "text-foreground", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
}, | ||
}, | ||
) | ||
|
||
export interface BadgeProps | ||
extends React.HTMLAttributes<HTMLDivElement>, | ||
VariantProps<typeof badgeVariants> {} | ||
|
||
function Badge({ className, variant, ...props }: BadgeProps) { | ||
return ( | ||
<div className={cn(badgeVariants({ variant }), className)} {...props} /> | ||
) | ||
} | ||
|
||
export { Badge, badgeVariants } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.