Skip to content

Refactor theme settings and interfaces for improved structure and cla…#4551

Closed
teboho wants to merge 2 commits intoshesha-io:mainfrom
teboho:teboho/e/themecore
Closed

Refactor theme settings and interfaces for improved structure and cla…#4551
teboho wants to merge 2 commits intoshesha-io:mainfrom
teboho:teboho/e/themecore

Conversation

@teboho
Copy link
Contributor

@teboho teboho commented Mar 3, 2026

…rity

This will support Sizwe's incoming theme changes

#3836

Summary by CodeRabbit

  • New Features

    • Expanded theming system with richer, strongly-typed configuration for UI styling
    • Granular controls for layout, input, standard, and inline components
    • New border, radius, shadow, spacing and component-background options
    • Customizable application color palette (primary, error, warning, success, info, processing)
  • Refactor

    • Theme configuration and exports reorganized for a flatter, more consistent public API

@teboho teboho requested a review from czwe-01 March 3, 2026 11:48
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 3, 2026

Walkthrough

Backend ThemeSettings was flattened and expanded with many new strongly-typed theme subtypes; the React theme provider/context gained matching TypeScript interfaces, extended initial state defaults, and re-exported the new types from the contexts module.

Changes

Cohort / File(s) Summary
Backend Theme Configuration
shesha-core/src/Shesha.Framework/Configuration/ThemeSettings.cs
Replaced nested Application wrapper with a flatter ThemeSettings.Default initialization; added many new public nested types (BorderStyle, RadiusConfig, BorderTheme, BorderConfig, ShadowTheme, LayoutComponentsSettings, InputComponentsSettings, StandardComponentsSettings, InlineComponentsSettings) and new properties (ComponentBackground, LayoutComponents, InputComponents, StandardComponents, InlineComponents). Application property now uses ApplicationSettings directly.
React Theme Interfaces & State
shesha-reactjs/src/providers/theme/contexts.ts
Exported ITextTheme; added/exported new interfaces (IApplicationTheme, IMarginPaddingTheme, IBorderStyle, IRadiusConfig, IBorderTheme, IShadowTheme, ILayoutComponents, IInputComponents, IStandardComponents, IInlineComponents); extended IConfigurableTheme with new properties and populated THEME_CONTEXT_INITIAL_STATE with defaults for componentBackground, marginPadding, layoutComponents, inputComponents, standardComponents, inlineComponents.
Theme Provider Exports
shesha-reactjs/src/providers/theme/index.tsx
Re-exported the expanded set of theme types from ./contexts instead of direct local type exports; continued exporting ThemeProvider, useTheme, useThemeActions, and useThemeState.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • AlexStepantsov
  • James-Baloyi
  • IvanIlyichev

Poem

🐰
I nibble pixels, stitch a theme so bright,
Borders, shadows, padding—everything just right.
From C# burrow to React meadow I hop,
Flatter fields of styles where colors never stop.
Hooray for themes—now let the UI pop! 🎨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changeset: refactoring theme settings and interfaces across multiple files to improve structure and clarity.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@shesha-core/src/Shesha.Framework/Configuration/ThemeSettings.cs`:
- Line 41: Extract the repeated JSON literal used for StylingBox into a single
constant (e.g., private static readonly string DefaultStylingBox =
"{\"marginBottom\":\"0\"}") inside the ThemeSettings class and replace every
inline occurrence of the literal (all StylingBox initializers) with that
constant; update object initializers or defaults that currently set StylingBox =
"{\"marginBottom\":\"0\"}" to StylingBox = DefaultStylingBox (or use a public
const if the value should be exposed).

In `@shesha-reactjs/src/providers/theme/contexts.ts`:
- Line 80: The union type declared as application?: IApplicationTheme | Theme on
the provider context creates an untagged ambiguity (IApplicationTheme lacks
processingColor while Ant Design Theme includes it); update the types so
consumers don’t need defensive checks: either add a discriminator property
(e.g., kind: 'application' | 'antd-theme') to the union members and set it when
you create the context value, or extend/normalize IApplicationTheme to include
processingColor and convert the Ant Design Theme to that normalized shape at the
provider boundary (contexts.ts) so components like
src/components/colorPicker/index.tsx can safely read
theme.application.processingColor without extra optional chaining.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 41c4fed and d5ef2a7.

📒 Files selected for processing (3)
  • shesha-core/src/Shesha.Framework/Configuration/ThemeSettings.cs
  • shesha-reactjs/src/providers/theme/contexts.ts
  • shesha-reactjs/src/providers/theme/index.tsx

},
LayoutComponents = new LayoutComponentsSettings()
{
StylingBox = "{\"marginBottom\":\"0\"}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Deduplicate repeated StylingBox default literal.

The same JSON literal appears multiple times. Extracting a constant avoids drift and typo regressions.

♻️ Suggested refactor
+        private const string ZeroMarginBottomStylingBox = "{\"marginBottom\":\"0\"}";
+
         public static ThemeSettings Default
         {
             get
             {
                 return defaultInstance ??= new ThemeSettings()
                 {
                     LayoutComponents = new LayoutComponentsSettings()
                     {
-                        StylingBox = "{\"marginBottom\":\"0\"}",
+                        StylingBox = ZeroMarginBottomStylingBox,
                         GridGapHorizontal = 8,
                         GridGapVertical = 8,
                         Border = new BorderTheme()
                         {
                             Border = new BorderConfig()
@@
                     InputComponents = new InputComponentsSettings()
                     {
                         LabelSpan = 8,
                         ContentSpan = 16,
                         LabelColon = true,
-                        StylingBox = "{\"marginBottom\":\"0\"}"
+                        StylingBox = ZeroMarginBottomStylingBox
                     },
                     StandardComponents = new StandardComponentsSettings()
                     {
-                        StylingBox = "{\"marginBottom\":\"0\"}"
+                        StylingBox = ZeroMarginBottomStylingBox
                     },
                     InlineComponents = new InlineComponentsSettings()
                     {
-                        StylingBox = "{\"marginBottom\":\"0\"}"
+                        StylingBox = ZeroMarginBottomStylingBox
                     }
                 };
             }
         }

Also applies to: 75-75, 79-79, 83-83

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shesha-core/src/Shesha.Framework/Configuration/ThemeSettings.cs` at line 41,
Extract the repeated JSON literal used for StylingBox into a single constant
(e.g., private static readonly string DefaultStylingBox =
"{\"marginBottom\":\"0\"}") inside the ThemeSettings class and replace every
inline occurrence of the literal (all StylingBox initializers) with that
constant; update object initializers or defaults that currently set StylingBox =
"{\"marginBottom\":\"0\"}" to StylingBox = DefaultStylingBox (or use a public
const if the value should be exposed).

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
shesha-reactjs/src/providers/theme/contexts.ts (1)

81-81: 🛠️ Refactor suggestion | 🟠 Major

Remove the untagged application union (or make it discriminated).

Line 81 still defines application?: IApplicationTheme | Theme as an untagged union. Even with processingColor now present, this keeps narrowing ambiguous for consumers. Prefer a single normalized type at this boundary, or a discriminator if both shapes must be retained.

♻️ Proposed fix
 export interface IConfigurableTheme {
-  application?: IApplicationTheme | Theme;
+  application?: IApplicationTheme;
   sidebar?: 'dark' | 'light';
   sidebarBackground?: string;
   layoutBackground?: string;
In Ant Design 5.27.6, what is the recommended public type for app theme colors, and is importing `Theme` from `antd/lib/config-provider/context` considered stable API usage?

As per coding guidelines: "Avoid monolithic types; use discriminated unions with a discriminator property instead."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shesha-reactjs/src/providers/theme/contexts.ts` at line 81, The field
application currently uses an untagged union (application?: IApplicationTheme |
Theme) which is ambiguous for consumers; change it to a single normalized type
(prefer IApplicationTheme) at this boundary or, if you must keep both shapes,
convert to a discriminated union by adding a discriminator property (e.g., kind:
"custom" | "antd") to the variants and update all uses to narrow on that
discriminator; ensure the new normalized type includes processingColor and
remove direct reliance on importing Theme from antd context so consumers use the
stable IApplicationTheme shape (or the new discriminated union) instead.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@shesha-reactjs/src/providers/theme/contexts.ts`:
- Line 81: The field application currently uses an untagged union (application?:
IApplicationTheme | Theme) which is ambiguous for consumers; change it to a
single normalized type (prefer IApplicationTheme) at this boundary or, if you
must keep both shapes, convert to a discriminated union by adding a
discriminator property (e.g., kind: "custom" | "antd") to the variants and
update all uses to narrow on that discriminator; ensure the new normalized type
includes processingColor and remove direct reliance on importing Theme from antd
context so consumers use the stable IApplicationTheme shape (or the new
discriminated union) instead.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d5ef2a7 and aa9df6e.

📒 Files selected for processing (1)
  • shesha-reactjs/src/providers/theme/contexts.ts

@teboho
Copy link
Contributor Author

teboho commented Mar 5, 2026

Defunct, will push new with Sizwe's changes

@teboho teboho closed this Mar 5, 2026
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.

1 participant