-
-
Notifications
You must be signed in to change notification settings - Fork 322
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
inject app theme into plugin instead of styles #2703
Conversation
Reviewer's Guide by SourceryThis PR changes how themes are handled in plugins by directly injecting theme configuration instead of relying on CSS stylesheet access. The implementation moves CSS variable generation to a dedicated module and modifies the plugin system to receive theme information directly rather than attempting to read styles from the parent application. Sequence diagram for Theme Injection into PluginsequenceDiagram
actor User
participant PluginContextService
participant PluginParentEngine
participant AltairV3Panel
User->>PluginContextService: Request Plugin
PluginContextService->>PluginParentEngine: Create PluginParentEngine with theme
PluginParentEngine->>AltairV3Panel: Pass theme and styles
AltairV3Panel->>AltairV3Panel: Inject CSS based on theme
AltairV3Panel-->>User: Rendered Plugin with Theme
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @imolorhe - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
import darkTheme from './defaults/dark'; | ||
import { ICustomTheme, ITheme, createTheme, hexToRgbStr } from './theme'; | ||
|
||
const asCSSVariablesString = (theme: ITheme) => { |
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.
issue (complexity): Consider refactoring CSS variable generation into structured mapping objects with type-safe accessors
The CSS variable generation can be simplified while maintaining explicit mapping. Here's how:
const COLOR_VARS = {
// Base colors
'black-color': (t) => t.colors.black,
'dark-grey-color': (t) => t.colors.darkGray,
// ... other colors
} as const;
const RGB_VARS = {
'rgb-black': (t) => hexToRgbStr(t.colors.black),
'rgb-dark-grey': (t) => hexToRgbStr(t.colors.darkGray),
// ... other rgb values
} as const;
const asCSSVariablesString = (theme: ITheme) => {
const createVars = (mapping: Record<string, (t: ITheme) => string>) =>
Object.entries(mapping)
.map(([key, getValue]) => `--${key}: ${getValue(theme)};`)
.join('\n ');
return `
:root {
${createVars(COLOR_VARS)}
${createVars(RGB_VARS)}
// Other variable groups...
}`;
};
This approach:
- Groups related variables into mapping objects
- Maintains explicit relationships between theme properties and CSS variables
- Reduces repetition and chance of errors
- Makes adding new variables easier
- Keeps type safety with const assertions
Visit the preview URL for this PR (updated for commit 4acb2bb): https://altair-gql--pr2703-imolorhe-inject-them-qs6s29ru.web.app (expires Sat, 16 Nov 2024 03:59:04 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 02d6323d75a99e532a38922862e269d63351a6cf |
Accessing stylesheet in a cross origin context fails with an error
The only reason we did this was to get the current theme of the app from the styles. However we can achieve the same thing if we pass the theme to the plugin for the plugin to create the styles itself/
Fixes
Checks
yarn test-build
Changes proposed in this pull request:
Summary by Sourcery
Enhancements: