Skip to content

implemented custom theme system#687

Open
adeboladee wants to merge 1 commit into
Smartdevs17:mainfrom
adeboladee:custom-theme-system
Open

implemented custom theme system#687
adeboladee wants to merge 1 commit into
Smartdevs17:mainfrom
adeboladee:custom-theme-system

Conversation

@adeboladee

@adeboladee adeboladee commented Jun 26, 2026

Copy link
Copy Markdown

Closes #379

PR Summary: Subscription Custom Theme System

Key Features

  • Theme Configuration: Utilizes ThemeConfig with brand colors (primary, secondary, accent + semantic colors), FontConfig (family, weights, sizes), and LogoConfig (URI, darkURI, dimensions).
  • Real-time Preview: State machine managed in the store following the flow:
    startPreviewupdatePreviewapplyPreview / discardPreview.
  • CSS Variable Generation: Automatically generates --st-{name} variables with auto -rgb variants, --st-ext-{name} for extended colors, font/logo variables, and full :root stylesheet generation.
  • WCAG Accessibility: Automatic contrast auditing on every custom theme creation using getAccessibilityRating(), providing fix suggestions for non-compliant color pairs.
  • Light/Dark Variant Pairs: The ThemeVariantPair system links light and dark themes together under a shared ThemeSharedConfig featuring fonts and logos.
  • Theme Inheritance: inheritTheme() allows the creation of child themes from a parent with partial overrides.
  • Export/Import: Introduces a JSON-based ThemeExportData format (v1.0.0) for sharing themes across merchants.
  • API Persistence: Backend CRUD endpoints with complete merchant isolation and single-active-theme enforcement controlled via a PostgreSQL trigger.
  • Auto-Semantic Colors: Automatically generates missing semantic colors (success, warning, error, info) from the primary brand color with mode-appropriate saturation.

New Files Created

File Purpose
src/theme/customThemeBuilder.ts Utility for hex/RGB conversion, color blending, semantic palette generation, full theme construction from config, light/dark variant pair creation, and theme inheritance.
src/theme/cssVariables.ts CSS variable generation from Theme objects with camelCase → kebab-case conversion, hex → RGB variable extraction, font/logo variables, and full stylesheet generation.
src/theme/accessibility.ts WCAG 2.1 AA/AAA contrast checking (relativeLuminance, contrastRatio, meetsWcagAA/AAA), getAccessibilityRating() for a full theme audit, and suggestContrastFix() for auto-correction.
src/theme/themeService.ts API service layer handles CRUD operations for themes with AsyncStorage persistence and saveThemeVariantPair().

Modified Files

File Changes
src/theme/types.ts Added ExtendedThemeColors, FontConfig, LogoConfig, AccessibilityInfo, AccessibilityIssue, ThemeVariantPair, ThemeSharedConfig, ThemeConfig, ThemeExportData, ThemeInheritance, and ThemePreviewState.
src/theme/themes.ts createBrandTheme now generates extendedColors, sets isCustom, manages createdAt/updatedAt, and exports highContrastTheme.
src/theme/themeStore.ts Complete rewrite to support the preview state machine, updateCustomTheme(), addThemeVariantPair(), removeThemeVariantPair(), exportTheme(), importTheme(), syncToApi(), syncFromApi(), WCAG accessibility rating audits, getThemeById(), and getVariantPair().
src/theme/index.ts Re-exports all new types and utilities.
src/store/index.ts Added useThemeStore export.
backend/subscription/router/index.ts Added createThemeRouter export.
backend/server/createApiServer.ts Mounted theme router at /api/v1/merchant.
backend/subscription/router/themeRouter.ts Express router mounting theme endpoints under /api/v1/merchant.
backend/migrations/004_theme_storage.sql SQL migration creating merchant_themes and theme_variant_pairs tables with JSONB config, alongside triggers for single-active-theme enforcement.

Test Results

83 tests passing across 6 test suites:

  • themes.test.ts (6 tests): Verifies highContrastTheme, extendedColors, isCustom, and timestamps.
  • customThemeBuilder.test.ts (21 tests): Covers color utilities, theme construction, variant pairs, and inheritance.
  • cssVariables.test.ts (12 tests): Covers variable flattening, camelCase → kebab-case conversion, prefix handling, and stylesheet generation.
  • accessibility.test.ts (20 tests): Covers luminance, contrast ratios, WCAG AA/AAA checks, theme ratings, and fix suggestions.
  • themeStore.test.ts (16 tests): Expanded from 9 → 16 tests covering previews, variants, export/import, and inheritance.
  • themeService.test.ts (7 tests): Covers CRUD, export/import, and sync capabilities.

@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

Hey @adeboladee! 👋 It looks like this PR isn't linked to any issue.

If this PR is for one of the issues assigned to you as part of a Wave, please link it to ensure your contribution is tracked properly. You can do this by adding a keyword to the PR description (e.g., Closes #123), or by clicking a button below:

Issue Title
#379 Implement subscription custom theme system Link to this issue

ℹ️ Learn more about linking PRs to issues

@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@adeboladee Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Implement subscription custom theme system

1 participant