- Published on
Interactive Component Library Documentation
- Authors

- Name
- Sunil Tiwari
- @sunil28071987
Interactive Component Library
This blog features a comprehensive library of reusable interactive components designed to make learning more engaging. All components are:
- ✅ Reusable - Use in any MDX blog post
- ✅ Configurable - Customizable through props
- ✅ Responsive - Work on all screen sizes
- ✅ Dark mode compatible - Adapt to theme automatically
- ✅ Self-contained - No external dependencies needed
Available Components
1. WaveVisualizer
Interactive sound wave visualizer for exploring audio properties.
<WaveVisualizer
title="Sound Wave Properties"
showHarmonics={true}
showPhase={true}
/>
Props:
title(string): Component titleshowHarmonics(boolean): Enable harmonic controlsshowPhase(boolean): Enable phase control
Example:
Example: Explore Wave Properties
Timbre (Harmonics) - Creates unique sound character
Try These:
- • Set frequency to 262 Hz for Middle C
- • Add harmonics to create richer sounds
- • Compare sine vs square waves at same frequency
- • Observe how phase affects wave position
Key Concepts:
- • Higher frequency = higher pitch
- • Larger amplitude = louder sound
- • Harmonics create timbre (tone quality)
- • Phase affects how waves combine
2. SamplingVisualizer
Demonstrates digital audio concepts: waveforms, sample rate, and bit depth.
<SamplingVisualizer
title="Digital Audio Concepts"
/>
Props:
title(string): Component title
Example:
Example: Sample Rate & Bit Depth
1. Waveform — the raw shape of sound
Air pressure changing over time. When you speak, your vocal cords push air molecules in waves. A microphone measures that pressure as a continuous signal between -1 and +1.
2. Sample Rate — how often we measure the wave
How many "snapshots" of the waveform we take per second. 24 kHz = 24,000 samples/sec means one snapshot every 0.000042 seconds. More samples = better reconstruction.
Low rate (few snapshots) → jagged reconstruction
High rate (dense samples, 24kHz = 24,000/sec) → smooth reconstruction
24kHz is standard for TTS — humans hear up to ~20kHz, so 24k comfortably covers speech
3. Bit Depth — how precisely we measure each sample
The precision of each measurement. 8 bits = 256 levels (coarse, noisy). 16 bits = 65,536 levels (CD quality). More bits = less quantization noise.
2-bit (4 levels)
8-bit (256 levels)
16-bit (65,536 levels)
| Format | Sample Rate | Bit Depth | File Size/min |
|---|---|---|---|
| Phone call | 8 kHz | 8-bit | ~0.5 MB |
| KittenTTS / TTS | 24 kHz | 16-bit | ~2.8 MB |
| CD audio | 44.1 kHz | 16-bit | ~10 MB |
Waveform
Air pressure changing over time. The blue line shows the continuous analog signal that exists in nature.
Sample Rate
How often we measure the waveform. Red dots show where we take snapshots. Higher rate = better quality.
Bit Depth
Precision of each measurement. Green line shows quantized values. More bits = less noise.
File Size: 46.9 KB/second for mono audio (2814.0 KB/minute)
Formula: (Sample Rate × Bit Depth) ÷ 8 ÷ 1024 = KB/sec
Nyquist Theorem
Maximum frequency that can be accurately captured: 12,000 Hz (half the sample rate). This is why 24 kHz is perfect for speech (captures up to 12 kHz).
3. CodePlayground
Live JavaScript code editor and executor.
<CodePlayground
title="JavaScript Example"
initialCode={`console.log('Hello World');`}
language="javascript"
/>
Props:
title(string): Component titleinitialCode(string): Starting codelanguage(string): Programming language (currently JavaScript)
Example:
4. PythonSimulator
Simplified Python code simulator for demonstrations.
<PythonSimulator
title="Python Demo"
initialCode={`print("Hello Python")`}
/>
Props:
title(string): Component titleinitialCode(string): Starting Python code
Example:
# Python simulator examplex = 10y = 20result = x + y
print(f"x = {x}")print(f"y = {y}")print(f"x + y = {result}")
# Arrays (simplified numpy)data = np.zeros(5)print(f"Array shape: {data.shape}")
5. InteractiveChart
Dynamic data visualization with line and bar charts.
<InteractiveChart
title="Data Visualization"
type="line"
data={[
{ name: 'Jan', value: 100, value2: 80 },
{ name: 'Feb', value: 120, value2: 90 }
]}
color="#3B82F6"
color2="#10B981"
/>
Props:
title(string): Chart titletype('line' | 'bar'): Chart typedata(array): Data points withname,value, optionalvalue2color(string): Primary series colorcolor2(string): Secondary series color
Example:
Example: Performance Metrics
6. Quiz
Interactive quiz component with scoring and feedback.
<Quiz
title="Knowledge Check"
questions={[
{
question: "What is 2 + 2?",
options: ["3", "4", "5", "6"],
correct: 1,
explanation: "2 + 2 equals 4"
}
]}
/>
Props:
title(string): Quiz titlequestions(array): Array of question objectsquestion(string): Question textoptions(string[]): Answer choicescorrect(number): Index of correct answerexplanation(string): Optional explanation
Example:
Example: Quick Quiz
Question 1 of 2Which component is used for audio visualization?
7. Tabs
Organize content in tabbed interface.
<Tabs
tabs={[
{
label: "Tab 1",
content: <div>Content 1</div>
},
{
label: "Tab 2",
content: <div>Content 2</div>
}
]}
defaultTab={0}
/>
Props:
tabs(array): Tab objects withlabelandcontentdefaultTab(number): Initially active tab index
Example:
Component Overview
This library contains 8 interactive components designed for educational content.
8. AudioPlayer
Custom audio player with enhanced controls.
<AudioPlayer
src="https://example.com/audio.mp3"
title="Audio Title"
/>
Props:
src(string): Audio file URLtitle(string): Player title
Example:
Example: Sample Audio Track
Usage Guidelines
When to Use Each Component
| Component | Best For | Example Use Cases |
|---|---|---|
| WaveVisualizer | Audio education | Sound properties, frequency, harmonics |
| SamplingVisualizer | Digital audio | Sample rate, bit depth, quantization |
| CodePlayground | JavaScript demos | Algorithms, web development |
| PythonSimulator | Python concepts | Data processing, basic scripts |
| InteractiveChart | Data visualization | Performance metrics, trends |
| Quiz | Knowledge testing | Comprehension checks, practice |
| Tabs | Content organization | Multiple examples, comparisons |
| AudioPlayer | Audio content | Podcasts, music, sound samples |
Integration in MDX Files
- Import Not Required: Components are automatically available in MDX files
- Use JSX Syntax: Write components as JSX elements
- Pass Props: Configure components through props
- Nest Content: Some components accept JSX content as props
Example MDX File Structure
---
title: 'Your Blog Post'
date: '2024-03-22'
tags: ['topic']
---
## Introduction
Your content here...
## Interactive Demo
<WaveVisualizer title="Sound Demo" />
## Code Example
<CodePlayground
title="Try It"
initialCode={`console.log('Edit me!');`}
/>
## Conclusion
Your summary...
Advanced Examples
Combining Multiple Components
You can create rich learning experiences by combining components:
Audio Properties
Timbre (Harmonics) - Creates unique sound character
Try These:
- • Set frequency to 262 Hz for Middle C
- • Add harmonics to create richer sounds
- • Compare sine vs square waves at same frequency
- • Observe how phase affects wave position
Key Concepts:
- • Higher frequency = higher pitch
- • Larger amplitude = louder sound
- • Harmonics create timbre (tone quality)
- • Phase affects how waves combine
Component Development
Adding New Components
- Create component in
/components/MDXComponents/ - Export from
/components/MDXComponents.tsx - Component is automatically available in all MDX files
Component Requirements
- Must be client-side components (
'use client') - Should handle loading and error states
- Must be responsive and theme-aware
- Should provide meaningful defaults
Tips & Best Practices
- Performance: Components lazy-load for better performance
- Accessibility: All components support keyboard navigation
- Mobile: Test components on mobile devices
- Content: Keep examples concise and relevant
- Documentation: Always provide clear explanations
Troubleshooting
Common Issues
- Component not rendering: Check prop syntax
- Dark mode issues: Ensure using theme-aware classes
- Performance: Large datasets may slow charts
- Audio playback: Check CORS headers for audio files
Future Components
Planned additions to the library:
- 3D Visualizer: Three.js-based 3D graphics
- Network Graph: Interactive network diagrams
- Timeline: Event timeline component
- Code Differ: Side-by-side code comparison
- Math Renderer: LaTeX equation rendering
Conclusion
This component library enables creation of highly interactive and engaging educational content. Each component is designed to enhance learning through hands-on interaction and immediate feedback.
Use these components to transform static blog posts into dynamic learning experiences!
