-
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.
refactor: extract a component for the quiz option
- Loading branch information
1 parent
90b00b7
commit 639d4e4
Showing
2 changed files
with
43 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as React from "react"; | ||
import { cn } from "@/lib/utils"; | ||
import { Button } from "./ui/button"; | ||
import { CircleCheck } from "lucide-react"; | ||
|
||
export type QuizOptionProps = { | ||
onClick: () => void; | ||
isSelected: boolean; | ||
display: string; | ||
value: string | boolean; | ||
}; | ||
|
||
export const QuizOption = React.memo(function QuizOption({ | ||
onClick, | ||
isSelected, | ||
display, | ||
value, | ||
}: QuizOptionProps) { | ||
return ( | ||
<Button | ||
onClick={onClick} | ||
variant="outline" | ||
className={cn("mt-2 h-auto flex flex-col relative", { | ||
"ring-2 ring-primary": isSelected, | ||
// TODO: only apply this after clicking the option because otherwise, when navigating back to a question, | ||
// the selected option will blink. | ||
"animate-blink": isSelected, | ||
})} | ||
> | ||
{isSelected ? ( | ||
<CircleCheck className="h-5 w-5 text-primary absolute top-2 right-2" /> | ||
) : null} | ||
<span dangerouslySetInnerHTML={{ __html: display }} /> | ||
{value} | ||
</Button> | ||
); | ||
}); |
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