Skip to content

Commit

Permalink
release-2021-11-18 packages/core-plugin-api/src/apis/definitions/AppT…
Browse files Browse the repository at this point in the history
…hemeApi.ts:45

Signed-off-by: Colton Padden <colton.padden@fastmail.com>
  • Loading branch information
cmpadden committed Dec 17, 2021
1 parent c24bae0 commit 5d6684f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 31 deletions.
2 changes: 0 additions & 2 deletions packages/app-defaults/src/defaults/themes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const themes: AppTheme[] = [
title: 'Light Theme',
variant: 'light',
icon: <LightIcon />,
theme: lightTheme,
Provider: ({ children }) => (
<ThemeProvider theme={lightTheme}>
<CssBaseline>{children}</CssBaseline>
Expand All @@ -40,7 +39,6 @@ export const themes: AppTheme[] = [
title: 'Dark Theme',
variant: 'dark',
icon: <DarkIcon />,
theme: darkTheme,
Provider: ({ children }) => (
<ThemeProvider theme={darkTheme}>
<CssBaseline>{children}</CssBaseline>
Expand Down
19 changes: 3 additions & 16 deletions packages/core-app-api/src/app/AppThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/

import React, { useMemo, useEffect, useState, PropsWithChildren } from 'react';
import { ThemeProvider } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import { useApi, appThemeApiRef, AppTheme } from '@backstage/core-plugin-api';
import { useObservable } from 'react-use';

Expand Down Expand Up @@ -90,20 +88,9 @@ export function AppThemeProvider({ children }: PropsWithChildren<{}>) {
throw new Error('App has no themes');
}

if (appTheme.Provider) {
return <appTheme.Provider children={children} />;
if (!appTheme.Provider) {
throw new Error('App has no theme provider');
}

// eslint-disable-next-line no-console
console.warn(
"DEPRECATION WARNING: A provided app theme is using the deprecated 'theme' property " +
'and should be migrated to use a Provider instead. ' +
'See https://backstage.io/docs/api/deprecations#app-theme for more info.',
);

return (
<ThemeProvider theme={appTheme.theme}>
<CssBaseline>{children}</CssBaseline>
</ThemeProvider>
);
return <appTheme.Provider children={children} />;
}
2 changes: 0 additions & 2 deletions packages/core-plugin-api/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
/// <reference types="react" />

import { BackstagePlugin as BackstagePlugin_2 } from '@backstage/core-plugin-api';
import { BackstageTheme } from '@backstage/theme';
import { ComponentType } from 'react';
import { Config } from '@backstage/config';
import { IconComponent as IconComponent_2 } from '@backstage/core-plugin-api';
Expand Down Expand Up @@ -164,7 +163,6 @@ export type AppTheme = {
id: string;
title: string;
variant: 'light' | 'dark';
theme: BackstageTheme;
icon?: React.ReactElement;
Provider?(props: { children: ReactNode }): JSX.Element | null;
};
Expand Down
7 changes: 0 additions & 7 deletions packages/core-plugin-api/src/apis/definitions/AppThemeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { ReactNode } from 'react';
import { ApiRef, createApiRef } from '../system';
import { BackstageTheme } from '@backstage/theme';
import { Observable } from '@backstage/types';

/**
Expand All @@ -40,12 +39,6 @@ export type AppTheme = {
*/
variant: 'light' | 'dark';

/**
* The specialized MaterialUI theme instance.
* @deprecated use Provider instead, see https://backstage.io/docs/api/deprecations#app-theme
*/
theme: BackstageTheme;

/**
* An Icon for the theme mode setting.
*/
Expand Down
3 changes: 0 additions & 3 deletions packages/dev-utils/src/devApp/SidebarThemeSwitcher.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { AppThemeApi, appThemeApiRef } from '@backstage/core-plugin-api';
import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { BackstageTheme } from '@backstage/theme';
import userEvent from '@testing-library/user-event';
import React from 'react';
import ObservableImpl from 'zen-observable';
Expand All @@ -41,13 +40,11 @@ describe('SidebarThemeSwitcher', () => {
id: 'dark',
title: 'Dark Theme',
variant: 'dark',
theme: {} as unknown as BackstageTheme,
},
{
id: 'light',
title: 'Light Theme',
variant: 'light',
theme: {} as unknown as BackstageTheme,
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
wrapInTestApp,
} from '@backstage/test-utils';
import { lightTheme } from '@backstage/theme';
import { ThemeProvider } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import { fireEvent } from '@testing-library/react';
import React from 'react';
import { UserSettingsThemeToggle } from './UserSettingsThemeToggle';
Expand All @@ -30,7 +32,11 @@ const mockTheme: AppTheme = {
id: 'light-theme',
title: 'Mock Theme',
variant: 'light',
theme: lightTheme,
Provider: ({ children }) => (
<ThemeProvider theme={lightTheme}>
<CssBaseline>{children}</CssBaseline>
</ThemeProvider>
),
};

const apiRegistry = TestApiRegistry.from([
Expand Down

0 comments on commit 5d6684f

Please sign in to comment.