@red-hat-developer-hub/backstage-plugin-theme 0.8.3 → 0.9.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 +6 -0
- package/dist/components/ThemeProvider.esm.js +5 -5
- package/dist/components/ThemeProvider.esm.js.map +1 -1
- package/dist/hooks/useBranding.esm.js +2 -2
- package/dist/hooks/useBranding.esm.js.map +1 -1
- package/dist/hooks/useTheme.esm.js +2 -2
- package/dist/hooks/useTheme.esm.js.map +1 -1
- package/dist/hooks/useThemeConfig.esm.js +2 -2
- package/dist/hooks/useThemeConfig.esm.js.map +1 -1
- package/dist/hooks/useThemeOptions.esm.js +2 -2
- package/dist/hooks/useThemeOptions.esm.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/themes.esm.js +13 -12
- package/dist/themes.esm.js.map +1 -1
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { UnifiedThemeProvider } from '@backstage/theme';
|
|
3
3
|
import { StyledEngineProvider, ThemeProvider as ThemeProvider$1 } from '@mui/material/styles';
|
|
4
4
|
import { useTheme } from '../hooks/useTheme.esm.js';
|
|
@@ -7,18 +7,18 @@ import { useThemeConfig } from '../hooks/useThemeConfig.esm.js';
|
|
|
7
7
|
const ThemeProvider = ({
|
|
8
8
|
theme,
|
|
9
9
|
children
|
|
10
|
-
}) => /* @__PURE__ */
|
|
10
|
+
}) => /* @__PURE__ */ jsx(UnifiedThemeProvider, { theme, children: /* @__PURE__ */ jsx(StyledEngineProvider, { injectFirst: true, children: /* @__PURE__ */ jsx(ThemeProvider$1, { theme: theme.getTheme("v5"), children }) }) });
|
|
11
11
|
const createThemeProvider = (theme) => function RHDHThemeProvider({ children }) {
|
|
12
|
-
return /* @__PURE__ */
|
|
12
|
+
return /* @__PURE__ */ jsx(ThemeProvider, { theme, children });
|
|
13
13
|
};
|
|
14
14
|
const createThemeProviderForThemeConfig = (themeConfig) => function RHDHThemeProviderForThemeConfig({ children }) {
|
|
15
15
|
const theme = useTheme(themeConfig);
|
|
16
|
-
return /* @__PURE__ */
|
|
16
|
+
return /* @__PURE__ */ jsx(ThemeProvider, { theme, children });
|
|
17
17
|
};
|
|
18
18
|
const createThemeProviderForThemeName = (themeName) => function RHDHThemeProviderForThemeName({ children }) {
|
|
19
19
|
const themeConfig = useThemeConfig(themeName);
|
|
20
20
|
const theme = useTheme(themeConfig);
|
|
21
|
-
return /* @__PURE__ */
|
|
21
|
+
return /* @__PURE__ */ jsx(ThemeProvider, { theme, children });
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export { createThemeProvider, createThemeProviderForThemeConfig, createThemeProviderForThemeName };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.esm.js","sources":["../../src/components/ThemeProvider.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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
|
|
1
|
+
{"version":3,"file":"ThemeProvider.esm.js","sources":["../../src/components/ThemeProvider.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 type { ReactNode } from 'react';\nimport { AppTheme } from '@backstage/core-plugin-api';\nimport { UnifiedTheme, UnifiedThemeProvider } from '@backstage/theme';\n\nimport {\n StyledEngineProvider,\n ThemeProvider as Mui5Provider,\n Theme as Mui5Theme,\n} from '@mui/material/styles';\n\nimport { useTheme } from '../hooks/useTheme';\nimport { useThemeConfig } from '../hooks/useThemeConfig';\nimport { ThemeConfig } from '../types';\n\n/**\n * Uses the UnifiedThemeProvider to style MUI v4 and v5 components.\n *\n * This component duplicated the StyledEngineProvider and MUI v5 ThemeProvider\n * to solve an issue that the defaultProps from the component configurations\n * (see `utils/createComponents.ts`) wasn't picked up.\n *\n * https://github.com/backstage/backstage/blob/master/packages/theme/src/unified/UnifiedThemeProvider.tsx#L94-L100\n */\nconst ThemeProvider = ({\n theme,\n children,\n}: {\n theme: UnifiedTheme;\n children: ReactNode;\n}) => (\n <UnifiedThemeProvider theme={theme}>\n <StyledEngineProvider injectFirst>\n <Mui5Provider theme={theme.getTheme('v5') as Mui5Theme}>\n {children}\n </Mui5Provider>\n </StyledEngineProvider>\n </UnifiedThemeProvider>\n);\n\nexport const createThemeProvider = (\n theme: UnifiedTheme,\n): AppTheme['Provider'] =>\n function RHDHThemeProvider({ children }) {\n return <ThemeProvider theme={theme}>{children}</ThemeProvider>;\n };\n\nexport const createThemeProviderForThemeConfig = (\n themeConfig: ThemeConfig,\n): AppTheme['Provider'] =>\n function RHDHThemeProviderForThemeConfig({ children }) {\n const theme = useTheme(themeConfig);\n return <ThemeProvider theme={theme}>{children}</ThemeProvider>;\n };\n\nexport const createThemeProviderForThemeName = (\n themeName: string,\n): AppTheme['Provider'] =>\n function RHDHThemeProviderForThemeName({ children }) {\n const themeConfig = useThemeConfig(themeName);\n const theme = useTheme(themeConfig);\n return <ThemeProvider theme={theme}>{children}</ThemeProvider>;\n };\n"],"names":["Mui5Provider"],"mappings":";;;;;;AAuCA,MAAM,gBAAgB,CAAC;AAAA,EACrB,KAAA;AAAA,EACA;AACF,CAAA,yBAIG,oBAAqB,EAAA,EAAA,KAAA,EACpB,QAAC,kBAAA,GAAA,CAAA,oBAAA,EAAA,EAAqB,aAAW,IAC/B,EAAA,QAAA,kBAAA,GAAA,CAACA,eAAa,EAAA,EAAA,KAAA,EAAO,MAAM,QAAS,CAAA,IAAI,CACrC,EAAA,QAAA,EACH,GACF,CACF,EAAA,CAAA;AAGK,MAAM,sBAAsB,CACjC,KAAA,KAEA,SAAS,iBAAkB,CAAA,EAAE,UAAY,EAAA;AACvC,EAAO,uBAAA,GAAA,CAAC,aAAc,EAAA,EAAA,KAAA,EAAe,QAAS,EAAA,CAAA;AAChD;AAEK,MAAM,oCAAoC,CAC/C,WAAA,KAEA,SAAS,+BAAgC,CAAA,EAAE,UAAY,EAAA;AACrD,EAAM,MAAA,KAAA,GAAQ,SAAS,WAAW,CAAA;AAClC,EAAO,uBAAA,GAAA,CAAC,aAAc,EAAA,EAAA,KAAA,EAAe,QAAS,EAAA,CAAA;AAChD;AAEK,MAAM,kCAAkC,CAC7C,SAAA,KAEA,SAAS,6BAA8B,CAAA,EAAE,UAAY,EAAA;AACnD,EAAM,MAAA,WAAA,GAAc,eAAe,SAAS,CAAA;AAC5C,EAAM,MAAA,KAAA,GAAQ,SAAS,WAAW,CAAA;AAClC,EAAO,uBAAA,GAAA,CAAC,aAAc,EAAA,EAAA,KAAA,EAAe,QAAS,EAAA,CAAA;AAChD;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
2
|
import { useApi, configApiRef } from '@backstage/core-plugin-api';
|
|
3
3
|
|
|
4
4
|
const useBranding = () => {
|
|
@@ -7,7 +7,7 @@ const useBranding = () => {
|
|
|
7
7
|
configApi = useApi(configApiRef);
|
|
8
8
|
} catch (err) {
|
|
9
9
|
}
|
|
10
|
-
return
|
|
10
|
+
return useMemo(() => {
|
|
11
11
|
const branding = configApi?.getOptional("app.branding");
|
|
12
12
|
return branding;
|
|
13
13
|
}, [configApi]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBranding.esm.js","sources":["../../src/hooks/useBranding.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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
|
|
1
|
+
{"version":3,"file":"useBranding.esm.js","sources":["../../src/hooks/useBranding.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 { useMemo } from 'react';\nimport { ConfigApi, configApiRef, useApi } from '@backstage/core-plugin-api';\nimport { Branding } from '../types';\n\nexport const useBranding = (): Branding | undefined => {\n let configApi: ConfigApi | undefined = undefined;\n try {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n configApi = useApi(configApiRef);\n } catch (err) {\n // useApi won't be initialized initially in createApp theme provider, and will get updated later\n }\n return useMemo(() => {\n const branding = configApi?.getOptional<Branding>('app.branding');\n return branding;\n }, [configApi]);\n};\n"],"names":[],"mappings":";;;AAoBO,MAAM,cAAc,MAA4B;AACrD,EAAA,IAAI,SAAmC,GAAA,SAAA;AACvC,EAAI,IAAA;AAEF,IAAA,SAAA,GAAY,OAAO,YAAY,CAAA;AAAA,WACxB,GAAK,EAAA;AAAA;AAGd,EAAA,OAAO,QAAQ,MAAM;AACnB,IAAM,MAAA,QAAA,GAAW,SAAW,EAAA,WAAA,CAAsB,cAAc,CAAA;AAChE,IAAO,OAAA,QAAA;AAAA,GACT,EAAG,CAAC,SAAS,CAAC,CAAA;AAChB;;;;"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
2
|
import { createUnifiedTheme } from '@backstage/theme';
|
|
3
3
|
import { useThemeOptions } from './useThemeOptions.esm.js';
|
|
4
4
|
|
|
5
5
|
const useTheme = (themeConfig) => {
|
|
6
6
|
const unifiedThemeOptions = useThemeOptions(themeConfig);
|
|
7
|
-
const theme =
|
|
7
|
+
const theme = useMemo(
|
|
8
8
|
() => createUnifiedTheme(unifiedThemeOptions),
|
|
9
9
|
[unifiedThemeOptions]
|
|
10
10
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTheme.esm.js","sources":["../../src/hooks/useTheme.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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
|
|
1
|
+
{"version":3,"file":"useTheme.esm.js","sources":["../../src/hooks/useTheme.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 { useMemo } from 'react';\nimport { createUnifiedTheme, type UnifiedTheme } from '@backstage/theme';\nimport type { ThemeConfig } from '../types';\nimport { useThemeOptions } from './useThemeOptions';\n\n/** Creates a memorized Backstage UnifiedTheme based on the given ThemeConfig. */\nexport const useTheme = (themeConfig: ThemeConfig): UnifiedTheme => {\n const unifiedThemeOptions = useThemeOptions(themeConfig);\n const theme = useMemo<UnifiedTheme>(\n () => createUnifiedTheme(unifiedThemeOptions),\n [unifiedThemeOptions],\n );\n return theme;\n};\n"],"names":[],"mappings":";;;;AAsBa,MAAA,QAAA,GAAW,CAAC,WAA2C,KAAA;AAClE,EAAM,MAAA,mBAAA,GAAsB,gBAAgB,WAAW,CAAA;AACvD,EAAA,MAAM,KAAQ,GAAA,OAAA;AAAA,IACZ,MAAM,mBAAmB,mBAAmB,CAAA;AAAA,IAC5C,CAAC,mBAAmB;AAAA,GACtB;AACA,EAAO,OAAA,KAAA;AACT;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
2
|
import { useApi, configApiRef } from '@backstage/core-plugin-api';
|
|
3
3
|
|
|
4
4
|
const useThemeConfig = (themeName) => {
|
|
@@ -7,7 +7,7 @@ const useThemeConfig = (themeName) => {
|
|
|
7
7
|
configApi = useApi(configApiRef);
|
|
8
8
|
} catch (err) {
|
|
9
9
|
}
|
|
10
|
-
return
|
|
10
|
+
return useMemo(() => {
|
|
11
11
|
if (!configApi) {
|
|
12
12
|
return {
|
|
13
13
|
mode: themeName.includes("dark") ? "dark" : "light"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThemeConfig.esm.js","sources":["../../src/hooks/useThemeConfig.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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
|
|
1
|
+
{"version":3,"file":"useThemeConfig.esm.js","sources":["../../src/hooks/useThemeConfig.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 { useMemo } from 'react';\nimport { ConfigApi, configApiRef, useApi } from '@backstage/core-plugin-api';\nimport { ThemeConfig } from '../types';\n\nexport const useThemeConfig = (themeName: string): ThemeConfig => {\n let configApi: ConfigApi | undefined = undefined;\n try {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n configApi = useApi<ConfigApi>(configApiRef); // NOSONAR\n } catch (err) {\n // useApi won't be initialized initially in createApp theme provider, and will get updated later\n }\n return useMemo(() => {\n if (!configApi) {\n return {\n mode: themeName.includes('dark') ? 'dark' : 'light',\n };\n }\n const themeConfig =\n configApi.getOptional<ThemeConfig>(`app.branding.theme.${themeName}`) ??\n {};\n if (!themeConfig.mode) {\n themeConfig.mode = themeName.includes('dark') ? 'dark' : 'light';\n }\n\n if (Array.isArray(themeConfig?.pageTheme?.default?.fontColor)) {\n themeConfig.pageTheme.default.fontColor =\n themeConfig.pageTheme.default.fontColor[0];\n }\n\n return themeConfig;\n }, [themeName, configApi]);\n};\n"],"names":[],"mappings":";;;AAoBa,MAAA,cAAA,GAAiB,CAAC,SAAmC,KAAA;AAChE,EAAA,IAAI,SAAmC,GAAA,SAAA;AACvC,EAAI,IAAA;AAEF,IAAA,SAAA,GAAY,OAAkB,YAAY,CAAA;AAAA,WACnC,GAAK,EAAA;AAAA;AAGd,EAAA,OAAO,QAAQ,MAAM;AACnB,IAAA,IAAI,CAAC,SAAW,EAAA;AACd,MAAO,OAAA;AAAA,QACL,IAAM,EAAA,SAAA,CAAU,QAAS,CAAA,MAAM,IAAI,MAAS,GAAA;AAAA,OAC9C;AAAA;AAEF,IAAA,MAAM,cACJ,SAAU,CAAA,WAAA,CAAyB,sBAAsB,SAAS,CAAA,CAAE,KACpE,EAAC;AACH,IAAI,IAAA,CAAC,YAAY,IAAM,EAAA;AACrB,MAAA,WAAA,CAAY,IAAO,GAAA,SAAA,CAAU,QAAS,CAAA,MAAM,IAAI,MAAS,GAAA,OAAA;AAAA;AAG3D,IAAA,IAAI,MAAM,OAAQ,CAAA,WAAA,EAAa,SAAW,EAAA,OAAA,EAAS,SAAS,CAAG,EAAA;AAC7D,MAAA,WAAA,CAAY,UAAU,OAAQ,CAAA,SAAA,GAC5B,YAAY,SAAU,CAAA,OAAA,CAAQ,UAAU,CAAC,CAAA;AAAA;AAG7C,IAAO,OAAA,WAAA;AAAA,GACN,EAAA,CAAC,SAAW,EAAA,SAAS,CAAC,CAAA;AAC3B;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
2
|
import { getDefaultThemeConfig } from '../backstage.esm.js';
|
|
3
3
|
import { getDefaultThemeConfig as getDefaultThemeConfig$1 } from '../rhdh.esm.js';
|
|
4
4
|
import { migrateThemeConfig } from '../utils/migrateTheme.esm.js';
|
|
@@ -7,7 +7,7 @@ import { createPageThemes } from '../utils/createPageThemes.esm.js';
|
|
|
7
7
|
import { createComponents } from '../utils/createComponents.esm.js';
|
|
8
8
|
|
|
9
9
|
const useThemeOptions = (themeConfig) => {
|
|
10
|
-
const theme =
|
|
10
|
+
const theme = useMemo(() => {
|
|
11
11
|
const mode = themeConfig.mode ?? "light";
|
|
12
12
|
const variant = themeConfig.variant ?? "rhdh";
|
|
13
13
|
let defaultThemeConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThemeOptions.esm.js","sources":["../../src/hooks/useThemeOptions.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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
|
|
1
|
+
{"version":3,"file":"useThemeOptions.esm.js","sources":["../../src/hooks/useThemeOptions.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 { useMemo } from 'react';\nimport { type UnifiedThemeOptions } from '@backstage/theme';\nimport type { ThemeConfig } from '../types';\nimport * as backstage from '../backstage';\nimport * as rhdh from '../rhdh';\nimport { migrateThemeConfig } from '../utils/migrateTheme';\nimport { mergeUnifiedThemeOptions } from '../utils/mergeTheme';\nimport { createPageThemes } from '../utils/createPageThemes';\nimport { createComponents } from '../utils/createComponents';\n\n/** Creates a memorized Backstage UnifiedThemeOptions based on the given ThemeConfig. */\nexport const useThemeOptions = (\n themeConfig: ThemeConfig,\n): UnifiedThemeOptions => {\n const theme = useMemo<UnifiedThemeOptions>(() => {\n const mode = themeConfig.mode ?? 'light';\n const variant = themeConfig.variant ?? 'rhdh';\n\n let defaultThemeConfig: ThemeConfig;\n if (variant === 'backstage') {\n defaultThemeConfig = backstage.getDefaultThemeConfig(mode);\n } else {\n defaultThemeConfig = rhdh.getDefaultThemeConfig(mode);\n }\n\n const migratedThemeConfig = migrateThemeConfig(themeConfig);\n const mergedThemeConfig = mergeUnifiedThemeOptions(\n defaultThemeConfig,\n migratedThemeConfig,\n );\n\n const unifiedThemeOption: UnifiedThemeOptions = {\n palette: mergedThemeConfig.palette as UnifiedThemeOptions['palette'],\n defaultPageTheme: mergedThemeConfig.defaultPageTheme,\n fontFamily: mergedThemeConfig.fontFamily,\n htmlFontSize: mergedThemeConfig.htmlFontSize,\n typography: mergedThemeConfig.typography,\n };\n\n unifiedThemeOption.pageTheme = createPageThemes(mergedThemeConfig);\n\n if (variant !== 'backstage') {\n unifiedThemeOption.components = createComponents(mergedThemeConfig);\n }\n\n return unifiedThemeOption;\n }, [themeConfig]);\n return theme;\n};\n"],"names":["backstage.getDefaultThemeConfig","rhdh.getDefaultThemeConfig"],"mappings":";;;;;;;;AA2Ba,MAAA,eAAA,GAAkB,CAC7B,WACwB,KAAA;AACxB,EAAM,MAAA,KAAA,GAAQ,QAA6B,MAAM;AAC/C,IAAM,MAAA,IAAA,GAAO,YAAY,IAAQ,IAAA,OAAA;AACjC,IAAM,MAAA,OAAA,GAAU,YAAY,OAAW,IAAA,MAAA;AAEvC,IAAI,IAAA,kBAAA;AACJ,IAAA,IAAI,YAAY,WAAa,EAAA;AAC3B,MAAqB,kBAAA,GAAAA,sBAAgC,IAAI,CAAA;AAAA,KACpD,MAAA;AACL,MAAqB,kBAAA,GAAAC,wBAA2B,IAAI,CAAA;AAAA;AAGtD,IAAM,MAAA,mBAAA,GAAsB,mBAAmB,WAAW,CAAA;AAC1D,IAAA,MAAM,iBAAoB,GAAA,wBAAA;AAAA,MACxB,kBAAA;AAAA,MACA;AAAA,KACF;AAEA,IAAA,MAAM,kBAA0C,GAAA;AAAA,MAC9C,SAAS,iBAAkB,CAAA,OAAA;AAAA,MAC3B,kBAAkB,iBAAkB,CAAA,gBAAA;AAAA,MACpC,YAAY,iBAAkB,CAAA,UAAA;AAAA,MAC9B,cAAc,iBAAkB,CAAA,YAAA;AAAA,MAChC,YAAY,iBAAkB,CAAA;AAAA,KAChC;AAEA,IAAmB,kBAAA,CAAA,SAAA,GAAY,iBAAiB,iBAAiB,CAAA;AAEjE,IAAA,IAAI,YAAY,WAAa,EAAA;AAC3B,MAAmB,kBAAA,CAAA,UAAA,GAAa,iBAAiB,iBAAiB,CAAA;AAAA;AAGpE,IAAO,OAAA,kBAAA;AAAA,GACT,EAAG,CAAC,WAAW,CAAC,CAAA;AAChB,EAAO,OAAA,KAAA;AACT;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
export { default as LightIcon } from '@mui/icons-material/WbSunnyRounded';
|
|
2
3
|
export { default as DarkIcon } from '@mui/icons-material/Brightness2Rounded';
|
|
3
4
|
import { UnifiedThemeOptions } from '@backstage/theme';
|
|
4
5
|
import * as _mui_material_styles from '@mui/material/styles';
|
|
5
|
-
import
|
|
6
|
+
import * as react from 'react';
|
|
6
7
|
import { AppTheme } from '@backstage/core-plugin-api';
|
|
7
8
|
|
|
8
9
|
type BackstageThemePalette = UnifiedThemeOptions['palette'];
|
|
@@ -109,10 +110,10 @@ declare const useThemeConfig: (themeName: string) => ThemeConfig;
|
|
|
109
110
|
declare const useThemeOptions: (themeConfig: ThemeConfig) => UnifiedThemeOptions;
|
|
110
111
|
|
|
111
112
|
declare const lightThemeProvider: (props: {
|
|
112
|
-
children:
|
|
113
|
+
children: react.ReactNode;
|
|
113
114
|
}) => JSX.Element | null;
|
|
114
115
|
declare const darkThemeProvider: (props: {
|
|
115
|
-
children:
|
|
116
|
+
children: react.ReactNode;
|
|
116
117
|
}) => JSX.Element | null;
|
|
117
118
|
declare const getAllThemes: () => AppTheme[];
|
|
118
119
|
declare const useAllThemes: () => AppTheme[];
|
package/dist/themes.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useMemo } from 'react';
|
|
2
3
|
import { themes } from '@backstage/theme';
|
|
3
4
|
import LightIcon from '@mui/icons-material/WbSunnyRounded';
|
|
4
5
|
import DarkIcon from '@mui/icons-material/Brightness2Rounded';
|
|
@@ -15,21 +16,21 @@ const getAllThemes = () => {
|
|
|
15
16
|
id: "light",
|
|
16
17
|
title: "RHDH Light (latest)",
|
|
17
18
|
variant: "light",
|
|
18
|
-
icon: /* @__PURE__ */
|
|
19
|
+
icon: /* @__PURE__ */ jsx(LightIcon, {}),
|
|
19
20
|
Provider: createThemeProviderForThemeName("light")
|
|
20
21
|
},
|
|
21
22
|
{
|
|
22
23
|
id: "dark",
|
|
23
24
|
title: "RHDH Dark (latest)",
|
|
24
25
|
variant: "dark",
|
|
25
|
-
icon: /* @__PURE__ */
|
|
26
|
+
icon: /* @__PURE__ */ jsx(DarkIcon, {}),
|
|
26
27
|
Provider: createThemeProviderForThemeName("dark")
|
|
27
28
|
},
|
|
28
29
|
{
|
|
29
30
|
id: "light-customized",
|
|
30
31
|
title: "RHDH Light (customized)",
|
|
31
32
|
variant: "light",
|
|
32
|
-
icon: /* @__PURE__ */
|
|
33
|
+
icon: /* @__PURE__ */ jsx(LightIcon, {}),
|
|
33
34
|
Provider: createThemeProviderForThemeConfig({
|
|
34
35
|
mode: "light",
|
|
35
36
|
variant: "rhdh",
|
|
@@ -43,7 +44,7 @@ const getAllThemes = () => {
|
|
|
43
44
|
id: "dark-customized",
|
|
44
45
|
title: "RHDH Dark (customized)",
|
|
45
46
|
variant: "dark",
|
|
46
|
-
icon: /* @__PURE__ */
|
|
47
|
+
icon: /* @__PURE__ */ jsx(DarkIcon, {}),
|
|
47
48
|
Provider: createThemeProviderForThemeConfig({
|
|
48
49
|
mode: "dark",
|
|
49
50
|
variant: "rhdh",
|
|
@@ -57,20 +58,20 @@ const getAllThemes = () => {
|
|
|
57
58
|
id: "backstage-light",
|
|
58
59
|
title: "Backstage Light",
|
|
59
60
|
variant: "light",
|
|
60
|
-
icon: /* @__PURE__ */
|
|
61
|
+
icon: /* @__PURE__ */ jsx(LightIcon, {}),
|
|
61
62
|
Provider: createThemeProvider(themes.light)
|
|
62
63
|
},
|
|
63
64
|
{
|
|
64
65
|
id: "backstage-dark",
|
|
65
66
|
title: "Backstage Dark",
|
|
66
67
|
variant: "dark",
|
|
67
|
-
icon: /* @__PURE__ */
|
|
68
|
+
icon: /* @__PURE__ */ jsx(DarkIcon, {}),
|
|
68
69
|
Provider: createThemeProvider(themes.dark)
|
|
69
70
|
}
|
|
70
71
|
];
|
|
71
72
|
};
|
|
72
73
|
const useAllThemes = () => {
|
|
73
|
-
return
|
|
74
|
+
return useMemo(() => getAllThemes(), []);
|
|
74
75
|
};
|
|
75
76
|
const getThemes = () => {
|
|
76
77
|
return [
|
|
@@ -78,23 +79,23 @@ const getThemes = () => {
|
|
|
78
79
|
id: "light",
|
|
79
80
|
title: "Light",
|
|
80
81
|
variant: "light",
|
|
81
|
-
icon: /* @__PURE__ */
|
|
82
|
+
icon: /* @__PURE__ */ jsx(LightIcon, {}),
|
|
82
83
|
Provider: createThemeProviderForThemeName("light")
|
|
83
84
|
},
|
|
84
85
|
{
|
|
85
86
|
id: "dark",
|
|
86
87
|
title: "Dark",
|
|
87
88
|
variant: "dark",
|
|
88
|
-
icon: /* @__PURE__ */
|
|
89
|
+
icon: /* @__PURE__ */ jsx(DarkIcon, {}),
|
|
89
90
|
Provider: createThemeProviderForThemeName("dark")
|
|
90
91
|
}
|
|
91
92
|
];
|
|
92
93
|
};
|
|
93
94
|
const useThemes = () => {
|
|
94
|
-
return
|
|
95
|
+
return useMemo(() => getThemes(), []);
|
|
95
96
|
};
|
|
96
97
|
const useLoaderTheme = () => {
|
|
97
|
-
return
|
|
98
|
+
return useMemo(() => {
|
|
98
99
|
const latestTheme = localStorage.getItem("theme");
|
|
99
100
|
const mode = latestTheme?.includes("dark") ? "dark" : "light";
|
|
100
101
|
const variant = latestTheme?.includes("backstage") ? "backstage" : "rhdh";
|
package/dist/themes.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"themes.esm.js","sources":["../src/themes.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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
|
|
1
|
+
{"version":3,"file":"themes.esm.js","sources":["../src/themes.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 { useMemo } from 'react';\nimport { AppTheme } from '@backstage/core-plugin-api';\nimport { themes } from '@backstage/theme';\n\nimport LightIcon from '@mui/icons-material/WbSunnyRounded';\nimport DarkIcon from '@mui/icons-material/Brightness2Rounded';\nimport { createTheme } from '@mui/material/styles';\n\nimport {\n createThemeProvider,\n createThemeProviderForThemeName,\n createThemeProviderForThemeConfig,\n} from './components/ThemeProvider';\nimport * as backstage from './backstage';\nimport * as rhdh from './rhdh';\n\nexport const lightThemeProvider = createThemeProviderForThemeName('light');\n\nexport const darkThemeProvider = createThemeProviderForThemeName('dark');\n\nexport const getAllThemes = (): AppTheme[] => {\n return [\n {\n id: 'light',\n title: 'RHDH Light (latest)',\n variant: 'light',\n icon: <LightIcon />,\n Provider: createThemeProviderForThemeName('light'),\n },\n {\n id: 'dark',\n title: 'RHDH Dark (latest)',\n variant: 'dark',\n icon: <DarkIcon />,\n Provider: createThemeProviderForThemeName('dark'),\n },\n {\n id: 'light-customized',\n title: 'RHDH Light (customized)',\n variant: 'light',\n icon: <LightIcon />,\n Provider: createThemeProviderForThemeConfig({\n mode: 'light',\n variant: 'rhdh',\n palette: {\n primary: { main: '#ff0000' },\n secondary: { main: '#00ff00' },\n },\n }),\n },\n {\n id: 'dark-customized',\n title: 'RHDH Dark (customized)',\n variant: 'dark',\n icon: <DarkIcon />,\n Provider: createThemeProviderForThemeConfig({\n mode: 'dark',\n variant: 'rhdh',\n palette: {\n primary: { main: '#ff0000' },\n secondary: { main: '#00ff00' },\n },\n }),\n },\n {\n id: 'backstage-light',\n title: 'Backstage Light',\n variant: 'light',\n icon: <LightIcon />,\n Provider: createThemeProvider(themes.light),\n },\n {\n id: 'backstage-dark',\n title: 'Backstage Dark',\n variant: 'dark',\n icon: <DarkIcon />,\n Provider: createThemeProvider(themes.dark),\n },\n ];\n};\n\nexport const useAllThemes = (): AppTheme[] => {\n return useMemo(() => getAllThemes(), []);\n};\n\nexport const getThemes = (): AppTheme[] => {\n return [\n {\n id: 'light',\n title: 'Light',\n variant: 'light',\n icon: <LightIcon />,\n Provider: createThemeProviderForThemeName('light'),\n },\n {\n id: 'dark',\n title: 'Dark',\n variant: 'dark',\n icon: <DarkIcon />,\n Provider: createThemeProviderForThemeName('dark'),\n },\n ];\n};\n\nexport const useThemes = (): AppTheme[] => {\n return useMemo(() => getThemes(), []);\n};\n\nexport const useLoaderTheme = () => {\n return useMemo(() => {\n const latestTheme = localStorage.getItem('theme');\n const mode = latestTheme?.includes('dark') ? 'dark' : 'light';\n const variant = latestTheme?.includes('backstage') ? 'backstage' : 'rhdh';\n const themeOptions =\n variant === 'backstage'\n ? backstage.getDefaultThemeConfig(mode)\n : rhdh.getDefaultThemeConfig(mode);\n return createTheme(themeOptions);\n }, []);\n};\n"],"names":["backstage.getDefaultThemeConfig","rhdh.getDefaultThemeConfig"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@red-hat-developer-hub/backstage-plugin-theme",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Red Hat Developer Hub Theme",
|
|
5
5
|
"main": "dist/index.esm.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -33,22 +33,22 @@
|
|
|
33
33
|
"postpack": "backstage-cli package postpack"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@backstage/core-plugin-api": "^1.10.
|
|
37
|
-
"@backstage/theme": "^0.6.
|
|
36
|
+
"@backstage/core-plugin-api": "^1.10.7",
|
|
37
|
+
"@backstage/theme": "^0.6.6",
|
|
38
38
|
"@material-ui/icons": "^4.11.3",
|
|
39
39
|
"@mui/icons-material": "^5.17.1",
|
|
40
40
|
"@mui/material": "^5.0.0",
|
|
41
41
|
"react": "^16.13.1 || ^17.0.0 || ^18.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@backstage/cli": "^0.
|
|
45
|
-
"@backstage/core-app-api": "^1.
|
|
46
|
-
"@backstage/core-components": "^0.
|
|
47
|
-
"@backstage/core-plugin-api": "^1.10.
|
|
48
|
-
"@backstage/dev-utils": "^1.1.
|
|
49
|
-
"@backstage/plugin-user-settings": "^0.8.
|
|
50
|
-
"@backstage/test-utils": "^1.7.
|
|
51
|
-
"@backstage/theme": "^0.6.
|
|
44
|
+
"@backstage/cli": "^0.32.1",
|
|
45
|
+
"@backstage/core-app-api": "^1.17.0",
|
|
46
|
+
"@backstage/core-components": "^0.17.2",
|
|
47
|
+
"@backstage/core-plugin-api": "^1.10.7",
|
|
48
|
+
"@backstage/dev-utils": "^1.1.10",
|
|
49
|
+
"@backstage/plugin-user-settings": "^0.8.22",
|
|
50
|
+
"@backstage/test-utils": "^1.7.8",
|
|
51
|
+
"@backstage/theme": "^0.6.6",
|
|
52
52
|
"@backstage/types": "^1.2.1",
|
|
53
53
|
"@material-ui/icons": "^4.11.3",
|
|
54
54
|
"@testing-library/jest-dom": "^6.0.0",
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
},
|
|
84
84
|
"typesVersions": {
|
|
85
85
|
"*": {
|
|
86
|
-
"
|
|
87
|
-
"
|
|
86
|
+
"package.json": [
|
|
87
|
+
"package.json"
|
|
88
88
|
]
|
|
89
89
|
}
|
|
90
90
|
},
|