Skip to content

Commit 93b9cbc

Browse files
Add support for globalCss to custom theme
1 parent 11238e5 commit 93b9cbc

File tree

7 files changed

+77
-4
lines changed

7 files changed

+77
-4
lines changed

airflow-core/docs/howto/customize-ui.rst

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ We can provide a JSON configuration to customize the UI.
7070

7171
.. important::
7272

73-
- Currently only the ``brand`` color palette can be customized.
73+
- Currently only the ``brand`` color palette and globalCss can be customized.
7474
- You must supply ``50``-``950`` OKLCH color values for ``brand`` color.
7575
- OKLCH colors must have next format ``oklch(l c h)`` For more info see :ref:`config:api__theme`
76+
- There is also the ability to provide custom global CSS for a fine grained theming control.
7677

7778
.. note::
7879

@@ -150,6 +151,35 @@ Dark Mode
150151

151152
.. image:: ../img/change-theme/exmaple_theme_configuration_dark_mode.png
152153

154+
3. To add custom CSS rules to the airflow UI, you can include a ``globalCss`` key in the theme configuration. More information https://chakra-ui.com/docs/theming/customization/global-css
155+
156+
.. code-block::
157+
158+
AIRFLOW__API__THEME='{
159+
"tokens": {
160+
"colors": {
161+
"brand": {
162+
"50": { "value": "oklch(0.971 0.013 17.38)" },
163+
"100": { "value": "oklch(0.936 0.032 17.717)" },
164+
"200": { "value": "oklch(0.885 0.062 18.334)" },
165+
"300": { "value": "oklch(0.808 0.114 19.571)" },
166+
"400": { "value": "oklch(0.704 0.191 22.216)" },
167+
"500": { "value": "oklch(0.637 0.237 25.331)" },
168+
"600": { "value": "oklch(0.577 0.245 27.325)" },
169+
"700": { "value": "oklch(0.505 0.213 27.518)" },
170+
"800": { "value": "oklch(0.444 0.177 26.899)" },
171+
"900": { "value": "oklch(0.396 0.141 25.723)" },
172+
"950": { "value": "oklch(0.258 0.092 26.042)" }
173+
}
174+
}
175+
},
176+
"globalCss": {
177+
"button": {
178+
"text-transform": "uppercase"
179+
}
180+
}
181+
}'
182+
153183
|
154184
155185
Adding Dashboard Alert Messages

airflow-core/src/airflow/api_fastapi/common/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,4 @@ class Theme(BaseModel):
178178
],
179179
],
180180
]
181+
globalCss: dict[str, dict] | None = None

airflow-core/src/airflow/api_fastapi/core_api/openapi/_private_ui.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2739,6 +2739,14 @@ components:
27392739
const: colors
27402740
type: object
27412741
title: Tokens
2742+
globalCss:
2743+
anyOf:
2744+
- additionalProperties:
2745+
additionalProperties: true
2746+
type: object
2747+
type: object
2748+
- type: 'null'
2749+
title: Globalcss
27422750
type: object
27432751
required:
27442752
- tokens

airflow-core/src/airflow/config_templates/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,9 +1372,10 @@ api:
13721372
theme:
13731373
description: |
13741374
JSON config to customize the Chakra UI theme.
1375-
Currently only supports ``brand`` color customization.
1375+
Currently only supports ``brand`` color customization and ``globalCss``.
13761376
13771377
Must supply ``50``-``950`` OKLCH color values for ``brand`` color.
1378+
13781379
For usage see :ref:`customizing-ui-theme`
13791380
13801381
.. important::

airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8382,6 +8382,21 @@ export const $Theme = {
83828382
},
83838383
type: 'object',
83848384
title: 'Tokens'
8385+
},
8386+
globalCss: {
8387+
anyOf: [
8388+
{
8389+
additionalProperties: {
8390+
additionalProperties: true,
8391+
type: 'object'
8392+
},
8393+
type: 'object'
8394+
},
8395+
{
8396+
type: 'null'
8397+
}
8398+
],
8399+
title: 'Globalcss'
83858400
}
83868401
},
83878402
type: 'object',

airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,6 +2078,11 @@ export type Theme = {
20782078
};
20792079
};
20802080
};
2081+
globalCss?: {
2082+
[key: string]: {
2083+
[key: string]: unknown;
2084+
};
2085+
} | null;
20812086
};
20822087

20832088
/**

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
/* eslint-disable perfectionist/sort-objects */
2121

2222
/* eslint-disable max-lines */
23-
import { createSystem, defaultConfig, defineConfig, mergeConfigs } from "@chakra-ui/react";
23+
import {
24+
createSystem,
25+
defaultConfig,
26+
defineConfig,
27+
mergeConfigs,
28+
type SystemStyleObject,
29+
} from "@chakra-ui/react";
2430
import type { CSSProperties } from "react";
2531

2632
import type { Theme } from "openapi/requests/types.gen";
@@ -400,7 +406,14 @@ const defaultAirflowTheme = {
400406
export const createTheme = (userTheme?: Theme) => {
401407
const defaultAirflowConfig = defineConfig({ theme: defaultAirflowTheme });
402408

403-
const userConfig = defineConfig({ theme: userTheme ?? {} });
409+
const userConfig = defineConfig(
410+
userTheme
411+
? {
412+
theme: { tokens: userTheme.tokens },
413+
globalCss: userTheme.globalCss as Record<string, SystemStyleObject>,
414+
}
415+
: {},
416+
);
404417

405418
const mergedConfig = mergeConfigs(defaultConfig, defaultAirflowConfig, userConfig);
406419

0 commit comments

Comments
 (0)