Skip to content

feat(CodeEditor): add isHighContrastTheme#12384

Merged
wise-king-sullyman merged 1 commit into
patternfly:mainfrom
logonoff:12383-codeeditor-hc
May 27, 2026
Merged

feat(CodeEditor): add isHighContrastTheme#12384
wise-king-sullyman merged 1 commit into
patternfly:mainfrom
logonoff:12383-codeeditor-hc

Conversation

@logonoff
Copy link
Copy Markdown
Member

@logonoff logonoff commented Apr 27, 2026

What: Closes #12383

Adds a new prop, isHighContrastTheme, which switches the CodeEditor over to the monaco-provided hc-black and hc-light themes (based on the value of isDarkTheme) when enabled.

A custom PatternFly variant of the hc-black and hc-light themes can come in a follow up, depending on the direction design wants to take on this

Dark mode state Contrast state Monaco theme
light theme no high contrast image
light theme high contrast image
dark theme no high contrast image
dark theme high contrast image

Summary by CodeRabbit

  • New Features
    • Added high-contrast theme support to the Code Editor.
    • New theme toggle lets users switch between standard, dark, and high-contrast color schemes.
    • Examples, demo, and configuration modal include controls to enable high-contrast mode.
  • Documentation
    • Example content updated with an icon for the high-contrast control.

Review Change Stack

@patternfly-build
Copy link
Copy Markdown
Collaborator

patternfly-build commented Apr 27, 2026

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 78ed8ec5-6c7f-4a1c-ab92-36a360475d78

📥 Commits

Reviewing files that changed from the base of the PR and between e963ba4 and 554c6d5.

⛔ Files ignored due to path filters (1)
  • packages/react-code-editor/src/components/CodeEditor/__test__/__snapshots__/CodeEditor.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx
  • packages/react-code-editor/src/components/CodeEditor/__test__/CodeEditor.test.tsx
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditor.md
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorBasic.tsx
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorConfigurationModal.tsx
  • packages/react-integration/demo-app-ts/src/components/demos/CodeEditorDemo/CodeEditorDemo.tsx
✅ Files skipped from review due to trivial changes (1)
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditor.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorConfigurationModal.tsx
  • packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx

Walkthrough

Adds an optional isHighContrastTheme prop to CodeEditor (default false), computes a memoized Monaco theme (hc-light/hc-black when enabled, otherwise existing PF themes), and wires the prop through examples, configuration modal, demo app, docs, and tests.

Changes

High contrast theme feature

Layer / File(s) Summary
CodeEditor theme wiring
packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx
Import useMemo; add isHighContrastTheme?: boolean to CodeEditorProps and default prop; compute memoized theme selecting hc-black/hc-light when high-contrast is enabled and previously used pf-v6-theme-dark/pf-v6-theme-light otherwise; pass theme into Monaco Editor.
Unit tests
packages/react-code-editor/src/components/CodeEditor/__test__/CodeEditor.test.tsx
Update @monaco-editor/react mock to expose data-theme and add tests asserting the rendered data-theme for default, dark, high-contrast, and dark+high-contrast scenarios.
Examples & Configuration modal
packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorBasic.tsx, packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorConfigurationModal.tsx, packages/react-code-editor/src/components/CodeEditor/examples/CodeEditor.md
Add isHighContrastTheme state and toggle handlers, add Checkbox/Switch controls wired to that state, forward prop to CodeEditor, and add AdjustIcon import used by the new control.
Demo app integration
packages/react-integration/demo-app-ts/src/components/demos/CodeEditorDemo/CodeEditorDemo.tsx
Add isHighContrastTheme to demo state, constructor default, toggleHighContrastTheme handler, Checkbox UI, and forward isHighContrastTheme prop into CodeEditor.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • lboehling
  • mcoker
  • thatblindgeye
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(CodeEditor): add isHighContrastTheme' directly and clearly summarizes the main change: adding a new prop to enable high-contrast theming.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #12383: adds isHighContrastTheme prop, switches Monaco theme to hc-light/hc-black when enabled, preserves isDarkTheme behavior, and implements the correct 2×2 theme mapping across all components and tests.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the isHighContrastTheme feature across the CodeEditor component, examples, tests, and demo app. No unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy Markdown

@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.

🧹 Nitpick comments (2)
packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx (2)

160-161: Document the interaction with isDarkTheme in the JSDoc.

The behavior depends on isDarkTheme (selecting hc-black vs hc-light), but the doc comment doesn't surface that. Consumers reading IDE hints will likely miss the dependency.

📝 Proposed JSDoc clarification
-  /** Flag indicating the editor is styled using monaco's high contrast themes. */
+  /** Flag indicating the editor uses Monaco's built-in high-contrast themes. When enabled,
+   * `isDarkTheme` selects between `hc-black` (dark) and `hc-light` (light), overriding the
+   * default PatternFly themes. */
   isHighContrastTheme?: boolean;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx` around
lines 160 - 161, Update the JSDoc for the isHighContrastTheme prop to explicitly
state it depends on isDarkTheme: document that when isHighContrastTheme is true
the component will select Monaco's "hc-black" theme if isDarkTheme is true and
"hc-light" if isDarkTheme is false (and that isDarkTheme takes precedence in
choosing the specific high-contrast variant); reference the isHighContrastTheme
and isDarkTheme symbols so consumers can see the interaction in IDE hints.

468-473: useMemo is unnecessary for this computation.

The branches return string literals from two boolean inputs — recomputing per render is effectively free, and the memoized value is consumed as a Monaco prop string, so referential stability buys nothing. A plain ternary keeps the code simpler.

♻️ Proposed simplification
-  const theme = useMemo(() => {
-    if (isHighContrastTheme) {
-      return isDarkTheme ? 'hc-black' : 'hc-light';
-    }
-    return isDarkTheme ? 'pf-v6-theme-dark' : 'pf-v6-theme-light';
-  }, [isHighContrastTheme, isDarkTheme]);
+  const theme = isHighContrastTheme
+    ? (isDarkTheme ? 'hc-black' : 'hc-light')
+    : (isDarkTheme ? 'pf-v6-theme-dark' : 'pf-v6-theme-light');

If you keep useMemo, useMemo can be removed from the imports on line 1 if no other usage remains.

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

In `@packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx` around
lines 468 - 473, The computed theme value using useMemo can be simplified:
replace the useMemo-based assignment to the theme constant inside CodeEditor.tsx
(which currently references isHighContrastTheme and isDarkTheme) with a direct
ternary expression that returns the same string literals, and remove useMemo
from the imports if no other usages remain.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx`:
- Around line 160-161: Update the JSDoc for the isHighContrastTheme prop to
explicitly state it depends on isDarkTheme: document that when
isHighContrastTheme is true the component will select Monaco's "hc-black" theme
if isDarkTheme is true and "hc-light" if isDarkTheme is false (and that
isDarkTheme takes precedence in choosing the specific high-contrast variant);
reference the isHighContrastTheme and isDarkTheme symbols so consumers can see
the interaction in IDE hints.
- Around line 468-473: The computed theme value using useMemo can be simplified:
replace the useMemo-based assignment to the theme constant inside CodeEditor.tsx
(which currently references isHighContrastTheme and isDarkTheme) with a direct
ternary expression that returns the same string literals, and remove useMemo
from the imports if no other usages remain.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ba3d96d-1801-4009-8968-8da952588ef4

📥 Commits

Reviewing files that changed from the base of the PR and between 3392662 and 222a78d.

📒 Files selected for processing (4)
  • packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditor.md
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorBasic.tsx
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorConfigurationModal.tsx

@logonoff logonoff force-pushed the 12383-codeeditor-hc branch from 222a78d to e963ba4 Compare April 27, 2026 20:45
Copy link
Copy Markdown

@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: 1

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

Inline comments:
In `@packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx`:
- Around line 468-473: The computed theme in CodeEditor is getting overridden by
caller-supplied editorProps.theme because editorProps is spread after theme; to
fix, ensure the component's computed theme cannot be overridden by moving the
spread before theme or by merging theme into editorProps (e.g., create
mergedEditorProps = { ...editorProps, theme } and pass mergedEditorProps) so the
local variable theme (from useMemo) always wins; update usages around the
CodeEditor render where theme and editorProps are applied (also apply same
change at the other occurrence noted near lines 592-593).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f4186b34-70f2-4d20-a806-b72a95095b1f

📥 Commits

Reviewing files that changed from the base of the PR and between 222a78d and e963ba4.

📒 Files selected for processing (4)
  • packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditor.md
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorBasic.tsx
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorConfigurationModal.tsx
✅ Files skipped from review due to trivial changes (1)
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditor.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorConfigurationModal.tsx
  • packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorBasic.tsx

Comment thread packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx
Adds a new prop, `isHighContrastTheme`, which switches the CodeEditor over to the monaco-provided `hc-black` and `hc-light` themes (based on the value of `isDarkTheme`) when enabled.

A custom PatternFly variant of the hc-black and hc-light themes can come in a follow up, depending on the direction design wants to take on this
@logonoff logonoff force-pushed the 12383-codeeditor-hc branch from e963ba4 to 554c6d5 Compare May 27, 2026 16:30
Copy link
Copy Markdown
Collaborator

@wise-king-sullyman wise-king-sullyman left a comment

Choose a reason for hiding this comment

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

🥳

@wise-king-sullyman wise-king-sullyman merged commit bee95e6 into patternfly:main May 27, 2026
14 checks passed
@patternfly-build
Copy link
Copy Markdown
Collaborator

Your changes have been released in:

  • @patternfly/react-code-editor@6.6.0-prerelease.2
  • @patternfly/react-docs@7.6.0-prerelease.2
  • @patternfly/react-integration@6.5.0-prerelease.19
  • demo-app-ts@6.5.0-prerelease.111

Thanks for your contribution! 🎉

@logonoff logonoff deleted the 12383-codeeditor-hc branch May 27, 2026 18:19
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.

CodeEditor - High contrast support

4 participants