Skip to content

Commit

Permalink
feat: add QuizAnswer sample stories
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc-resourcify committed Jul 27, 2023
1 parent 0fdd567 commit b025bfe
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/components/molecules/RandomFacts/QuizAnswers.tsx
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;
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,
};

0 comments on commit b025bfe

Please sign in to comment.