Skip to content

Commit 60db269

Browse files
Add support for globalCss to custom theme (#61161)
* Add support for globalCss to custom theme * Fix CI
1 parent e166926 commit 60db269

File tree

9 files changed

+87
-5
lines changed

9 files changed

+87
-5
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 theme 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
@@ -1379,9 +1379,10 @@ api:
13791379
theme:
13801380
description: |
13811381
JSON config to customize the Chakra UI theme.
1382-
Currently only supports ``brand`` color customization.
1382+
Currently only supports ``brand`` color customization and ``globalCss``.
13831383
13841384
Must supply ``50``-``950`` OKLCH color values for ``brand`` color.
1385+
13851386
For usage see :ref:`customizing-ui-theme`
13861387
13871388
.. 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

airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@
4242
"950": {"value": "oklch(0.179 0.05 265.487)"},
4343
}
4444
}
45-
}
45+
},
46+
"globalCss": {
47+
"button": {
48+
"text-transform": "uppercase",
49+
},
50+
"a": {
51+
"text-transform": "uppercase",
52+
},
53+
},
4654
}
4755

4856
expected_config_response = {

docs/spelling_wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ Gitter
789789
gitter
790790
gke
791791
Glassdoor
792+
globalCSS
792793
globstring
793794
glyphicon
794795
Gmail

0 commit comments

Comments
 (0)