@backstage/theme 0.6.8 → 0.6.9-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useEffect } from 'react';
|
|
3
2
|
import CssBaseline from '@material-ui/core/CssBaseline';
|
|
4
3
|
import { createGenerateClassName, StylesProvider, ThemeProvider } from '@material-ui/core/styles';
|
|
5
4
|
import { StyledEngineProvider, ThemeProvider as ThemeProvider$1 } from '@mui/material/styles';
|
|
6
5
|
import { unstable_ClassNameGenerator } from '@mui/material/className';
|
|
6
|
+
import { useApplyThemeAttributes } from './useApplyThemeAttributes.esm.js';
|
|
7
7
|
|
|
8
8
|
unstable_ClassNameGenerator.configure((componentName) => {
|
|
9
9
|
return `v5-${componentName}`;
|
|
@@ -15,16 +15,10 @@ function UnifiedThemeProvider(props) {
|
|
|
15
15
|
const { children, theme, noCssBaseline = false } = props;
|
|
16
16
|
const v4Theme = theme.getTheme("v4");
|
|
17
17
|
const v5Theme = theme.getTheme("v5");
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
document.body.setAttribute("data-theme-name", themeName);
|
|
23
|
-
return () => {
|
|
24
|
-
document.body.removeAttribute("data-theme-mode");
|
|
25
|
-
document.body.removeAttribute("data-theme-name");
|
|
26
|
-
};
|
|
27
|
-
}, [themeMode, themeName]);
|
|
18
|
+
useApplyThemeAttributes(
|
|
19
|
+
v4Theme ? v4Theme.palette.type : v5Theme?.palette.mode,
|
|
20
|
+
"backstage"
|
|
21
|
+
);
|
|
28
22
|
let cssBaseline = void 0;
|
|
29
23
|
if (!noCssBaseline) {
|
|
30
24
|
cssBaseline = /* @__PURE__ */ jsx(CssBaseline, {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnifiedThemeProvider.esm.js","sources":["../../src/unified/UnifiedThemeProvider.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ReactNode
|
|
1
|
+
{"version":3,"file":"UnifiedThemeProvider.esm.js","sources":["../../src/unified/UnifiedThemeProvider.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ReactNode } from 'react';\nimport CssBaseline from '@material-ui/core/CssBaseline';\nimport {\n ThemeProvider,\n StylesProvider,\n createGenerateClassName,\n Theme as Mui4Theme,\n} from '@material-ui/core/styles';\nimport {\n StyledEngineProvider,\n ThemeProvider as Mui5Provider,\n Theme as Mui5Theme,\n} from '@mui/material/styles';\nimport { UnifiedTheme } from './types';\nimport { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/material/className';\n\n/**\n * Props for {@link UnifiedThemeProvider}.\n *\n * @public\n */\nexport interface UnifiedThemeProviderProps {\n children: ReactNode;\n theme: UnifiedTheme;\n noCssBaseline?: boolean;\n}\n\n/**\n * This API is introduced in @mui/material (v5.0.5) as a replacement of deprecated createGenerateClassName & only affects v5 Material UI components from `@mui/*`.\n *\n * This call needs to be in the same module as the `UnifiedThemeProvider` to ensure that it doesn't get removed by tree shaking\n */\nClassNameGenerator.configure(componentName => {\n return `v5-${componentName}`;\n});\n\n// Background at https://mui.com/x/migration/migration-data-grid-v4/#using-mui-core-v4-with-v5\n// Rather than disabling globals and custom seed, we instead only set a production prefix that\n// won't collide with Material UI 5 styles. We've already got the separate class name generator\n// for v5 set up in just above, so only the production JSS needs deduplication.\nconst generateV4ClassName = createGenerateClassName({\n productionPrefix: 'jss4-',\n});\n\nimport { useApplyThemeAttributes } from './useApplyThemeAttributes';\n\n/**\n * Provides themes for all Material UI versions supported by the provided unified theme.\n *\n * @public\n */\nexport function UnifiedThemeProvider(\n props: UnifiedThemeProviderProps,\n): JSX.Element {\n const { children, theme, noCssBaseline = false } = props;\n\n const v4Theme = theme.getTheme('v4') as Mui4Theme;\n const v5Theme = theme.getTheme('v5') as Mui5Theme;\n\n useApplyThemeAttributes(\n v4Theme ? v4Theme.palette.type : v5Theme?.palette.mode,\n 'backstage',\n );\n\n let cssBaseline: JSX.Element | undefined = undefined;\n if (!noCssBaseline) {\n cssBaseline = <CssBaseline />;\n }\n\n let result = (\n <>\n {cssBaseline}\n {children}\n </>\n );\n\n if (v4Theme) {\n result = (\n <StylesProvider generateClassName={generateV4ClassName}>\n <ThemeProvider theme={v4Theme}>{result}</ThemeProvider>\n </StylesProvider>\n );\n }\n\n if (v5Theme) {\n result = (\n <StyledEngineProvider injectFirst>\n <Mui5Provider theme={v5Theme}>{result}</Mui5Provider>\n </StyledEngineProvider>\n );\n }\n\n return result;\n}\n"],"names":["ClassNameGenerator","Mui5Provider"],"mappings":";;;;;;;AAgDAA,2BAAA,CAAmB,UAAU,CAAA,aAAA,KAAiB;AAC5C,EAAA,OAAO,MAAM,aAAa,CAAA,CAAA;AAC5B,CAAC,CAAA;AAMD,MAAM,sBAAsB,uBAAA,CAAwB;AAAA,EAClD,gBAAA,EAAkB;AACpB,CAAC,CAAA;AASM,SAAS,qBACd,KAAA,EACa;AACb,EAAA,MAAM,EAAE,QAAA,EAAU,KAAA,EAAO,aAAA,GAAgB,OAAM,GAAI,KAAA;AAEnD,EAAA,MAAM,OAAA,GAAU,KAAA,CAAM,QAAA,CAAS,IAAI,CAAA;AACnC,EAAA,MAAM,OAAA,GAAU,KAAA,CAAM,QAAA,CAAS,IAAI,CAAA;AAEnC,EAAA,uBAAA;AAAA,IACE,OAAA,GAAU,OAAA,CAAQ,OAAA,CAAQ,IAAA,GAAO,SAAS,OAAA,CAAQ,IAAA;AAAA,IAClD;AAAA,GACF;AAEA,EAAA,IAAI,WAAA,GAAuC,MAAA;AAC3C,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,WAAA,uBAAe,WAAA,EAAA,EAAY,CAAA;AAAA,EAC7B;AAEA,EAAA,IAAI,yBACF,IAAA,CAAA,QAAA,EAAA,EACG,QAAA,EAAA;AAAA,IAAA,WAAA;AAAA,IACA;AAAA,GAAA,EACH,CAAA;AAGF,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,MAAA,mBACE,GAAA,CAAC,kBAAe,iBAAA,EAAmB,mBAAA,EACjC,8BAAC,aAAA,EAAA,EAAc,KAAA,EAAO,OAAA,EAAU,QAAA,EAAA,MAAA,EAAO,CAAA,EACzC,CAAA;AAAA,EAEJ;AAEA,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,MAAA,mBACE,GAAA,CAAC,wBAAqB,WAAA,EAAW,IAAA,EAC/B,8BAACC,eAAA,EAAA,EAAa,KAAA,EAAO,OAAA,EAAU,QAAA,EAAA,MAAA,EAAO,CAAA,EACxC,CAAA;AAAA,EAEJ;AAEA,EAAA,OAAO,MAAA;AACT;;;;"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const STACK_ATTR = "data-unified-theme-stack";
|
|
4
|
+
const MODE_ATTR = "data-theme-mode";
|
|
5
|
+
const NAME_ATTR = "data-theme-name";
|
|
6
|
+
function mutateAttrStack(mutator) {
|
|
7
|
+
const stack = (() => {
|
|
8
|
+
const raw = document.body.getAttribute(STACK_ATTR);
|
|
9
|
+
if (!raw) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const parsed = JSON.parse(raw);
|
|
14
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
15
|
+
} catch {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
})();
|
|
19
|
+
mutator(stack);
|
|
20
|
+
if (stack.length === 0) {
|
|
21
|
+
document.body.removeAttribute(STACK_ATTR);
|
|
22
|
+
} else {
|
|
23
|
+
document.body.setAttribute(STACK_ATTR, JSON.stringify(stack));
|
|
24
|
+
}
|
|
25
|
+
const top = stack[stack.length - 1];
|
|
26
|
+
if (top?.mode) {
|
|
27
|
+
document.body.setAttribute(MODE_ATTR, String(top.mode));
|
|
28
|
+
} else {
|
|
29
|
+
document.body.removeAttribute(MODE_ATTR);
|
|
30
|
+
}
|
|
31
|
+
if (top?.name) {
|
|
32
|
+
document.body.setAttribute(NAME_ATTR, String(top.name));
|
|
33
|
+
} else {
|
|
34
|
+
document.body.removeAttribute(NAME_ATTR);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function useApplyThemeAttributes(themeMode, themeName) {
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
mutateAttrStack((stack) => {
|
|
40
|
+
stack.push({ mode: themeMode, name: themeName });
|
|
41
|
+
});
|
|
42
|
+
return () => {
|
|
43
|
+
mutateAttrStack((stack) => {
|
|
44
|
+
stack.pop();
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
}, [themeMode, themeName]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { useApplyThemeAttributes };
|
|
51
|
+
//# sourceMappingURL=useApplyThemeAttributes.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useApplyThemeAttributes.esm.js","sources":["../../src/unified/useApplyThemeAttributes.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useEffect } from 'react';\n\ntype ThemeFrame = { mode?: string; name?: string };\n\nconst STACK_ATTR = 'data-unified-theme-stack';\nconst MODE_ATTR = 'data-theme-mode';\nconst NAME_ATTR = 'data-theme-name';\n\nfunction mutateAttrStack(mutator: (stack: ThemeFrame[]) => void) {\n const stack = (() => {\n const raw = document.body.getAttribute(STACK_ATTR);\n if (!raw) {\n return [] as ThemeFrame[];\n }\n try {\n const parsed = JSON.parse(raw);\n return Array.isArray(parsed) ? (parsed as ThemeFrame[]) : [];\n } catch {\n return [] as ThemeFrame[];\n }\n })();\n\n mutator(stack);\n\n if (stack.length === 0) {\n document.body.removeAttribute(STACK_ATTR);\n } else {\n document.body.setAttribute(STACK_ATTR, JSON.stringify(stack));\n }\n\n const top = stack[stack.length - 1];\n if (top?.mode) {\n document.body.setAttribute(MODE_ATTR, String(top.mode));\n } else {\n document.body.removeAttribute(MODE_ATTR);\n }\n if (top?.name) {\n document.body.setAttribute(NAME_ATTR, String(top.name));\n } else {\n document.body.removeAttribute(NAME_ATTR);\n }\n}\n\nexport function useApplyThemeAttributes(themeMode: string, themeName: string) {\n useEffect(() => {\n mutateAttrStack(stack => {\n stack.push({ mode: themeMode, name: themeName });\n });\n\n return () => {\n mutateAttrStack(stack => {\n stack.pop();\n });\n };\n }, [themeMode, themeName]);\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,UAAA,GAAa,0BAAA;AACnB,MAAM,SAAA,GAAY,iBAAA;AAClB,MAAM,SAAA,GAAY,iBAAA;AAElB,SAAS,gBAA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A,EACzC;AACF;AAEO,SAAS,uBAAA,CAAwB,WAAmB,SAAA,EAAmB;AAC5E,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,eAAA,CAAgB,CAAA,KAAA,KAAS;AACvB,MAAA,KAAA,CAAM,KAAK,EAAE,IAAA,EAAM,SAAA,EAAW,IAAA,EAAM,WAAW,CAAA;AAAA,IACjD,CAAC,CAAA;AAED,IAAA,OAAO,MAAM;AACX,MAAA,eAAA,CAAgB,CAAA,KAAA,KAAS;AACvB,QAAA,KAAA,CAAM,GAAA,EAAI;AAAA,MACZ,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,SAAA,EAAW,SAAS,CAAC,CAAA;AAC3B;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/theme",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9-next.0",
|
|
4
4
|
"description": "material-ui theme for use with Backstage.",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "web-library"
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@mui/material": "^5.12.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@backstage/cli": "
|
|
44
|
+
"@backstage/cli": "0.34.4-next.2",
|
|
45
45
|
"@mui/styles": "^5.14.18",
|
|
46
46
|
"@testing-library/jest-dom": "^6.0.0",
|
|
47
47
|
"@testing-library/react": "^16.0.0",
|