-
-
Notifications
You must be signed in to change notification settings - Fork 254
Add darkTheme and lightTheme to init options of BitTheme js api (#10026) #10027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add darkTheme and lightTheme to init options of BitTheme js api (#10026) #10027
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis change refactors theme management in the Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant Theme as BitTheme
App->>Theme: init(options)
Note right of Theme: Determine system, stored, or default theme
Theme-->>Theme: Set _currentTheme = persisted/default (_lightTheme)
Theme-->>Theme: Configure _onThemeChange callback
App->>Theme: get()/set()/toggleDarkLight()
Theme-->>App: Updated theme
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/BlazorUI/Bit.BlazorUI/Utils/Theme/bit-theme.ts (2)
13-35: LGTM! Consider documenting the initialization options.The initialization logic is well-structured and the new options for customizing dark and light themes align with the PR objectives. However, the options parameter could benefit from better type safety and documentation.
Consider defining an interface for the options parameter:
interface BitThemeOptions { /** Use system color scheme preference */ system?: boolean; /** Default theme to use if system preference is not used */ default?: string; /** Persist theme selection in localStorage */ persist?: boolean; /** Custom dark theme value (default: 'dark') */ darkTheme?: string; /** Custom light theme value (default: 'light') */ lightTheme?: string; /** Callback when theme changes */ onChange?: onThemeChangeType; }Then update the method signature:
- public static init(options: any) { + public static init(options: BitThemeOptions) {
46-50: Consider separating the side effect from the getter.The method now has a side effect of updating
_currentThemebefore returning it. This could lead to unexpected behavior if the caller assumes the getter is pure.Consider separating the concerns:
public static get() { return BitTheme._currentTheme; } private static syncWithDOM() { BitTheme._currentTheme = document.documentElement.getAttribute(BitTheme.THEME_ATTRIBUTE) || ''; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/BlazorUI/Bit.BlazorUI/Utils/Theme/bit-theme.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build and test
🔇 Additional comments (5)
src/BlazorUI/Bit.BlazorUI/Utils/Theme/bit-theme.ts (5)
7-11: LGTM! Improved encapsulation with private static variables.The use of private static variables with underscore prefix follows TypeScript conventions and improves encapsulation. The initialization of
_currentThemenow references_lightThemeinstead of a string literal, which reduces duplication and makes the code more maintainable.
37-39: LGTM! Consistent with the refactoring.The update to use the new private static variable is correct.
41-44: LGTM! Consistent with the refactoring.The updates to use the new private static variables are correct and maintain the existing system theme detection logic.
52-60: LGTM! Consistent with the refactoring.The updates to use the new private static variables are correct and maintain the existing functionality.
62-68: LGTM! Consistent with the refactoring.The updates to use the new private static variables are correct and the toggle logic now properly uses the custom theme values.
closes #10026
Summary by CodeRabbit