From 2d365809f1c965817e2e99b92e45a59001b9a175 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 14 May 2020 16:53:03 +0200 Subject: [PATCH] packages/core: added initial AppThemeApi --- .../src/api/apis/definitions/AppThemeApi.ts | 64 +++++++++++++++++++ .../core/src/api/apis/definitions/index.ts | 1 + 2 files changed, 65 insertions(+) create mode 100644 packages/core/src/api/apis/definitions/AppThemeApi.ts diff --git a/packages/core/src/api/apis/definitions/AppThemeApi.ts b/packages/core/src/api/apis/definitions/AppThemeApi.ts new file mode 100644 index 0000000000..bddb6f1a10 --- /dev/null +++ b/packages/core/src/api/apis/definitions/AppThemeApi.ts @@ -0,0 +1,64 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ApiRef } from '../ApiRef'; +import { BackstageTheme } from '@backstage/theme'; + +/** + * Describes a theme provided by the app. + */ +export type AppTheme = { + /** + * Title of the theme + */ + title: string; + + /** + * Theme variant + */ + variant: 'light' | 'dark'; + + /** + * The specialized MaterialUI theme instance. + */ + theme: BackstageTheme; +}; + +/** + * The AppThemeApi gives access to the current app theme, and allows switching + * to other options that have been registered as a part of the App. + */ +export type AppThemeApi = { + /** + * Get a list of available themes. + */ + getThemeOptions(): AppTheme[]; + + /** + * Get the current theme. Returns undefined if the default theme is used. + */ + getTheme(): AppTheme | undefined; + + /** + * Set a specific theme to use in the app, overriding the default theme selection. + */ + setTheme(theme?: AppTheme): void; +}; + +export const appThemeApiRef = new ApiRef({ + id: 'core.apptheme', + description: 'API Used to configure the app theme, and enumerate options', +}); diff --git a/packages/core/src/api/apis/definitions/index.ts b/packages/core/src/api/apis/definitions/index.ts index 9e7f7534b9..2bb365b2ab 100644 --- a/packages/core/src/api/apis/definitions/index.ts +++ b/packages/core/src/api/apis/definitions/index.ts @@ -21,6 +21,7 @@ // If you think some API definition is missing, please open an Issue or send a PR! export * from './AlertApi'; +export * from './AppThemeApi'; export * from './ErrorApi'; export * from './FeatureFlagsApi'; export * from './OAuthRequestApi';