Skip to content

Add optional Theme Preview generation#13

Merged
rozd merged 5 commits intomainfrom
claude/generate-theme-preview-file
Feb 24, 2026
Merged

Add optional Theme Preview generation#13
rozd merged 5 commits intomainfrom
claude/generate-theme-preview-file

Conversation

@Claude
Copy link
Contributor

@Claude Claude AI commented Feb 23, 2026

Adds opt-in generation of a Theme+Preview.swift file containing a SwiftUI view that renders all theme tokens as a visual palette.

Changes

  • JSON Schema: Added shouldGeneratePreview boolean flag to config section (defaults to false)
  • ThemeFile.GenerationConfig: Added shouldGeneratePreview property with convenience accessor on ThemeFile
  • ThemePreviewGenerator: New generator producing preview file with:
    • Color swatches in adaptive grid
    • Gradient strips with linear gradient visualization
    • Shadow showcase cards with proper shadow enum handling
    • Private helper components (ColorSwatch, GradientStrip, ShadowCard, ShadowModifier)
  • ThemeFileGenerator: Conditionally includes preview file when flag is enabled
  • Test coverage: 21 unit tests for generator, 4 integration tests for flag behavior
  • Documentation: Updated README with usage example and feature description

Usage

Enable in theme.json:

{
  "styles": {
    "colors": ["surface", "primary"],
    "gradients": ["hero"]
  },
  "config": {
    "outputPath": ".",
    "shouldGeneratePreview": true
  }
}

Generated preview resolves tokens through @Environment(\.theme) and @Environment(\.self), adapting to color scheme and environment automatically:

public struct ThemePreview: View {
    @Environment(\.theme) var theme
    @Environment(\.self) var environment
    
    public var body: some View {
        ScrollView {
            VStack(alignment: .leading, spacing: 24) {
                // Color swatches, gradient strips, shadow cards
            }
        }
    }
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Optionally generate Theme Preview</issue_title>
<issue_description>Generate a Theme+Preview.swift file containing a SwiftUI view that renders all tokens as a visual palette, something like:

public struct ThemePreview: View {
      @Environment(\.theme) var theme

      public var body: some View {
          ScrollView {
              // Color swatches grid
              // Gradient strips
              // Mesh Gradient rects
              // Shadow showcase cards
          }
      }
  }

  #Preview { ThemePreview() }

Could be opt-in via shouldGeneratePreview config flag.</issue_description>

Comments on the Issue (you are @claude[agent] in this section)

@rozd @claude work on it

Claude AI and others added 3 commits February 23, 2026 15:41
Co-authored-by: rozd <158493+rozd@users.noreply.github.com>
Co-authored-by: rozd <158493+rozd@users.noreply.github.com>
Co-authored-by: rozd <158493+rozd@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Add option to generate Theme Preview Swift file Add optional Theme Preview generation Feb 23, 2026
@Claude Claude AI requested a review from rozd February 23, 2026 15:43
Refactor ThemePreviewGenerator to use ShapeStyle generics instead of
resolved environment values, making preview components simpler and
removing @Environment dependencies. Update configurator to render
boolean config fields as polished toggle switches with descriptions,
and filter out default values (false, empty string) from JSON output.

Updates Theme Configurator with bool field to toggle Theme Preview
generation.
@rozd rozd marked this pull request as ready for review February 24, 2026 09:05
@rozd rozd merged commit 8634d37 into main Feb 24, 2026
1 check passed
@rozd rozd deleted the claude/generate-theme-preview-file branch February 24, 2026 09:06
@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.46%. Comparing base (f168dc0) to head (0663c99).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #13      +/-   ##
==========================================
+ Coverage   99.35%   99.46%   +0.10%     
==========================================
  Files          30       32       +2     
  Lines        1405     1677     +272     
==========================================
+ Hits         1396     1668     +272     
  Misses          9        9              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Optionally generate Theme Preview

2 participants