feat: enhance theme detection with auto mode and multiple strategies #235
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
This pull request introduces a major refactor and enhancement to the theme detection and switching logic across the JavaScript, Browser, and React packages. It unifies and extends theme detection strategies, replacing the old
'class'mode with a more flexible'auto'mode that supports detection via data attributes, CSS classes, and system preferences, with configurable strategy and priority. The ReactThemeProviderand related APIs are updated to leverage these new capabilities, providing more robust and customizable theme handling.Theme detection and configuration enhancements:
ThemeDetectionStrategytype and expanded theThemeDetectioninterface to support detection via data attributes, CSS classes, and system preferences, with configurable strategy and priority ('auto'mode now replaces'class'mode). [1] [2]createDataAttributeObserverandcreateAutoObserverfor robust theme change detection based on the configured strategy and priority. [1] [2]detectThemeModeto support the new strategies and fallback logic, and deprecated the'class'mode in favor of'auto'. [1] [2]ThemeDetectionStrategyandBrowserThemeDetection. [1] [2]React ThemeProvider and context updates:
ThemeProviderto use the new'auto'mode by default, support the new detection strategies, and clean up observers properly. The old'class'and'branding'modes are removed or replaced. [1] [2] [3] [4]ThemeContextand related types to use the newThemeModeand detection logic.API and type improvements:
createThemeAPI to exclude runtime detection properties from its config, clarifying its intended use.Code quality and consistency:
DOMTokenList, explicit type annotations, and improved observer setup/cleanup). [1] [2]These changes collectively provide a more flexible, reliable, and extensible foundation for theme management in applications using these packages.
Related Issues
Related PRs
Checklist
Security checks