/** * Examples Gallery Component * * Displays a gallery of example Arduino projects that users can load and run */ import React, { useState } from 'react'; import { exampleProjects, getCategories, type ExampleProject } from '../../data/examples'; import './ExamplesGallery.css'; interface ExamplesGalleryProps { onLoadExample: (example: ExampleProject) => void; } export const ExamplesGallery: React.FC = ({ onLoadExample }) => { const [selectedCategory, setSelectedCategory] = useState( 'all' ); const [selectedDifficulty, setSelectedDifficulty] = useState< ExampleProject['difficulty'] | 'all' >('all'); const categories = getCategories(); // Filter examples based on selected category and difficulty const filteredExamples = exampleProjects.filter((example) => { const categoryMatch = selectedCategory === 'all' || example.category === selectedCategory; const difficultyMatch = selectedDifficulty === 'all' || example.difficulty === selectedDifficulty; return categoryMatch && difficultyMatch; }); const getCategoryIcon = (category: ExampleProject['category']): React.ReactNode => { const svgProps = { width: 16, height: 16, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round' as const, strokeLinejoin: 'round' as const, style: { display: 'inline-block', verticalAlign: 'middle', flexShrink: 0 }, }; const icons: Record = { basics: ( ), sensors: ( ), displays: ( ), communication: ( ), games: ( ), robotics: ( ), }; return icons[category]; }; const getDifficultyColor = (difficulty: ExampleProject['difficulty']): string => { const colors: Record = { beginner: '#4ade80', intermediate: '#fbbf24', advanced: '#f87171', }; return colors[difficulty]; }; return (

Featured Projects

Explore and run example Arduino projects

{/* Filters */}
{categories.map((category) => ( ))}
{/* Examples Grid */}
{filteredExamples.map((example) => (
onLoadExample(example)} >
{example.thumbnail ? ( {example.title} ) : (
{getCategoryIcon(example.category)}
{example.components.length} component{example.components.length !== 1 ? 's' : ''}
{example.wires.length} wire{example.wires.length !== 1 ? 's' : ''}
)}

{example.title}

{example.description}

{example.difficulty} {getCategoryIcon(example.category)} {example.category} {example.boards && ( Multi-Board )} {!example.boards && example.boardType === 'raspberry-pi-pico' && ( Pico )} {!example.boards && example.boardType === 'esp32' && ( ESP32 )}
))}
{filteredExamples.length === 0 && (

No examples found with the selected filters

)}
); };