Mermaid-Based Components for Blog
Blob Changlog - Embedding Mermaid Diagrams
- Use this to iterate on mermaid diagrams
- Explore how to optimize the blog / use the latest features
Execution Plan
Overview
Currently, Mermaid diagrams are embedded directly in MDX files using code fences. While this works, creating reusable React components would provide:
- Consistent styling and theming
- Easier reuse across multiple posts
- Better integration with Docusaurus theme (light/dark mode)
- Component-level documentation in Storybook
- Type safety and validation
Planned Components
1. MermaidDiagram Component
Purpose: Base component for rendering Mermaid diagrams
Features:
- Accepts Mermaid code as prop or children
- Automatic theme detection (light/dark mode)
- Loading states
- Error handling with fallback display
- Responsive sizing
- Configurable Mermaid options
Props:
interface MermaidDiagramProps {
code: string;
title?: string;
config?: MermaidConfig;
height?: string | number;
theme?: 'light' | 'dark' | 'auto';
className?: string;
}
2. MermaidTimeline Component
Purpose: Specialized component for timeline diagrams
Features:
- Pre-configured timeline styling
- Common timeline patterns
- Date formatting helpers
- Color scheme integration
3. MermaidFlowchart Component
Purpose: Specialized component for flowcharts and process diagrams
Features:
- Pre-configured flowchart styling
- Common flowchart patterns
- Node styling helpers
- Link styling customization
4. MermaidSequence Component
Purpose: Specialized component for sequence diagrams
Features:
- Pre-configured sequence diagram styling
- Actor styling helpers
- Message formatting
- Activation box styling
5. MermaidGantt Component
Purpose: Specialized component for Gantt charts
Features:
- Pre-configured Gantt styling
- Date range helpers
- Task grouping
- Milestone markers
Implementation Strategy
Phase 1: Base Component
- Create
src/components/Mermaid/MermaidDiagram.tsx - Integrate with
@docusaurus/theme-mermaid - Add theme detection using
useColorModehook - Implement error boundaries
- Add loading states
- Create Storybook stories
Phase 2: Specialized Components
- Create specialized components (Timeline, Flowchart, Sequence, Gantt)
- Add component-specific styling and helpers
- Create Storybook stories for each
- Document usage patterns
Phase 3: Integration
- Update documentation in
docs/6-techniques/3-blogging-techniques/2-embed-diagrams/ - Create usage examples
- Migrate existing mermaid diagrams to use components (optional)
- Add component to MDXComponents for global availability
Technical Considerations
Dependencies
@docusaurus/theme-mermaid- Already installedmermaid- Already installed@docusaurus/theme-common- ForuseColorModehook
Theme Integration
- Detect current theme using
useColorMode()hook - Pass theme to Mermaid config
- Support manual theme override
- Ensure proper contrast in both themes
Performance
- Lazy load Mermaid library if needed
- Memoize diagram rendering
- Optimize re-renders on theme changes
Error Handling
- Catch Mermaid parsing errors
- Display error message with original code
- Fallback to code block display
- Log errors for debugging
Storybook Integration
Create stories for:
- Base MermaidDiagram component
- Each specialized component
- Theme switching (light/dark)
- Error states
- Loading states
- Various diagram types
Documentation
Update:
docs/6-techniques/3-blogging-techniques/2-embed-diagrams/diagrams-mermaid.mdx- Add component usage examples
- Document props and configuration
- Add migration guide from code fences
Benefits
- Consistency: All diagrams use same styling and theming
- Reusability: Easy to reuse diagrams across posts
- Maintainability: Centralized styling and configuration
- Type Safety: TypeScript props prevent errors
- Documentation: Storybook provides interactive examples
- Theme Support: Automatic light/dark mode support
- Error Handling: Better error messages and fallbacks
Execution Results / Attempts
✅ Initial Work Completed (2025-09-15 to 2025-09-29)
Work Period: September 15, 2025 to September 29, 2025
Commits: 2 commits related to Mermaid diagrams
Key Accomplishments:
- Got Mermaid diagrams working in the blog
- Added comprehensive professional contributions timeline using Mermaid diagrams
Notable Commits:
4402f778(2025-09-15): Got mermaid diagrams to workdc099fc3(2025-09-29): feat: Add comprehensive professional contributions timeline and approach documentation
Status: Initial Mermaid integration is complete. The blog now supports Mermaid diagrams. The plan to create reusable React components wrapping Mermaid diagrams is still planned for future work.