Skip to content

Conversation

@JasonWarrenUK
Copy link
Contributor

Summary

Completes the palette system migration by converting all 35 component files to use dynamic CSS custom properties instead of hardcoded colour values. This establishes TypeScript palette files as the single source of truth for all UI colours.

What Changed

Build Infrastructure (Previously Completed)

  • ✅ Build-time CSS generation from TypeScript palette sources
  • ✅ Automatic palette variable generation on dev and build
  • ✅ 75+ CSS variables generated for 5 workflow palettes

Component Conversions (This PR)

Metis Components (4 files) - 30 colour values

  • FileUpload, StructuredInputForm, ModulePreview, ChangelogViewer

Themis Components (7 files) - ~160 colour values

  • CourseConfigForm, ArcStructurePlanner, ModuleStructurePlanner
  • ModuleWithinArcPlanner, CourseStructureReview
  • ModuleGenerationList, CourseOverview

Theia Components (3 files) - 76 colour values

  • CourseStructureUpload, ExportButton, ExportConfigModal

Error Components (2 files) - 18 colour values

  • ErrorBoundary, ErrorAlert

Total Impact

  • 35 component files converted
  • ~350 hardcoded colour values replaced with palette variables
  • 100% of components now use dynamic theming

Key Benefits

  1. Single Source of Truth: All colours defined in src/lib/config/palettes/*.ts
  2. Zero Runtime Overhead: CSS generated at build time
  3. Consistent Theming: Components automatically adapt to workflow palettes
  4. Easy Palette Updates: Change TypeScript, rebuild, done
  5. Type Safety: Palette structure validated by TypeScript

Technical Details

Colour Mapping Patterns

  • Success states → var(--palette-foreground)
  • Error states → var(--palette-primary)
  • Warning states → var(--palette-accent)
  • Body text → var(--palette-foreground-alt)
  • Borders → var(--palette-line)
  • Subtle backgrounds → var(--palette-bg-subtle)

Example Conversion

- background: #28a745;
- color: white;
+ background: var(--palette-foreground);
+ color: white;

- box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.1);
+ box-shadow: 0 0 0 3px color-mix(in srgb, var(--palette-foreground) 10%, transparent);

Testing

  • ✅ Build succeeds with no TypeScript errors
  • ✅ Dev server runs without errors
  • ⏳ Visual testing across all workflows (recommended before merge)
  • ⏳ Palette switching verification

Documentation

Updated docs/dev/ref/palettes/PALETTE-MIGRATION-STATUS.md with:

  • Complete conversion tracking
  • Colour mapping reference
  • Progress statistics

Migration Status

Components: 35/35 ✅ (100%)

See full migration details in: /docs/dev/ref/palettes/PALETTE-MIGRATION-STATUS.md


🤖 Generated with Claude Code

JasonWarrenUK and others added 12 commits October 25, 2025 22:30
Eliminate palette data duplication by consolidating all palette definitions
into src/lib/config/palettes/ as TypeScript modules. This refactor addresses
all requirements from MVP task 2.1.

Key changes:
- Move palette definitions from docs/dev/ref/palettes/ to src/lib/config/palettes/
- Create paletteTransformer.ts to separate data from transformation logic
- Update paletteTypes.ts to use rich semantic structure with named colours
- Refactor paletteLoader.ts to import palettes directly (eliminates 78 lines)
- Remove duplicate JSON files
- Add comprehensive documentation at docs/dev/ref/palettes/README.md

Architecture improvements:
- Single source of truth: src/lib/config/palettes/{workflow}Palette.ts
- Transformation layer: src/lib/utils/palette/paletteTransformer.ts
- Human-readable semantic structure with colour names (e.g., "bronze", "teal")
- Type-safe with PaletteStructure interface
- Clear separation of concerns (data vs. logic)

Tailwind CSS evaluation: Decided against inclusion as custom system is
sufficient for managing 5 workflow palettes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…ource

Establish build-time palette generation as core architecture to enforce single
source of truth principle. All colour values now flow from TypeScript palette
files through automated build script to generated CSS consumed by components.

Key additions:
- Build script (scripts/generatePaletteCss.js) parses TypeScript palette files
- Generates palettes.generated.css with workflow-specific CSS variables
- Auto-runs before build and dev via package.json scripts
- Hub screen now uses generated palette variables instead of hardcoded hex

Architecture:
- Source: src/lib/config/palettes/*.ts (TypeScript palette definitions)
- Build: scripts/generatePaletteCss.js (regex parser + CSS generator)
- Output: src/lib/styles/palettes.generated.css (75+ CSS custom properties)
- Usage: Components reference --{workflow}-{property} variables

Benefits:
- Zero manual synchronisation between TypeScript and CSS
- Change palette once, updates propagate automatically
- Build-time generation means zero runtime overhead
- Type-safe palette definitions with runtime CSS generation

Documentation:
- BUILD-TIME-GENERATION.md explains system architecture and workflow
- Details troubleshooting, migration path, and critical do/don't rules

This establishes the foundation for converting remaining 650+ hardcoded
colours across components to use the palette system.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Complete migration of all Metis workflow components from hardcoded
colour values to CSS palette variables, following build-time generation
architecture.

- Convert FileUpload.svelte success/error states to palette variables
- Convert StructuredInputForm.svelte validation and button colours
- Convert ModulePreview.svelte status indicators to use palette system
- Convert ChangelogViewer.svelte confidence badges and warnings
- Add PALETTE-MIGRATION-STATUS.md to track conversion progress
- Regenerate palettes.generated.css with latest build script

All Metis components now use var(--palette-*) variables ensuring
automatic palette propagation when switching workflows. Replaces
~30 hardcoded hex values with semantic palette references.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Systematically convert CourseConfigForm, ArcStructurePlanner,
ModuleStructurePlanner, and ModuleWithinArcPlanner from hardcoded
colour values to CSS palette variables.

Converted Components:
- CourseConfigForm.svelte: 2 rgba values to color-mix
- ArcStructurePlanner.svelte: 5 hardcoded colours
- ModuleStructurePlanner.svelte: 25 hardcoded colours
- ModuleWithinArcPlanner.svelte: 30 hardcoded colours

Total: ~62 hardcoded values replaced with semantic palette references.
All components now use var(--palette-*) ensuring automatic palette
propagation. Build verified with no errors.

Progress: 26% complete (17/35 files, 167 values converted)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…ables

Completed palette variable conversion for final 3 Themis components:
- ModuleGenerationList: Converted status colours and error styling (9 values)
- CourseOverview: Converted status banners and error states (9 values)
- CourseStructureReview: Already using palette variables

All 7 Themis components now use dynamic palette system. Status colour
function returns CSS variables instead of hardcoded hex values.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Completed palette variable conversion for all 3 Theia components:
- CourseStructureUpload: Converted drag/drop states, warnings, and status
  indicators (30 colour values)
- ExportButton: Converted button variants (6 colour values)
- ExportConfigModal: Converted modal styling, form controls, and buttons
  (40 colour values)

All Theia components now use dynamic palette system for consistent theming.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Completed palette variable conversion for both error components:
- ErrorBoundary: Converted fallback text colour (1 value)
- ErrorAlert: Converted all severity states, buttons, and details panel
  (17 colour values)

ALL 35 component files now use the dynamic palette system! This completes
the component conversion phase of the palette migration.

Next: Visual testing and final integration verification.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
CourseStructureReview was already partially using palette variables, but
had ~80 remaining hardcoded colours. This commit converts all remaining:
- Loading state spinner and text colours
- Error state styling and buttons
- Review header and descriptions
- Arc container styling and hover states
- Module cards, badges, and form controls
- Navigation buttons and shadows

All Themis components now fully use the dynamic palette system.

Also updates palettes.generated.css from build-time generation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@claude
Copy link

claude bot commented Oct 27, 2025

Summary

This PR successfully completes the palette system migration by converting all 35 component files to use dynamic CSS custom properties. The implementation establishes a solid build-time generation architecture with TypeScript palette files as the single source of truth. While the code quality and architecture are excellent, there are opportunities to improve the regex-based parsing approach and add test coverage.

Code Quality & Best Practices

Excellent:

  • Clean separation of concerns: Data → Transformation → Generation → Components
  • Consistent naming conventions: CSS variables follow predictable patterns
  • Type safety: TypeScript interfaces ensure palette structure integrity
  • Documentation: Comprehensive docs explain the system clearly
  • Component consistency: All 35 components use the same palette variable patterns

Suggestions:

  1. scripts/generatePaletteCss.js:37-52 - The regex parsing is fragile. Consider using a proper TypeScript AST parser or JSON export.
  2. Magic string duplication: Workflow names appear in multiple places. Consider a shared constant file.
  3. Error handling: Build script doesn't validate all required palette properties exist before generation.

Potential Issues

Medium Priority:

  1. Regex parsing brittleness (lines 24-63) - Complex regex with multiple fallbacks could silently fail if palette structure changes
  2. color-mix() browser support - Modern syntax, worth documenting minimum browser requirements

Low Priority:

  1. Hardcoded workflow list requires editing build script in 3 places when adding workflows
  2. No validation between TypeScript types and generated CSS variables

Performance

Excellent:

  • Zero runtime overhead (build-time generation)
  • No FOUC (CSS variables available immediately)
  • Efficient selector specificity
  • 170 lines of CSS is well within performance budgets

Security

No Issues Identified:

  • No user input processed
  • No external dependencies added
  • Build script reads local files only
  • TypeScript types prevent malformed data

Test Coverage

Current State: No tests

Recommendations:

  1. Build script validation tests (HIGH PRIORITY)
  2. Palette structure validation tests (HIGH PRIORITY)
  3. Transformer tests (HIGH PRIORITY)
  4. Integration tests for CSS variable application
  5. Visual regression tests for palette consistency

The build script parsing is fragile (regex-based) and needs a safety net.

Recommendation

Approve with suggestions for follow-up.

This is excellent work:

  • ✅ Single source of truth established
  • ✅ All components converted (100%)
  • ✅ Build-time generation working
  • ✅ Comprehensive documentation

Before Merge (if possible):

  1. Add basic validation to build script to ensure all palette properties exist
  2. Test the build script manually with a malformed palette

Follow-up Issues (post-merge):

  1. Add test coverage for palette system
  2. Consider replacing regex parsing with proper TS parsing
  3. Add visual regression tests

Great job on the architecture and execution! The separation of concerns and documentation are particularly well done.

@JasonWarrenUK JasonWarrenUK merged commit abd9276 into main Oct 27, 2025
1 check passed
@JasonWarrenUK JasonWarrenUK deleted the ui/palette-refactor branch October 27, 2025 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants