Quiz Card
Quiz Card
The QuizCard component is a call-to-action card designed to promote quiz engagement. It displays a title, description, and a button to launch a quiz in a modal. Optionally, it can include a subtle animated attention dot to draw user focus.
Features
- Styled Card: Pre-styled with background, border, and padding
- Animated Attention Dot: Optional floating red dot animation (desktop only)
- Fully Configurable: All quiz parameters can be customized
- Responsive: Works seamlessly on all screen sizes
- Reusable: Perfect for sidebars, call-to-action sections, or standalone placement
Basic Usage
import QuizCard from '@site/src/components/QuizCard';
import quizData from '@site/src/data/quiz-demo.json';
<QuizCard
quizData={quizData}
title="Test Your Knowledge"
description="Take the 5-question quiz to see how well you understand the topic."
questionCount={5}
/>
Live Preview:
Test Your Knowledge
Take the 5-question quiz to see how well you understand the topic.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
quizData | object | required | Quiz data object containing questions |
title | string | 'Test Your Knowledge' | Card heading text |
description | string | - | Optional description text below title |
buttonText | string | 'Start Quiz' | Text displayed on the quiz button |
questionCount | number | 5 | Number of questions to show |
passingScore | number | 60 | Minimum percentage to pass (0-100) |
allowRetry | boolean | true | Whether users can retry incorrect answers |
showDot | boolean | false | Show animated attention dot |
Examples
Basic Quiz Card
<QuizCard
quizData={quizData}
title="Quick Knowledge Check"
description="Test what you've learned in just 3 questions."
questionCount={3}
/>
Quick Knowledge Check
Test what you've learned in just 3 questions.
Quiz Card with Animated Dot
Perfect for drawing attention in sidebars:
<QuizCard
quizData={quizData}
title="Security Awareness Quiz"
description="Can you spot the scams? Take our quiz to find out."
questionCount={5}
passingScore={80}
showDot={true}
/>
Security Awareness Quiz
Can you spot the scams? Take our quiz to find out.
Strict Quiz Mode
No retries allowed, high passing score:
<QuizCard
quizData={quizData}
title="Certification Exam"
description="Pass this exam with 90% to earn your certificate."
questionCount={5}
passingScore={90}
allowRetry={false}
buttonText="Begin Exam"
/>
Certification Exam
Pass this exam with 90% to earn your certificate.
Custom Button Text
<QuizCard
quizData={quizData}
title="Weekly Challenge"
description="Take on this week's challenge quiz!"
buttonText="Accept Challenge"
/>
Weekly Challenge
Take on this week's challenge quiz!
In a Two-Column Layout
Combine with TwoColumnLayout for sidebar placement:
import TwoColumnLayout from '@site/src/components/TwoColumnLayout';
<TwoColumnLayout
sidebar={
<QuizCard
quizData={quizData}
title="Test Your Skills"
description="Quick 5-question quiz on what you just learned."
showDot={true}
/>
}
>
<div>
{/* Main content here */}
</div>
</TwoColumnLayout>
Animated Attention Dot
The showDot prop enables a subtle red dot animation that moves organically around the card and appears and disappears with smooth transitions.
When to Use the Dot
Good use cases:
- Important quizzes that users should notice
- Sidebar call-to-action cards
- Above-the-fold quiz promotions
- Pages where quiz engagement is the primary goal
Avoid using when:
- Multiple quiz cards are on the same page
- The quiz is secondary to main content
- Page already has many animated elements
- Mobile-first experience is critical
Styling
The component uses CSS modules for scoped styling. Default styles include:
- Background:
var(--ifm-background-surface-color) - Border: 2px solid with emphasis color
- Border Radius: 16px
- Padding: 1.5rem
- Title Font Size: 1.25rem
- Description Color: Emphasis color with proper contrast
Custom Styling
Wrap the component in a div to add custom styles:
<div style={{ maxWidth: '400px', margin: '2rem auto' }}>
<QuizCard
quizData={quizData}
title="Centered Quiz Card"
/>
</div>
Accessibility
- Semantic HTML: Uses proper heading hierarchy
- Keyboard Navigation: All interactive elements are keyboard accessible
- Screen Reader Friendly: Clear text labels and structure
- Focus Management: Modal quiz handles focus appropriately
- Motion: Animation can be disabled via CSS
prefers-reduced-motion