Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export const ChakraCustomProvider = ({ children }: PropsWithChildren) => {
return undefined;
}

return createTheme(theme as Theme);
const syst = createTheme(theme as Theme);

// Once the system is created, make it globally available to dynamically imported React plugins.
Reflect.set(globalThis, "ChakraUISystem", syst);

return syst;
}, [theme]);

return system && <ChakraProvider value={system}>{children}</ChakraProvider>;
Expand Down
2 changes: 2 additions & 0 deletions dev/react-plugin-tools/react_plugin_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ For development and testing, use `pnpm dev` which will:
- Start a development server on port 5173
- Load the component using `src/dev.tsx` entry point
- Enable hot module replacement
- Chakra Theme provided for local development is the default one, but in production when the plugin is loaded into the Airflow Core UI,
it will inherit the main application theme for a consistent look and feel.

### Library Configuration

Expand Down
24 changes: 24 additions & 0 deletions dev/react-plugin-tools/react_plugin_template/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export interface global {}

declare global {
var ChakraUISystem: SystemContext | undefined
}
8 changes: 7 additions & 1 deletion dev/react-plugin-tools/react_plugin_template/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { FC } from "react";
import { ColorModeProvider } from "src/context/colorMode";
import { HomePage } from "src/pages/HomePage";

import { system } from "./theme";
import { localSystem } from "./theme";

export interface PluginComponentProps {
// Add any props your plugin component needs
Expand All @@ -33,6 +33,12 @@ export interface PluginComponentProps {
* Main plugin component
*/
const PluginComponent: FC<PluginComponentProps> = (props) => {

// Use the globalChakraUISystem provided by the Airflow Core UI,
// so the plugin has a consistent theming with the host Airflow UI,
// fallback to localSystem for local development.
const system = (globalThis.ChakraUISystem) ?? localSystem;

return (
<ChakraProvider value={system}>
<ColorModeProvider>
Expand Down
Loading
Loading