Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Dec 22, 2025

Link issues

fixes #856

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add optional dark mode support and adjust theme handling for the UniverSheet component.

New Features:

  • Expose an IsDarkMode nullable parameter on UniverSheet and pass it through initialization to control dark mode behavior.

Enhancements:

  • Refine UniverSheet theme and dark mode initialization in JavaScript to support a green theme option, default theme fallback, and automatic dark mode based on the current site theme when not explicitly set.

Copilot AI review requested due to automatic review settings December 22, 2025 04:55
@bb-auto bb-auto bot added the enhancement New feature or request label Dec 22, 2025
@bb-auto bb-auto bot added this to the v9.2.0 milestone Dec 22, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 22, 2025

Reviewer's Guide

Adds an optional IsDarkMode parameter to UniverSheet, threads it through the Blazor-to-JS interop layer, and adjusts the Univer initialization logic so theme selection and dark mode are determined consistently, with automatic dark-mode detection when not explicitly set.

Sequence diagram for UniverSheet initialization with IsDarkMode

sequenceDiagram
    participant Blazor_UniverSheet as Blazor_UniverSheet
    participant JS_UniverSheetInterop as UniverSheet_razor_js
    participant Univer_Module as univer_js
    participant Univer_Core as Univer_library

    Blazor_UniverSheet->>JS_UniverSheetInterop: InvokeVoidAsync init(Id, Interop, { theme, lang, plugins, data, darkMode, ribbonType })
    JS_UniverSheetInterop->>JS_UniverSheetInterop: Build univerSheet { el, invoke, plugins, theme, lang, ribbonType, darkMode }
    JS_UniverSheetInterop->>Univer_Module: createUniverSheetAsync(univerSheet)

    Univer_Module->>Univer_Module: Build options { theme: sheet.theme, darkMode: sheet.darkMode, locale, locales, plugins }
    Univer_Module->>Univer_Module: if options.theme == greenTheme then options.theme = UniverDesign.greenTheme else options.theme = UniverDesign.defaultTheme
    Univer_Module->>Univer_Module: if options.darkMode == null then options.darkMode = (getTheme() == dark)

    Univer_Module->>Univer_Core: createUniver(options)
    Univer_Core-->>Univer_Module: { univer, univerAPI }
    Univer_Module-->>JS_UniverSheetInterop: univerSheet initialized
    JS_UniverSheetInterop-->>Blazor_UniverSheet: init completed
Loading

Class diagram for UniverSheet component with IsDarkMode

classDiagram
    class UniverSheet {
        +string Id
        +Dictionary~string,string~ Plugins
        +string Theme
        +bool IsDarkMode
        +string Lang
        +object Data
        +Enum RibbonType
        +Task OnAfterRenderAsync(bool firstRender)
        +Task InvokeInitAsync()
        +Task PushAsync(object data)
    }

    class JSInterop_UniverSheet_razor_js {
        +Task init(string id, object invoke, object options)
    }

    class JS_Univer_Module_univer_js {
        +Task createUniverSheetAsync(object sheet)
    }

    UniverSheet --> JSInterop_UniverSheet_razor_js : uses_init
    JSInterop_UniverSheet_razor_js --> JS_Univer_Module_univer_js : calls_createUniverSheetAsync
Loading

Flow diagram for theme and darkMode resolution in univer.js

flowchart TD
    A[Input sheet.theme and sheet.darkMode] --> B{Is sheet.theme equal to greenTheme?}
    B -- Yes --> C[Set options.theme to UniverDesign.greenTheme]
    B -- No --> D[Set options.theme to UniverDesign.defaultTheme]

    C --> E{Is options.darkMode null?}
    D --> E

    E -- Yes --> F[Call getTheme]
    F --> G{Does getTheme return dark?}
    G -- Yes --> H[Set options.darkMode to true]
    G -- No --> I[Set options.darkMode to false]

    E -- No --> J[Keep options.darkMode as provided]

    H --> K[Call createUniver with resolved options]
    I --> K
    J --> K
Loading

File-Level Changes

Change Details Files
Expose IsDarkMode as a Blazor parameter and pass it through to the JS init call.
  • Add nullable bool IsDarkMode parameter with documentation to the UniverSheet component.
  • Extend the InvokeInitAsync interop call payload to include a DarkMode field sourced from IsDarkMode.
src/components/BootstrapBlazor.UniverSheet/Components/UniverSheet.razor.cs
Propagate darkMode and theme through the JS init wrapper to UniverSheet creation.
  • Update the UniverSheet.razor.js init helper to accept darkMode from options.
  • Include darkMode on the univerSheet object passed to createUniverSheetAsync.
src/components/BootstrapBlazor.UniverSheet/Components/UniverSheet.razor.js
Refine Univer JS initialization to use explicit theme names, map them to UniverDesign, and auto-detect dark mode when unset.
  • Import getTheme helper from utility.js for theme detection.
  • Pass through raw sheet.theme and sheet.darkMode into options instead of immediately resolving to UniverDesign/default values.
  • Map the string theme value (e.g., 'greenTheme') to UniverDesign.greenTheme or defaultTheme before calling createUniver.
  • When darkMode is null, determine dark mode by checking the current UI theme via getTheme().
src/components/BootstrapBlazor.UniverSheet/wwwroot/univer.js

Assessment against linked issues

Issue Objective Addressed Explanation
#856 Expose an IsDarkMode parameter on the UniverSheet component API.
#856 Wire the IsDarkMode parameter through the JS interop so UniverSheet’s underlying Univer options respect the dark mode setting (including a sensible default when not set).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArgoZhang ArgoZhang merged commit f8a72da into master Dec 22, 2025
3 of 4 checks passed
@ArgoZhang ArgoZhang deleted the feat-univer-theme branch December 22, 2025 04:56
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/components/BootstrapBlazor.UniverSheet/wwwroot/univer.js:90-95` </location>
<code_context>
         options.plugins.push(plugin);
     }

+    if (options.theme === 'greenTheme') {
+        options.theme = UniverDesign.greenTheme;
+    }
+    else {
+        options.theme = UniverDesign.defaultTheme;
+    }
+
</code_context>

<issue_to_address>
**suggestion:** Make the theme mapping more flexible instead of hard-coding only `greenTheme` vs default.

This change maps all non-`greenTheme` values (including any future valid themes) to `defaultTheme`. Previously, any `UniverDesign[options.theme]` key was used, with `defaultTheme` only as a fallback. This will block new themes from working. Instead, resolve the theme dynamically, e.g. `options.theme = UniverDesign[options.theme] ?? UniverDesign.defaultTheme;`, and add a special case only if you need a `'greenTheme'` alias.

```suggestion
    options.theme = UniverDesign[options.theme] ?? UniverDesign.defaultTheme;
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +90 to +95
if (options.theme === 'greenTheme') {
options.theme = UniverDesign.greenTheme;
}
else {
options.theme = UniverDesign.defaultTheme;
}
Copy link

Choose a reason for hiding this comment

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

suggestion: Make the theme mapping more flexible instead of hard-coding only greenTheme vs default.

This change maps all non-greenTheme values (including any future valid themes) to defaultTheme. Previously, any UniverDesign[options.theme] key was used, with defaultTheme only as a fallback. This will block new themes from working. Instead, resolve the theme dynamically, e.g. options.theme = UniverDesign[options.theme] ?? UniverDesign.defaultTheme;, and add a special case only if you need a 'greenTheme' alias.

Suggested change
if (options.theme === 'greenTheme') {
options.theme = UniverDesign.greenTheme;
}
else {
options.theme = UniverDesign.defaultTheme;
}
options.theme = UniverDesign[options.theme] ?? UniverDesign.defaultTheme;

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for configuring dark mode in the UniverSheet component. Previously, the dark mode setting was handled internally, but now users can explicitly control it through a new IsDarkMode parameter. When not set, the component automatically detects the theme from the Bootstrap Blazor theme system.

Key Changes:

  • Added IsDarkMode nullable boolean parameter to the UniverSheet component
  • Implemented automatic dark mode detection when the parameter is null
  • Updated theme handling logic to properly resolve theme strings to UniverDesign objects

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
UniverSheet.razor.cs Added IsDarkMode parameter and passed it to JavaScript initialization
UniverSheet.razor.js Added darkMode to destructured options and passed it to sheet creation
univer.js Implemented theme resolution logic and automatic dark mode detection using getTheme()
BootstrapBlazor.UniverSheet.csproj Incremented version from 10.0.3 to 10.0.4

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

public string? Theme { get; set; }

/// <summary>
/// 获得/设置 是否为暗黑模式 默认 null 未设置 自动
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The comment uses '暗黑模式' which should be '深色模式' for consistency with standard Chinese terminology for dark mode.

Suggested change
/// 获得/设置 是否为暗黑模式 默认 null 未设置 自动
/// 获得/设置 是否为深色模式 默认 null 未设置 自动

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(UniverSheet): add IsDarkMode parameter

2 participants