This document describes the implementation of Issue #56: Carbon Credit Comparison Tool for the FarmCredit Stellar application.
- Users can select up to 3 carbon credit projects for comparison
- Visual feedback when selection limit is reached
- Checkbox-based selection interface
- Out-of-stock projects are disabled and cannot be selected
The comparison table displays the following attributes side-by-side:
- Price per Ton: Formatted in USD currency
- Type: Project category (Reforestation, Renewable Energy, etc.)
- Location: Geographic location of the project
- Co-Benefits: Environmental and social benefits (displayed as badges)
- Verification Status: Certification standard (Gold Standard, Verra, etc.)
- Vintage Year: Year of carbon credit generation
- Available Supply: Quantity available in tons CO₂
- Each project in the comparison table has an "Add to Cart" button
- Clicking redirects to the purchase page with the selected project
- Out-of-stock projects show "Out of Stock" instead of the button
- "Export as PDF" button generates a downloadable comparison document
- PDF includes all selected projects with complete details
- Filename includes generation date for easy organization
- Plain text format for universal compatibility
- Mobile: Single column layout with horizontal scroll for comparison table
- Tablet: 2-column grid for project selection cards
- Desktop: 3-column grid for optimal viewing
- Comparison table scrolls horizontally on smaller screens
- All interactive elements have proper ARIA labels
- Keyboard navigation fully supported
- Screen reader friendly with semantic HTML
- Focus indicators on all interactive elements
- Live regions for dynamic content updates (selection counter)
- Proper heading hierarchy
- No
anytypes used - All props properly typed with interfaces
- Strict null checks enabled
- Type-safe event handlers
lib/
├── types/
│ └── carbon.ts # Extended with comparison fields
├── api/
│ └── mock/
│ └── carbonProjects.ts # Updated with new attributes
└── utils/
└── pdf.ts # PDF export utility
components/
├── atoms/
│ └── Checkbox.tsx # New checkbox component
├── molecules/
│ ├── ComparisonTable.tsx # Comparison table display
│ └── ProjectSelectionCard.tsx # Project selection card
└── organisms/
└── ComparisonTool/
└── ComparisonTool.tsx # Main comparison tool
app/
└── credits/
├── compare/
│ └── page.tsx # Comparison page route
└── purchase/
└── page.tsx # Updated with link to comparison
Added to CarbonProject interface:
type: ProjectType;
location: string;
coBenefits: string[];
verificationStatus: VerificationStatus;Following atomic design pattern:
- Atom:
Checkbox- Reusable checkbox with label support - Molecules:
ComparisonTable,ProjectSelectionCard- Composed UI elements - Organism:
ComparisonTool- Complete feature with state management
- Local state using React hooks (
useState,useCallback) - Selection limit enforced at component level
- Efficient re-renders with proper memoization
- Tailwind CSS utility classes
- Stellar brand colors (stellar-blue, stellar-green, etc.)
- Consistent spacing and typography
- Responsive breakpoints (md, lg)
- Can select up to 3 projects
- Selection counter updates correctly (X / 3 selected)
- Cannot select more than 3 projects
- Can deselect projects
- Out-of-stock projects are disabled
- Checkbox states are visually clear
- Table displays all selected projects
- All attributes are correctly displayed
- Price formatting is correct (USD currency)
- Co-benefits display as badges
- Table is readable on all screen sizes
- Horizontal scroll works on mobile
- "Add to Cart" button works for each project
- Redirects to purchase page with correct project
- Out-of-stock projects show "Out of Stock"
- Button is disabled for out-of-stock projects
- "Export as PDF" button is visible
- PDF downloads successfully
- PDF contains all selected projects
- PDF filename includes date
- PDF content is readable
- Mobile (< 768px): Single column, horizontal scroll
- Tablet (768px - 1024px): 2-column grid
- Desktop (> 1024px): 3-column grid
- No layout breaks at any screen size
- Touch targets are adequate on mobile (min 44x44px)
- Tab navigation works through all elements
- Focus indicators are visible
- Screen reader announces selection changes
- All buttons have descriptive labels
- ARIA attributes are present and correct
- Heading hierarchy is logical (h1 → h2 → h3)
- No TypeScript errors in build
- No
anytypes used - All props are properly typed
Test in the following browsers:
- Chrome/Edge (latest)
- Firefox (latest)
- Safari (latest)
- Mobile Safari (iOS)
- Chrome Mobile (Android)
# Type checking
npx tsc --noEmit
# Linting
npm run lint
# Build
npm run build-
Start the development server:
npm run dev
-
Navigate to the comparison page:
- Direct URL:
http://localhost:3000/credits/compare - Or from purchase page: Click "Compare Projects" button
- Direct URL:
-
Test the workflow:
- Select 2-3 projects by clicking checkboxes
- Verify comparison table appears
- Click "Export as PDF" and verify download
- Click "Add to Cart" on a project
- Verify navigation to purchase page
-
Test responsive design:
- Open DevTools (F12)
- Toggle device toolbar (Ctrl+Shift+M)
- Test various screen sizes
-
Test accessibility:
- Navigate using Tab key only
- Use screen reader (NVDA, JAWS, or VoiceOver)
- Run Lighthouse audit in DevTools
-
PDF Export: Currently generates plain text format. Future enhancement could use a proper PDF library (e.g., jsPDF) for richer formatting.
-
Cart Integration: Currently redirects to purchase page. Full cart functionality would require cart state management.
-
Project Filtering: No filtering by type, location, or price range. Could be added in future iterations.
- Advanced PDF formatting with charts and graphs
- Save comparison for later viewing
- Share comparison via link
- Filter and sort projects before comparison
- Compare more than 3 projects with pagination
- Print-friendly view
✅ Up to 3 projects selectable ✅ Comparison table accurate ✅ Add to Cart works per project ✅ PDF export generates correctly ✅ Responsive layout (scroll on mobile) ✅ Responsive across mobile/tablet/desktop ✅ Accessible (WCAG 2.1 AA) ✅ TypeScript strict — no any types
This feature was implemented with atomic commits:
feat(carbon): extend CarbonProject type with comparison fieldsfeat(carbon): update mock data with comparison attributesfeat(carbon): add PDF export utility for comparisonfeat(ui): add Checkbox atom componentfeat(carbon): add comparison table and project selection card moleculesfeat(carbon): add ComparisonTool organism componentfeat(carbon): add comparison page routefeat(carbon): add navigation link to comparison tool from purchase page
Each commit builds on the previous one and maintains a working state.