Skip to content

Commit eea9b50

Browse files
pierrejeambrunephraimbuddy
authored andcommitted
Inherit core theme in React plugins (#60256) (#60405)
(cherry picked from commit 3e57f1e)
1 parent a716b3e commit eea9b50

File tree

5 files changed

+38
-404
lines changed

5 files changed

+38
-404
lines changed

airflow-core/src/airflow/ui/src/theme.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ export const customConfig = defineConfig({
399399

400400
export const system = createSystem(defaultConfig, customConfig);
401401

402+
// Once the system is created, make it globally available to dynamically imported React plugins.
403+
Reflect.set(globalThis, "ChakraUISystem", system);
404+
402405
// Utility function to resolve CSS variables to their computed values
403406
// See: https://github.com/chakra-ui/panda/discussions/2200
404407
export const getComputedCSSVariableValue = (variable: string): string =>

dev/react-plugin-tools/react_plugin_template/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ For development and testing, use `pnpm dev` which will:
7272
- Start a development server on port 5173
7373
- Load the component using `src/dev.tsx` entry point
7474
- Enable hot module replacement
75+
- Chakra Theme provided for local development is the default one, but in production when the plugin is loaded into the Airflow Core UI,
76+
it will inherit the main application theme for a consistent look and feel.
7577

7678
### Library Configuration
7779

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*!
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
export interface global {}
21+
22+
declare global {
23+
var ChakraUISystem: SystemContext | undefined
24+
}

dev/react-plugin-tools/react_plugin_template/src/main.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { FC } from "react";
2323
import { ColorModeProvider } from "src/context/colorMode";
2424
import { HomePage } from "src/pages/HomePage";
2525

26-
import { system } from "./theme";
26+
import { localSystem } from "./theme";
2727

2828
export interface PluginComponentProps {
2929
// Add any props your plugin component needs
@@ -33,6 +33,12 @@ export interface PluginComponentProps {
3333
* Main plugin component
3434
*/
3535
const PluginComponent: FC<PluginComponentProps> = (props) => {
36+
37+
// Use the globalChakraUISystem provided by the Airflow Core UI,
38+
// so the plugin has a consistent theming with the host Airflow UI,
39+
// fallback to localSystem for local development.
40+
const system = (globalThis.ChakraUISystem) ?? localSystem;
41+
3642
return (
3743
<ChakraProvider value={system}>
3844
<ColorModeProvider>

0 commit comments

Comments
 (0)