Context Zero Logo
Published on

Interactive Component Library Documentation

Authors

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 title
  • showHarmonics (boolean): Enable harmonic controls
  • showPhase (boolean): Enable phase control

Example:

Example: Explore Wave Properties

20 Hz (Low)440 Hz (A4)2000 Hz (High)
SilentNormalLoud
180°360°

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.

peak (loud)trough (loud)amp+10-1timeAir pressure over timeSpeakers push/pull airto recreate this shape

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)

coarse / noisy

8-bit (256 levels)

decent quality

16-bit (65,536 levels)

CD quality
FormatSample RateBit DepthFile Size/min
Phone call8 kHz8-bit~0.5 MB
KittenTTS / TTS24 kHz16-bit~2.8 MB
CD audio44.1 kHz16-bit~10 MB
Continuous waveform
Sample points
Quantized signal
Quantization error
8 kHz24 kHz44.1 kHz96 kHz
4-bit8-bit16-bit24-bit

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 title
  • initialCode (string): Starting code
  • language (string): Programming language (currently JavaScript)

Example:

Example: Array Methods
Output will appear here...

4. PythonSimulator

Simplified Python code simulator for demonstrations.

<PythonSimulator
  title="Python Demo"
  initialCode={`print("Hello Python")`}
/>

Props:

  • title (string): Component title
  • initialCode (string): Starting Python code

Example:

Example: Python Basics
# Python simulator example
x = 10
y = 20
result = 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}")
Output will appear here...

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 title
  • type ('line' | 'bar'): Chart type
  • data (array): Data points with name, value, optional value2
  • color (string): Primary series color
  • color2 (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 title
  • questions (array): Array of question objects
    • question (string): Question text
    • options (string[]): Answer choices
    • correct (number): Index of correct answer
    • explanation (string): Optional explanation

Example:

Example: Quick Quiz

Question 1 of 2

Which 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 with label and content
  • defaultTab (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 URL
  • title (string): Player title

Example:

Example: Sample Audio Track

0:000:00

Usage Guidelines

When to Use Each Component

ComponentBest ForExample Use Cases
WaveVisualizerAudio educationSound properties, frequency, harmonics
SamplingVisualizerDigital audioSample rate, bit depth, quantization
CodePlaygroundJavaScript demosAlgorithms, web development
PythonSimulatorPython conceptsData processing, basic scripts
InteractiveChartData visualizationPerformance metrics, trends
QuizKnowledge testingComprehension checks, practice
TabsContent organizationMultiple examples, comparisons
AudioPlayerAudio contentPodcasts, music, sound samples

Integration in MDX Files

  1. Import Not Required: Components are automatically available in MDX files
  2. Use JSX Syntax: Write components as JSX elements
  3. Pass Props: Configure components through props
  4. 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

20 Hz (Low)440 Hz (A4)2000 Hz (High)
SilentNormalLoud

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

  1. Create component in /components/MDXComponents/
  2. Export from /components/MDXComponents.tsx
  3. 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

  1. Performance: Components lazy-load for better performance
  2. Accessibility: All components support keyboard navigation
  3. Mobile: Test components on mobile devices
  4. Content: Keep examples concise and relevant
  5. 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!