generated from theodorusclarence/ts-nextjs-tailwind-starter
-
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
1 parent
0fdd567
commit b025bfe
Showing
2 changed files
with
103 additions
and
0 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,50 @@ | ||
'use client'; | ||
|
||
import * as React from 'react'; | ||
import { BsFillCheckCircleFill, BsFillXSquareFill } from 'react-icons/bs'; | ||
|
||
export interface QuizAnswer { | ||
headline: string; | ||
key?: string; | ||
} | ||
|
||
export interface QuizAnswersProps { | ||
answers: QuizAnswer[]; | ||
falseOption?: string; | ||
answeredCorrectly: boolean; | ||
} | ||
|
||
const QuizAnswers = ({ | ||
answers, | ||
falseOption, | ||
answeredCorrectly, | ||
}: QuizAnswersProps) => { | ||
return ( | ||
<div className='p4 rounded dark:bg-slate-900'> | ||
<ul> | ||
{answers.map((answer) => ( | ||
<li className='mb-4 flex flex-row' key={answer.key}> | ||
<span className='me-3 text-xl'> | ||
{answer.key == falseOption ? ( | ||
<BsFillXSquareFill className='fill-current text-red-600' /> | ||
) : ( | ||
<BsFillCheckCircleFill className='fill-current text-green-600' /> | ||
)} | ||
</span> | ||
{answer.headline} | ||
</li> | ||
))} | ||
</ul> | ||
|
||
<div className='rounded bg-gray-200 p-4'> | ||
<p className='text-gray-800'> | ||
{answeredCorrectly | ||
? "You're correct! 🥳" | ||
: 'Too bad, better luck next time ✌️'} | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default QuizAnswers; |
53 changes: 53 additions & 0 deletions
53
src/components/molecules/RandomFacts/__stories__/QuizAnswer.stories.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 { Meta } from '@storybook/react'; | ||
|
||
import QuizAnswers, { | ||
QuizAnswer, | ||
QuizAnswersProps, | ||
} from '@/components/molecules/RandomFacts/QuizAnswers'; | ||
|
||
const meta: Meta<typeof QuizAnswers> = { | ||
title: 'Components/Random Facts/Quiz Answers', | ||
component: QuizAnswers, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
|
||
const answers: QuizAnswer[] = [ | ||
{ | ||
key: 'a', | ||
headline: | ||
'I have been officially excommunicated by the Roman Catholic Church ⛪', | ||
}, | ||
{ | ||
key: 'b', | ||
headline: 'I studied oboe at the music school for more than 12 years 🎶', | ||
}, | ||
{ | ||
key: 'c', | ||
headline: 'I know flags and capitals of all 195 countries in the world 🇰🇲', | ||
}, | ||
{ | ||
key: 'd', | ||
headline: | ||
'I was an extra-actor in a movie once: "Correspondence" by Giuseppe Tornatore 🎬', | ||
}, | ||
]; | ||
|
||
export const CorrectAnswerStory = (args: QuizAnswersProps) => ( | ||
<QuizAnswers {...args} /> | ||
); | ||
CorrectAnswerStory.args = { | ||
answers, | ||
falseOption: 'c', | ||
answeredCorrectly: true, | ||
}; | ||
|
||
export const WrongAnswerStory = (args: QuizAnswersProps) => ( | ||
<QuizAnswers {...args} /> | ||
); | ||
WrongAnswerStory.args = { | ||
answers, | ||
falseOption: 'c', | ||
answeredCorrectly: false, | ||
}; |