The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Apply unified theme object to main app and modular embedding (#68169)
Phoomparin Manod491eb6d51f6
diff --git a/.storybook/preview.tsx b/.storybook/preview.tsxindex e0e6f1f601e..5b149aa5074 100644--- a/.storybook/preview.tsx+++ b/.storybook/preview.tsx@@ -1,4 +1,5 @@-import React, { useMemo, useEffect } from "react";+import React, { useEffect, useMemo } from "react";+import { ThemeProvider } from "metabase/ui";// @ts-expect-error: See metabase/lib/delay@@ -15,10 +16,13 @@ import "@mantine/dates/styles.css";import { EmotionCacheProvider } from "metabase/styled-components/components/EmotionCacheProvider";import { getMetabaseCssVariables } from "metabase/styled-components/theme/css-variables";-import { css, Global, useTheme } from "@emotion/react";++import { Global, css, useTheme } from "@emotion/react";+import { baseStyle, rootStyle } from "metabase/css/core/base.styled";import { defaultFontFiles } from "metabase/css/core/fonts.styled";import { saveDomImageStyles } from "metabase/visualizations/lib/image-exports";+import { initialize, mswLoader } from "msw-storybook-addon";// Note: Changing the names of the stories may impact loki visual testing. Please ensure that@@ -107,7 +111,9 @@ function CssVariables() {}, []);// This can get expensive so we should memoize it separately- const cssVariables = useMemo(() => getMetabaseCssVariables(theme), [theme]);+ const cssVariables = useMemo(() => {+ return getMetabaseCssVariables({ theme });+ }, [theme]);const styles = useMemo(() => {return css`diff --git a/bin/find-never-defined-css-variables/find-never-defined-css-variables.ts b/bin/find-never-defined-css-variables/find-never-defined-css-variables.tsindex 5c2304e0671..ef4d219f7ae 100644--- a/bin/find-never-defined-css-variables/find-never-defined-css-variables.ts+++ b/bin/find-never-defined-css-variables/find-never-defined-css-variables.ts@@ -4,7 +4,7 @@ import { readFileSync } from "fs";import { glob } from "glob";-import { colorConfig } from "../../frontend/src/metabase/lib/colors/colors";+import { ALL_COLOR_NAMES } from "../../frontend/src/metabase/lib/colors";/*** This script finds css variables that are used but *never* defined in our codebase.@@ -104,7 +104,7 @@ const main = () => {allDefinitions.add(definition);}- Object.keys(colorConfig).forEach((key) => {+ ALL_COLOR_NAMES.forEach((key) => {allDefinitions.add(`--mb-color-${key}`);});diff --git a/enterprise/frontend/src/embedding-sdk-package/index.ts b/enterprise/frontend/src/embedding-sdk-package/index.tsindex 236403122b1..b86ab3caabd 100644--- a/enterprise/frontend/src/embedding-sdk-package/index.ts+++ b/enterprise/frontend/src/embedding-sdk-package/index.ts@@ -87,6 +87,7 @@ export type {export type {ButtonProps,ChartColor,+ ChartColorV2,CreateDashboardValues,EntityTypeFilterKeys,InitializationStatus,@@ -97,6 +98,7 @@ export type {MetabaseAuthConfigWithSaml,MetabaseIsGuestAuthConfig,MetabaseClickActionPluginsConfig,+ MetabaseColorKey,MetabaseColors,MetabaseClickAction,MetabaseComponentTheme,@@ -105,8 +107,12 @@ export type {MetabaseDataPointObject,MetabaseDashboard,MetabaseDashboardPluginsConfig,+ MetabaseEmbeddingColorKeyV2,+ MetabaseEmbeddingTheme,+ MetabaseEmbeddingThemeV2,MetabaseFontFamily,MetabaseGlobalPluginsConfig,+ ProtectedColorKey,MetabasePluginsConfig,MetabaseQuestion,MetabaseTheme,diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.tsxindex f47fddb33a4..9c97937a43c 100644--- a/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.tsx+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.tsx@@ -3,12 +3,10 @@ import { Global } from "@emotion/react";import { useContext, useId, useMemo } from "react";import { DEFAULT_FONT } from "embedding-sdk-bundle/config";-import { getEmbeddingThemeOverride } from "embedding-sdk-bundle/lib/theme";-import type { MetabaseTheme } from "embedding-sdk-bundle/types/ui";+import { useEmbeddingThemeOverride } from "embedding-sdk-bundle/hooks/private/use-embedding-theme-override";import { EnsureSingleInstance } from "embedding-sdk-shared/components/EnsureSingleInstance/EnsureSingleInstance";-import { applyThemePreset } from "embedding-sdk-shared/lib/apply-theme-preset";import { useSetting } from "metabase/common/hooks";-import { setGlobalEmbeddingColors } from "metabase/embedding-sdk/theme/embedding-color-palette";+import type { MetabaseEmbeddingTheme } from "metabase/embedding-sdk/theme";import { useSelector } from "metabase/lib/redux";import { getFont } from "metabase/styled-components/selectors";import { getMetabaseSdkCssVariables } from "metabase/styled-components/theme/css-variables";@@ -16,23 +14,12 @@ import { ThemeProvider, useMantineTheme } from "metabase/ui";import { ThemeProviderContext } from "metabase/ui/components/theme/ThemeProvider/context";interface Props {- theme?: MetabaseTheme;+ theme?: MetabaseEmbeddingTheme;children: React.ReactNode;}export const SdkThemeProvider = ({ theme, children }: Props) => {- const font = useSelector(getFont);- const appColors = useSetting("application-colors");-- const themeOverride = useMemo(() => {- const themeWithPreset = applyThemePreset(theme);-- // !! Mutate the global colors object to apply the new colors.- // This must be done before ThemeProvider calls getThemeOverrides.- setGlobalEmbeddingColors(themeWithPreset?.colors, appColors ?? {});-- return getEmbeddingThemeOverride(themeWithPreset || {}, font);- }, [appColors, theme, font]);+ const themeOverride = useEmbeddingThemeOverride(theme);const { withCssVariables, withGlobalClasses } =useContext(ThemeProviderContext);@@ -64,14 +51,14 @@ export const SdkThemeProvider = ({ theme, children }: Props) => {function GlobalSdkCssVariables() {const theme = useMantineTheme();+ const whitelabelColors = useSetting("application-colors");// the default is needed for when the sdk can't connect to the instance and get the default from thereconst font = useSelector(getFont) ?? DEFAULT_FONT;- const styles = useMemo(- () => getMetabaseSdkCssVariables(theme, font),- [theme, font],- );+ const styles = useMemo(() => {+ return getMetabaseSdkCssVariables({ theme, font, whitelabelColors });+ }, [theme, font, whitelabelColors]);return <Global styles={styles} />;}diff --git a/frontend/src/embedding-sdk-bundle/components/public/ComponentProvider/ComponentProvider.tsx b/frontend/src/embedding-sdk-bundle/components/public/ComponentProvider/ComponentProvider.tsxindex 93106471f42..845c5a04c28 100644--- a/frontend/src/embedding-sdk-bundle/components/public/ComponentProvider/ComponentProvider.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/ComponentProvider/ComponentProvider.tsx@@ -18,6 +18,7 @@ import type { SdkStore } from "embedding-sdk-bundle/store/types";import type { MetabaseProviderProps } from "embedding-sdk-bundle/types/metabase-provider";import { EnsureSingleInstance } from "embedding-sdk-shared/components/EnsureSingleInstance/EnsureSingleInstance";import { useInstanceLocale } from "metabase/common/hooks/use-instance-locale";+import { isEmbeddingThemeV1 } from "metabase/embedding-sdk/theme";import { MetabaseReduxProvider, useSelector } from "metabase/lib/redux";import { LocaleProvider } from "metabase/public/LocaleProvider";import { setOptions } from "metabase/redux/embed";@@ -70,7 +71,7 @@ export const ComponentProviderInternal = (} = useNormalizeComponentProviderProps(props);const isGuestEmbed = !!authConfig.isGuest;- const { fontFamily } = theme ?? {};+ const fontFamily = isEmbeddingThemeV1(theme) ? theme.fontFamily : undefined;// The main call of useInitData happens in the MetabaseProvider// This call in the ComponentProvider is still needed for:diff --git a/frontend/src/embedding-sdk-bundle/hooks/private/use-embedding-theme-override.ts b/frontend/src/embedding-sdk-bundle/hooks/private/use-embedding-theme-override.tsnew file mode 100644index 00000000000..f038cd5f8f8--- /dev/null+++ b/frontend/src/embedding-sdk-bundle/hooks/private/use-embedding-theme-override.ts@@ -0,0 +1,64 @@+import { useMemo } from "react";++import { DEFAULT_FONT } from "embedding-sdk-bundle/config";+import { getEmbeddingThemeOverride } from "embedding-sdk-bundle/lib/theme";+import { applyThemePreset } from "embedding-sdk-shared/lib/apply-theme-preset";+import { useSetting } from "metabase/common/hooks";+import {+ type MetabaseEmbeddingTheme,+ getEmbeddingComponentOverrides,+ isEmbeddingThemeV1,+ isEmbeddingThemeV2,+} from "metabase/embedding-sdk/theme";+import { setGlobalEmbeddingColors } from "metabase/embedding-sdk/theme/embedding-color-palette";+import { deriveFullMetabaseTheme } from "metabase/lib/colors";+import { useSelector } from "metabase/lib/redux";+import { getFont } from "metabase/styled-components/selectors";+import type { MantineThemeOverride } from "metabase/ui";+import { getColorShades } from "metabase/ui/utils/colors";++/**+ * Returns the Mantine theme override for modular embedding.+ */+export function useEmbeddingThemeOverride(+ theme?: MetabaseEmbeddingTheme,+): MantineThemeOverride | undefined {+ const font = useSelector(getFont);+ const appColors = useSetting("application-colors");++ return useMemo(() => {+ if (isEmbeddingThemeV1(theme)) {+ const themeWithPreset = applyThemePreset(theme);++ // !! Mutate the global colors object to apply the new colors.+ // This must be done before ThemeProvider calls getThemeOverrides.+ setGlobalEmbeddingColors(themeWithPreset?.colors, appColors ?? {});++ return getEmbeddingThemeOverride(themeWithPreset || {}, font);+ }++ // We must include Modular Embedding specific overrides for portals (e.g. popover and modal) to target the correct portal id+ const components = getEmbeddingComponentOverrides();++ if (isEmbeddingThemeV2(theme)) {+ const derivedTheme = deriveFullMetabaseTheme({+ colorScheme: "light",+ whitelabelColors: appColors ?? {},+ embeddingThemeOverride: theme,+ });++ // Convert derived colors to Mantine color tuples+ const colors = Object.fromEntries(+ Object.entries(derivedTheme.colors).map(([key, value]) => [+ key,+ getColorShades(value),+ ]),+ );++ return { colors, fontFamily: font ?? DEFAULT_FONT, components };+ }++ // No theme provided: just return the component overrides for portals+ return { components };+ }, [appColors, theme, font]);+}diff --git a/frontend/src/embedding-sdk-bundle/lib/theme/get-embedding-theme.ts b/frontend/src/embedding-sdk-bundle/lib/theme/get-embedding-theme.tsindex 5ba1305fefa..8f3aa6f6f40 100644--- a/frontend/src/embedding-sdk-bundle/lib/theme/get-embedding-theme.ts+++ b/frontend/src/embedding-sdk-bundle/lib/theme/get-embedding-theme.ts@@ -18,6 +18,8 @@ import {SDK_TO_MAIN_APP_COLORS_MAPPING,SDK_TO_MAIN_APP_TOOLTIP_COLORS_MAPPING,} from "metabase/embedding-sdk/theme/embedding-color-palette";+import type { MetabaseAccentColorKey } from "metabase/lib/colors";+import { mapChartColorsToAccents } from "metabase/lib/colors/accents";import type { MantineThemeOverride } from "metabase/ui";import { colorTuple } from "./color-tuple";@@ -101,6 +103,21 @@ export function getEmbeddingThemeOverride(}}}++ if (theme.colors.charts) {+ const accents = mapChartColorsToAccents(theme.colors.charts);++ for (const _accentKey in accents) {+ const accentKey = _accentKey as MetabaseAccentColorKey;+ const accentColor = accents[accentKey];++ if (!accentColor) {+ continue;+ }++ override.colors[accentKey] = colorTuple(accentColor);+ }+ }}if (theme.components?.tooltip) {diff --git a/frontend/src/embedding-sdk-bundle/test/storybook-themes.ts b/frontend/src/embedding-sdk-bundle/test/storybook-themes.tsindex adb924c13f0..3c52de13052 100644--- a/frontend/src/embedding-sdk-bundle/test/storybook-themes.ts+++ b/frontend/src/embedding-sdk-bundle/test/storybook-themes.ts@@ -1,7 +1,8 @@import {- type MetabaseTheme,+ type MetabaseEmbeddingTheme,defineMetabaseTheme,} from "metabase/embedding-sdk/theme";+import { METABASE_DARK_THEME } from "metabase/lib/colors/constants/themes/dark";export const darkColors = {primary: "#DF75E9",@@ -69,7 +70,7 @@ const pugColors = {negative: "#D30100",};-const pugTheme: MetabaseTheme = {+const pugTheme: MetabaseEmbeddingTheme = {// fontFamily: "DM Mono", // we don't have it in storybookfontSize: "14px",colors: {@@ -127,7 +128,7 @@ const stitchColors = {background: "#161A1D",};-const stitchTheme: MetabaseTheme = {+const stitchTheme: MetabaseEmbeddingTheme = {fontFamily: "Inter",fontSize: "14px",colors: {@@ -182,7 +183,7 @@ const luminaraColors = {viz1: "#64786A",};-const luminaraTheme: MetabaseTheme = {+const luminaraTheme: MetabaseEmbeddingTheme = {// fontFamily: "Arsenal", // we don't have it in storybookfontSize: "14px",colors: {@@ -243,7 +244,7 @@ const proficiencyColors = {negative: "rgba(234, 56, 41, 1)",};-const proficiencyTheme: MetabaseTheme = {+const proficiencyTheme: MetabaseEmbeddingTheme = {// fontFamily: "Figtree", // we don't have it in storybookfontSize: "14px",colors: {@@ -310,9 +311,13 @@ const proficiencyTheme: MetabaseTheme = {},};-export const storybookThemes: Record<string, MetabaseTheme | undefined> = {+export const storybookThemes: Record<+ string,+ MetabaseEmbeddingTheme | undefined+> = {default: undefined,dark: darkTheme,+ "dark-v2": METABASE_DARK_THEME,pug: pugTheme,stitch: stitchTheme,luminara: luminaraTheme,diff --git a/frontend/src/embedding-sdk-bundle/types/index.ts b/frontend/src/embedding-sdk-bundle/types/index.tsindex 9b791d4d11e..dffc29ba2a3 100644--- a/frontend/src/embedding-sdk-bundle/types/index.ts+++ b/frontend/src/embedding-sdk-bundle/types/index.ts@@ -5,5 +5,6 @@ export type * from "./entity";export type * from "./events";export type * from "./plugins";export type * from "./question";+export type * from "./theme";export type * from "./ui";export type * from "./user";diff --git a/frontend/src/embedding-sdk-bundle/types/metabase-provider.ts b/frontend/src/embedding-sdk-bundle/types/metabase-provider.tsindex 84ad39f5e21..ddd03b903b5 100644--- a/frontend/src/embedding-sdk-bundle/types/metabase-provider.ts+++ b/frontend/src/embedding-sdk-bundle/types/metabase-provider.ts@@ -1,6 +1,6 @@import type { ReactNode } from "react";-import type { MetabaseTheme } from "metabase/embedding-sdk/theme";+import type { MetabaseEmbeddingTheme } from "metabase/embedding-sdk/theme";import type { MetabaseAuthConfig } from "./auth-config";import type { SdkEventHandlersConfig } from "./events";@@ -32,7 +32,7 @@ export interface MetabaseProviderProps {/*** See [Appearance](https://www.metabase.com/docs/latest/embedding/sdk/appearance).*/- theme?: MetabaseTheme;+ theme?: MetabaseEmbeddingTheme;/*** See [Plugins](https://www.metabase.com/docs/latest/embedding/sdk/plugins).diff --git a/frontend/src/embedding-sdk-bundle/types/theme.ts b/frontend/src/embedding-sdk-bundle/types/theme.tsnew file mode 100644index 00000000000..676bcfe35c9--- /dev/null+++ b/frontend/src/embedding-sdk-bundle/types/theme.ts@@ -0,0 +1,11 @@+export type {+ MetabaseEmbeddingColorKeyV2,+ MetabaseEmbeddingTheme,+ MetabaseEmbeddingThemeV2,+} from "metabase/embedding-sdk/theme";++export type {+ ChartColorV2,+ MetabaseColorKey,+ ProtectedColorKey,+} from "metabase/lib/colors";diff --git a/frontend/src/embedding-sdk-shared/lib/apply-theme-preset.ts b/frontend/src/embedding-sdk-shared/lib/apply-theme-preset.tsindex 77c48f9c70d..d66f038735d 100644--- a/frontend/src/embedding-sdk-shared/lib/apply-theme-preset.ts+++ b/frontend/src/embedding-sdk-shared/lib/apply-theme-preset.ts@@ -7,8 +7,7 @@ import {type MappableSdkColor,SDK_TO_MAIN_APP_COLORS_MAPPING,} from "metabase/embedding-sdk/theme/embedding-color-palette";-import { getColors, getDarkColors } from "metabase/lib/colors/colors";-import type { ColorPalette } from "metabase/lib/colors/types";+import { deriveFullMetabaseTheme } from "metabase/lib/colors";const PRESET_SDK_COLORS: MappableSdkColor[] = ["background",@@ -23,22 +22,17 @@ const PRESET_SDK_COLORS: MappableSdkColor[] = ["brand-hover-light",];-const COLOR_GETTERS: Record<MetabaseThemePreset, () => ColorPalette> = {- light: getColors,- dark: getDarkColors,-};-const getPresetColors = (preset: MetabaseThemePreset): MetabaseColors => {- const palette = COLOR_GETTERS[preset]?.();-- if (!palette) {+ if (preset !== "light" && preset !== "dark") {return {};}+ const { colors } = deriveFullMetabaseTheme({ colorScheme: preset });+return Object.fromEntries(PRESET_SDK_COLORS.map((sdkColor) => {const mainAppColor = SDK_TO_MAIN_APP_COLORS_MAPPING[sdkColor][0];- return [sdkColor, palette[mainAppColor]];+ return [sdkColor, colors[mainAppColor]];}),);};diff --git a/frontend/src/metabase/.eslintrc.js b/frontend/src/metabase/.eslintrc.jsindex 207413bd8e0..d568186795a 100644--- a/frontend/src/metabase/.eslintrc.js+++ b/frontend/src/metabase/.eslintrc.js@@ -52,6 +52,12 @@ const baseRestrictedConfig = {message:"Please use `testing-library/react` or `@testing-library/user-event`",},+ {+ name: "metabase/lib/colors/constants/base-colors",+ importNames: ["getBaseColorsForThemeDefinitionOnly"],+ message:+ "getBaseColorsForThemeDefinitionOnly is only for use within lib/colors. Use theme colors from 'metabase/lib/colors' instead.",+ },],};diff --git a/frontend/src/metabase/common/hooks/use-palette.ts b/frontend/src/metabase/common/hooks/use-palette.tsindex c7531fa4416..80e6bfeee7c 100644--- a/frontend/src/metabase/common/hooks/use-palette.ts+++ b/frontend/src/metabase/common/hooks/use-palette.ts@@ -1,8 +1,8 @@import { useMemo } from "react";+import { ALL_COLOR_NAMES } from "metabase/lib/colors";import type { ColorPalette } from "metabase/lib/colors/types";import { useMantineTheme } from "metabase/ui";-import { ALL_COLOR_NAMES } from "metabase/ui/utils/colors";/*** Allows palettes to be overridden by the user, primarily via the React embedding SDK.diff --git a/frontend/src/metabase/embedding-sdk/theme/MetabaseThemeV2.ts b/frontend/src/metabase/embedding-sdk/theme/MetabaseThemeV2.tsnew file mode 100644index 00000000000..bb8d3dda308--- /dev/null+++ b/frontend/src/metabase/embedding-sdk/theme/MetabaseThemeV2.ts@@ -0,0 +1,36 @@+import type {+ ChartColorV2,+ MetabaseColorKey,+ ProtectedColorKey,+} from "metabase/lib/colors";++/**+ * Color keys available for theming in modular embedding.+ *+ * Excludes protected colors such as admin colors that should not be exposed.+ *+ * @inline+ */+export type MetabaseEmbeddingColorKeyV2 = Exclude<+ MetabaseColorKey,+ ProtectedColorKey+>;++/**+ * Version 2 theme configuration for embedded Metabase components.+ *+ * @category Theming+ */+export interface MetabaseEmbeddingThemeV2 {+ /** Theme version must be 2 for version 2 themes. */+ version: 2;++ /** Color overrides. */+ colors?: Partial<Record<MetabaseEmbeddingColorKeyV2, string>>;++ /**+ * Chart colors overrides.+ * Each color can be a string or an object with base/tint/shade.+ */+ chartColors?: ChartColorV2[];+}diff --git a/frontend/src/metabase/embedding-sdk/theme/embedding-color-palette.ts b/frontend/src/metabase/embedding-sdk/theme/embedding-color-palette.tsindex 858df35cd60..c391effb879 100644--- a/frontend/src/metabase/embedding-sdk/theme/embedding-color-palette.ts+++ b/frontend/src/metabase/embedding-sdk/theme/embedding-color-palette.ts@@ -3,11 +3,10 @@ import type {MetabaseColors,MetabaseComponentTheme,} from "metabase/embedding-sdk/theme";-import { colorConfig, colors } from "metabase/lib/colors";+import { colors } from "metabase/lib/colors";+import { mapChartColorsToAccents } from "metabase/lib/colors/accents";import type { ColorName, ColorPalette } from "metabase/lib/colors/types";-import { getEmbeddingChartColors } from "./get-embedding-chart-colors";-/*** Define SDK colors that can be mapped 1:1 to the main app colors.*@@ -102,7 +101,7 @@ export function getEmbeddingColorPalette();const chartColors =- sdkColors.charts && getEmbeddingChartColors(sdkColors.charts);+ sdkColors.charts && mapChartColorsToAccents(sdkColors.charts);return {...originalColors,@@ -128,12 +127,6 @@ export function setGlobalEmbeddingColors(colors[key as ColorName] = value;});- // Also set overrides on the color config, this way when we- // set up the mantine theme colors, we will grab appropriate app palette colors as well 🥺- Object.entries(combinedThemeColors).forEach(([key, value]) => {- colorConfig[key as ColorName] = { light: value, dark: value };- });-/*** (EMB-696)* Reset colors set previously that's now not passed in `sdkColors`.diff --git a/frontend/src/metabase/embedding-sdk/theme/get-embedding-chart-colors.ts b/frontend/src/metabase/embedding-sdk/theme/get-embedding-chart-colors.tsdeleted file mode 100644index 6ac4a2f0eed..00000000000--- a/frontend/src/metabase/embedding-sdk/theme/get-embedding-chart-colors.ts+++ /dev/null@@ -1,40 +0,0 @@-import type { ChartColor } from "metabase/embedding-sdk/theme";--/**- * Map the input chart colors from the theme settings to the- * color names we use in our charts.- *- * @param chartColors chart colors defined in embedding theme settings- */-export function getEmbeddingChartColors(- chartColors: ChartColor[],-): Record<string, string> {- const mappedColors: Record<string, string> = {};-- // Populate the 8 chart colors, including the shades and tints when available.- // When shades or tints are not explicitly defined, they're derived by `libs/colors/palette`.- chartColors.slice(0, 8).forEach((color, index) => {- if (!color) {- return;- }-- if (typeof color === "string") {- mappedColors[`accent${index}`] = color;- return;- }-- if (typeof color === "object") {- mappedColors[`accent${index}`] = color.base;-- if (color.shade) {- mappedColors[`accent${index}-dark`] = color.shade;- }-- if (color.tint) {- mappedColors[`accent${index}-light`] = color.tint;- }- }- });-- return mappedColors;-}diff --git a/frontend/src/metabase/embedding-sdk/theme/index.ts b/frontend/src/metabase/embedding-sdk/theme/index.tsindex 987f609a0ee..6279295aefa 100644--- a/frontend/src/metabase/embedding-sdk/theme/index.ts+++ b/frontend/src/metabase/embedding-sdk/theme/index.ts@@ -1,4 +1,6 @@export * from "./default-component-theme";export * from "./MetabaseTheme";+export * from "./MetabaseThemeV2";+export * from "./theme-version";export * from "./define-metabase-theme";diff --git a/frontend/src/metabase/embedding-sdk/theme/theme-version.ts b/frontend/src/metabase/embedding-sdk/theme/theme-version.tsnew file mode 100644index 00000000000..8bbaf5c7e71--- /dev/null+++ b/frontend/src/metabase/embedding-sdk/theme/theme-version.ts@@ -0,0 +1,21 @@+import type { MetabaseTheme } from "./MetabaseTheme";+import type { MetabaseEmbeddingThemeV2 } from "./MetabaseThemeV2";++/**+ * Theme configuration for embedded Metabase components.+ *+ * @category Theming+ */+export type MetabaseEmbeddingTheme = MetabaseTheme | MetabaseEmbeddingThemeV2;++export function isEmbeddingThemeV2(+ theme: MetabaseEmbeddingTheme | undefined,+): theme is MetabaseEmbeddingThemeV2 {+ return theme !== undefined && "version" in theme && theme.version === 2;+}++export function isEmbeddingThemeV1(+ theme: MetabaseEmbeddingTheme | undefined,+): theme is MetabaseTheme {+ return theme !== undefined && !isEmbeddingThemeV2(theme);+}diff --git a/frontend/src/metabase/lib/colors/accents.ts b/frontend/src/metabase/lib/colors/accents.tsnew file mode 100644index 00000000000..0716a7273e2--- /dev/null+++ b/frontend/src/metabase/lib/colors/accents.ts@@ -0,0 +1,80 @@+import Color from "color";++import {+ ACCENT_COLOR_NAMES_MAP,+ CHART_TINT_SHADE_FACTOR,+} from "./constants/accents";+import type { ChartColorV2 } from "./types";+import type { MetabaseAccentColorKey } from "./types/color-keys";++/**+ * Transforms chartColors array into accent0 - accent7.+ * This makes defining chart colors a little bit nicer.+ *+ * Each chart color can be:+ * - A string: maps to accent{index}, and derives accent{index}-light and accent{index}-dark+ * - An object with base/tint/shade: maps to accent{index}, accent{index}-light, accent{index}-dark+ *+ * When tints or shades are not provided they will be derived from the base color.+ */+export function mapChartColorsToAccents(+ chartColors: ChartColorV2[],+): Partial<Record<MetabaseAccentColorKey, string>> {+ const mappedColors: Partial<Record<MetabaseAccentColorKey, string>> = {};++ chartColors.slice(0, 9).forEach((color, index) => {+ if (!color) {+ return;+ }++ const accentKeys = ACCENT_COLOR_NAMES_MAP[index];++ if (typeof color === "string") {+ mappedColors[accentKeys.base] = color;++ // Derive tint and shade when only base color is provided.+ // Previously, we relied on the color aliases in `lib/colors/palette.ts`,+ // but this color is defined directly in Mantine now.+ mappedColors[accentKeys.tint] = deriveChartTintColor(color);+ mappedColors[accentKeys.shade] = deriveChartShadeColor(color);++ return;+ }++ if (typeof color === "object") {+ mappedColors[accentKeys.base] = color.base;++ // Use provided tint/shade or derive from base+ mappedColors[accentKeys.tint] =+ color.tint ?? deriveChartTintColor(color.base);+ mappedColors[accentKeys.shade] =+ color.shade ?? deriveChartShadeColor(color.base);+ }+ });++ return mappedColors;+}++/**+ * Derives a tint (lighter) variant of a color.+ * Matches the alias logic in palette.ts tint().+ */+export function deriveChartTintColor(hexColor: string): string {+ const value = Color(hexColor);++ return value+ .lightness(value.lightness() + CHART_TINT_SHADE_FACTOR * 100)+ .hex();+}++/**+ * Derives a shade (darker) variant of a color.+ * Matches the alias logic in palette.ts shade().+ */+export function deriveChartShadeColor(hexColor: string): string {+ const value = Color(hexColor);++ return value+ .lightness(value.lightness() - CHART_TINT_SHADE_FACTOR * 100)+ .hex();+}diff --git a/frontend/src/metabase/lib/colors/accents.unit.spec.ts b/frontend/src/metabase/lib/colors/accents.unit.spec.tsnew file mode 100644index 00000000000..4e12ed2a883--- /dev/null+++ b/frontend/src/metabase/lib/colors/accents.unit.spec.ts@@ -0,0 +1,104 @@+import {+ deriveChartShadeColor,+ deriveChartTintColor,+ mapChartColorsToAccents,+} from "./accents";++describe("mapChartColorsToAccents", () => {+ it("maps string colors to accent keys with derived tint and shade", () => {+ const result = mapChartColorsToAccents(["#FF0000", "#00FF00", "#0000FF"]);++ expect(result).toEqual({+ accent0: "#FF0000",+ "accent0-light": deriveChartTintColor("#FF0000"),+ "accent0-dark": deriveChartShadeColor("#FF0000"),+ accent1: "#00FF00",+ "accent1-light": deriveChartTintColor("#00FF00"),+ "accent1-dark": deriveChartShadeColor("#00FF00"),+ accent2: "#0000FF",+ "accent2-light": deriveChartTintColor("#0000FF"),+ "accent2-dark": deriveChartShadeColor("#0000FF"),+ });+ });++ it("maps object colors with explicit base, tint and shade", () => {+ const result = mapChartColorsToAccents([+ { base: "#FF0000", tint: "#FF8888", shade: "#880000" },+ ]);++ expect(result).toEqual({+ accent0: "#FF0000",+ "accent0-light": "#FF8888",+ "accent0-dark": "#880000",+ });+ });++ it("derives missing tint/shade when object only has base", () => {+ const result = mapChartColorsToAccents([{ base: "#FF0000" }]);++ expect(result).toEqual({+ accent0: "#FF0000",+ "accent0-light": deriveChartTintColor("#FF0000"),+ "accent0-dark": deriveChartShadeColor("#FF0000"),+ });+ });++ it("handles mixed string and object color formats", () => {+ const result = mapChartColorsToAccents([+ "#FF0000",+ { base: "#00FF00", tint: "#88FF88", shade: "#008800" },+ ]);++ expect(result).toEqual({+ accent0: "#FF0000",+ "accent0-light": deriveChartTintColor("#FF0000"),+ "accent0-dark": deriveChartShadeColor("#FF0000"),+ accent1: "#00FF00",+ "accent1-light": "#88FF88",+ "accent1-dark": "#008800",+ });+ });++ it("only maps the first 9 colors (8 + grey)", () => {+ const manyColors = Array.from({ length: 12 }, () => "#FF0000");+ const result = mapChartColorsToAccents(manyColors);++ // 9 base + 9 tint + 9 shade = 27 keys+ expect(Object.keys(result)).toHaveLength(27);++ // accent8 should not exist+ expect(result).not.toHaveProperty("accent8");+ expect(result).not.toHaveProperty("accent8-light");++ // gray should exist+ expect(result).toHaveProperty("accent-gray");+ expect(result).toHaveProperty("accent-gray-light");+ });++ it("skips all variants if color at index is null", () => {+ const result = mapChartColorsToAccents(["#FF0000", null, "#0000FF"]);++ expect(result).toEqual({+ accent0: "#FF0000",+ "accent0-light": deriveChartTintColor("#FF0000"),+ "accent0-dark": deriveChartShadeColor("#FF0000"),+ accent2: "#0000FF",+ "accent2-light": deriveChartTintColor("#0000FF"),+ "accent2-dark": deriveChartShadeColor("#0000FF"),+ });+ });+});++describe("deriveChartTintColor", () => {+ it("derives a lighter variant of the color", () => {+ // Default accent0 blue (#509EE3) should become lighter+ expect(deriveChartTintColor("#509EE3")).toBe("#87BCEC");+ });+});++describe("deriveChartShadeColor", () => {+ it("derives a darker variant of the color", () => {+ // Default accent0 blue (#509EE3) should become darker+ expect(deriveChartShadeColor("#509EE3")).toBe("#227FD2");+ });+});diff --git a/frontend/src/metabase/lib/colors/colors.ts b/frontend/src/metabase/lib/colors/colors.tsindex 3842edc1085..61c1875e508 100644--- a/frontend/src/metabase/lib/colors/colors.ts+++ b/frontend/src/metabase/lib/colors/colors.ts@@ -1,619 +1,31 @@-/* eslint-disable no-color-literals */// NOTE: DO NOT ADD COLORS WITHOUT EXTREMELY GOOD REASON AND DESIGN REVIEWimport type { ColorSettings } from "metabase-types/api/settings";+import { getBaseColorsForThemeDefinitionOnly } from "./constants/base-colors";+import { deriveFullMetabaseTheme } from "./derive-theme";+import type { MetabaseColorKey } from "./types/color-keys";+const win = typeof window !== "undefined" ? window : ({} as Window);const tokenFeatures = win.MetabaseBootstrap?.["token-features"] ?? {};const shouldWhitelabel = !!tokenFeatures["whitelabel"];const whitelabelColors =(shouldWhitelabel && win.MetabaseBootstrap?.["application-colors"]) || {};-// Do not export this or you will be fired-const baseColors = {- white: "hsla(0, 0%, 100%, 1.00)",- black: "hsla(0, 0%, 0%, 1.00)",-- // Brand colors (dynamic based on --mb-color-brand). Expanded to roughly match the values in the new color palette (but these should be reworked).- brand: {- 100: "color-mix(in srgb, var(--mb-color-brand), black 86%)",- 90: "color-mix(in srgb, var(--mb-color-brand), black 75%)",- 80: "color-mix(in srgb, var(--mb-color-brand), black 62%)",- 70: "color-mix(in srgb, var(--mb-color-brand), black 47%)",- 60: "color-mix(in srgb, var(--mb-color-brand), black 28%)",- 50: "color-mix(in srgb, var(--mb-color-brand), black 12%)",- 40: "var(--mb-color-brand)", // This is the base brand color- 30: "color-mix(in srgb, var(--mb-color-brand), white 35%)",- 20: "color-mix(in srgb, var(--mb-color-brand), white 70%)",- 10: "color-mix(in srgb, var(--mb-color-brand), white 91%)",- 5: "color-mix(in srgb, var(--mb-color-brand), white 96%)",- },-- // Deprecated Blue- blue: {- 100: "hsla(208, 100%, 8%, 1.00)",- 90: "hsla(208, 89%, 14%, 1.00)",- 80: "hsla(208, 82%, 22%, 1.00)",- 70: "hsla(208, 80%, 31%, 1.00)",- 60: "hsla(208, 78%, 42%, 1.00)",- 50: "hsla(208, 68%, 53%, 1.00)",- 40: "hsla(208, 72%, 60%, 1.00)", // brand- 30: "hsla(208, 73%, 74%, 1.00)",- 20: "hsla(209, 73%, 88%, 1.00)", // focus- 10: "hsla(208, 79%, 96%, 1.00)", // baby blue- 5: "hsla(210, 75%, 98%, 1.00)",- },-- // Deprecated Gray- gray: {- 100: "hsla(206, 16%, 8%, 1.00)", // background-primary-inverse- 90: "hsla(202, 15%, 15%, 1.00)",- 80: "hsla(205, 15%, 23%, 1.00)",- 70: "hsla(206, 14%, 32%, 1.00)",- 60: "hsla(207, 9%, 44%, 1.00)",- 50: "hsla(208, 7%, 54%, 1.00)",- 40: "hsla(208, 7%, 60%, 1.00)",- 30: "hsla(208, 11%, 74%, 1.00)",- 20: "hsla(210, 13%, 88%, 1.00)",- 10: "hsla(210, 20%, 96%, 1.00)",- 5: "hsla(210, 25%, 98%, 1.00)",- },-- // Ocean- ocean: {- 100: "hsla(208, 100%, 9%, 1)",- 90: "hsla(208, 89%, 15%, 1)",- 80: "hsla(208, 82%, 22%, 1)",- 70: "hsla(208, 80%, 31%, 1)",- 60: "hsla(208, 78%, 42%, 1)",- 50: "hsla(208, 68%, 53%, 1)",- 40: "hsla(208, 72%, 60%, 1)",- 30: "hsla(208, 73%, 74%, 1)",- 20: "hsla(209, 73%, 88%, 1)",- 10: "hsla(208, 79%, 96%, 1)",- 5: "hsla(208, 75%, 98%, 1)",- },-- // Orion- orion: {- 110: "hsla(205, 63%, 5%, 1)",- 100: "hsla(204, 66%, 8%, 1)",- 90: "hsla(204, 34%, 14%, 1)",- 80: "hsla(205, 19%, 23%, 1)",- 70: "hsla(204, 12%, 32%, 1)",- 60: "hsla(205, 8%, 43%, 1)",- 50: "hsla(203, 5%, 53%, 1)",- 40: "hsla(205, 6%, 60%, 1)",- 30: "hsla(203, 6%, 73%, 1)",- 20: "hsla(195, 6%, 87%, 1)",- 10: "hsla(240, 4%, 95%, 1)",- 5: "hsla(240, 11%, 98%, 1)",- },-- // Orion Alpha- orionAlpha: {- 100: "hsla(204, 68%, 8%, 1)",- 90: "hsla(204, 66%, 8%, 0.93)",- 80: "hsla(204, 66%, 8%, 0.84)",- 70: "hsla(204, 66%, 8%, 0.74)",- 60: "hsla(204, 66%, 8%, 0.62)",- 50: "hsla(204, 66%, 8%, 0.51)",- 40: "hsla(204, 66%, 8%, 0.44)",- 30: "hsla(204, 66%, 8%, 0.29)",- 20: "hsla(204, 66%, 8%, 0.17)",- 10: "hsla(204, 66%, 8%, 0.05)",- 5: "hsla(204, 66%, 8%, 0.02)",- },-- // Ocean Alpha. These are not in use yet because of whitelabeling- oceanAlpha: {- 50: "hsla(208, 95%, 42%, 0.82)",- 40: "hsla(208, 95%, 42%, 0.69)",- 30: "hsla(208, 95%, 42%, 0.45)",- 20: "hsla(208, 95%, 42%, 0.21)",- 10: "hsla(208, 95%, 42%, 0.07)",- 5: "hsla(208, 95%, 42%, 0.03)",- },-- orionAlphaInverse: {- 100: "hsla(0, 0%, 100%, 1.00)",- 90: "hsla(0, 0%, 100%, 0.98)",- 80: "hsla(0, 0%, 100%, 0.95)",- 70: "hsla(0, 0%, 100%, 0.85)",- 60: "hsla(0, 0%, 100%, 0.69)",- 50: "hsla(0, 0%, 100%, 0.53)",- 40: "hsla(0, 0%, 100%, 0.46)",- 30: "hsla(0, 0%, 100%, 0.33)",- 20: "hsla(0, 0%, 100%, 0.21)",- 10: "hsla(0, 0%, 100%, 0.10)",- 5: "hsla(0, 0%, 100%, .01)",- },-- // Lobster- lobster: {- 100: "hsla(0, 81%, 11%, 1)",- 90: "hsla(1, 75%, 17%, 1)",- 80: "hsla(1, 71%, 26%, 1)",- 70: "hsla(1, 69%, 37%, 1)",- 60: "hsla(1, 67%, 49%, 1)",- 50: "hsla(358, 71%, 62%, 1)",- 40: "hsla(1, 84%, 69%, 1)",- 30: "hsla(1, 85%, 81%, 1)",- 20: "hsla(2, 67%, 90%, 1)",- 10: "hsla(0, 76%, 97%, 1)",- 5: "hsla(0, 100%, 99%, 1)",- },-- // Flamingo- flamingo: {- 100: "hsla(334, 75%, 10%, 1)",- 90: "hsla(334, 79%, 17%, 1)",- 80: "hsla(334, 72%, 26%, 1)",- 70: "hsla(334, 71%, 36%, 1)",- 60: "hsla(334, 69%, 48%, 1)",- 50: "hsla(334, 67%, 60%, 1)",- 40: "hsla(334, 80%, 68%, 1)",- 30: "hsla(334, 79%, 80%, 1)",- 20: "hsla(335, 79%, 91%, 1)",- 10: "hsla(335, 67%, 96%, 1)",- 5: "hsla(330, 67%, 99%, 1)",- },-- // Mango- mango: {- 100: "hsla(26, 89%, 7%, 1)",- 90: "hsla(26, 79%, 13%, 1)",- 80: "hsla(25, 73%, 20%, 1)",- 70: "hsla(26, 70%, 29%, 1)",- 60: "hsla(26, 69%, 39%, 1)",- 50: "hsla(26, 68%, 48%, 1)",- 40: "hsla(26, 79%, 54%, 1)",- 30: "hsla(26, 84%, 70%, 1)",- 20: "hsla(26, 88%, 87%, 1)",- 10: "hsla(25, 100%, 95%, 1)",- 5: "hsla(30, 100%, 98%, 1)",- },-- // Dubloon- dubloon: {- 100: "hsla(45, 100%, 5%, 1)",- 90: "hsla(46, 88%, 10%, 1)",- 80: "hsla(46, 82%, 15%, 1)",- 70: "hsla(46, 79%, 22%, 1)",- 60: "hsla(46, 76%, 30%, 1)",- 50: "hsla(46, 76%, 37%, 1)",- 40: "hsla(46, 75%, 44%, 1)",- 30: "hsla(46, 81%, 52%, 1)",- 20: "hsla(46, 94%, 74%, 1)",- 10: "hsla(46, 96%, 90%, 1)",- 5: "hsla(45, 100%, 96%, 1)",- },-- // Palm- palm: {- 100: "hsla(94, 85%, 5%, 1)",- 90: "hsla(92, 62%, 10%, 1)",- 80: "hsla(89, 54%, 16%, 1)",- 70: "hsla(89, 50%, 24%, 1)",- 60: "hsla(89, 48%, 32%, 1)",- 50: "hsla(89, 48%, 40%, 1)",- 40: "hsla(89, 47%, 45%, 1)",- 30: "hsla(90, 47%, 60%, 1)",- 20: "hsla(91, 51%, 81%, 1)",- 10: "hsla(92, 65%, 92%, 1)",- 5: "hsla(93, 73%, 97%, 1)",- },-- // Seafoam- seafoam: {- 100: "hsla(180, 84%, 5%, 1)",- 90: "hsla(180, 34%, 12%, 1)",- 80: "hsla(180, 80%, 14%, 1)",- 70: "hsla(180, 70%, 21%, 1)",- 60: "hsla(180, 44%, 33%, 1)",- 50: "hsla(180, 74%, 34%, 1)",- 40: "hsla(180, 42%, 46%, 1)",- 30: "hsla(180, 47%, 60%, 1)",- 20: "hsla(180, 55%, 81%, 1)",- 10: "hsla(180, 68%, 93%, 1)",- 5: "hsla(180, 69%, 97%, 1)",- },-- // Octopus- octopus: {- 100: "hsla(240, 7%, 9%, 1)",- 90: "hsla(240, 7%, 9%, 1)",- 80: "hsla(240, 43%, 33%, 1)",- 70: "hsla(240, 40%, 46%, 1)",- 60: "hsla(240, 46%, 58%, 1)",- 50: "hsla(240, 65%, 69%, 1)",- 40: "hsla(240, 69%, 74%, 1)",- 30: "hsla(240, 49%, 81%, 1)",- 20: "hsla(240, 66%, 92%, 1)",- 10: "hsla(240, 100%, 97%, 1)",- 5: "hsla(240, 100%, 99%, 1)",- },-};--const getColorConfig = (settings: ColorSettings = {}) => ({- "accent-gray-dark": {- light: baseColors.orion[20],- dark: baseColors.orion[110],- },- "accent-gray-light": {- light: baseColors.orion[5],- dark: baseColors.orion[80],- },- "accent-gray": { light: baseColors.orion[10], dark: baseColors.orion[80] },- "admin-navbar": {- light: baseColors.octopus[60],- dark: baseColors.octopus[80],- },- "admin-navbar-secondary": {- light: baseColors.octopus[40],- dark: baseColors.octopus[60],- },- "admin-navbar-inverse": {- light: baseColors.octopus[80],- dark: baseColors.octopus[60],- },- "background-brand": {- light: baseColors.brand[10],- dark: baseColors.brand[90],- },- "background-disabled": {- light: baseColors.orionAlpha[10],- dark: baseColors.orionAlphaInverse[10],- },- "background-disabled-inverse": {- light: baseColors.orionAlphaInverse[10],- dark: baseColors.orionAlpha[10],- },- "background-error-secondary": {- light: baseColors.lobster[5],- dark: baseColors.lobster[90],- },- "background-hover": {- light: `color-mix(in srgb, var(--mb-color-brand) 21%, transparent)`, //baseColors.oceanAlpha[20],- dark: `color-mix(in srgb, var(--mb-color-brand) 21%, transparent)`, //baseColors.oceanAlpha[20],- },- "background-hover-light": {- light: `color-mix(in srgb, var(--mb-color-brand) 7%, transparent)`, //baseColors.oceanAlpha[10],- dark: `color-mix(in srgb, var(--mb-color-brand) 7%, transparent)`, //baseColors.oceanAlpha[10],- },-- "background-selected": {- light: baseColors.brand[50],- dark: baseColors.brand[40],- },- "background-primary": {- light: baseColors.white,- dark: baseColors.orion[100],- },- "background-secondary": {- light: baseColors.orion[5],- dark: baseColors.orion[110],- },- "background-tertiary": {- light: baseColors.orion[10],- dark: baseColors.orion[80],- },- "background-primary-inverse": {- light: baseColors.orion[80],- dark: baseColors.orion[20],- },- "background-secondary-inverse": {- light: baseColors.orion[70],- dark: baseColors.orion[30],- }, // Only used one place- "background-tertiary-inverse": {- light: baseColors.orion[40],- dark: baseColors.orion[70],- },- overlay: {- light: baseColors.orionAlpha[60],- dark: baseColors.orionAlpha[70],- },- "bg-ocean-alpha-light": {- light: baseColors.oceanAlpha[5],- dark: baseColors.oceanAlpha[20],- },- "background-error": {- light: baseColors.lobster[10],- dark: baseColors.lobster[90],- },- "background-success": {- light: baseColors.palm[5],- dark: baseColors.palm[90],- },- "brand-alpha-04": {- //all of these colors derived from brand should be reworked to fit the values in the new color palette, and to have semantic names- light: `color-mix(in srgb, var(--mb-color-brand) 4%, transparent)`,- dark: `color-mix(in srgb, var(--mb-color-brand) 4%, transparent)`,- },- "brand-alpha-88": {- light: `color-mix(in srgb, var(--mb-color-brand) 88%, transparent)`,- dark: `color-mix(in srgb, var(--mb-color-brand) 88%, transparent)`,- },- "brand-dark": {- light: baseColors.brand[60],- dark: baseColors.brand[30],- },- "brand-darker": {- light: baseColors.brand[70],- dark: baseColors.brand[20],- },- "brand-light": {- light: baseColors.brand[10],- dark: baseColors.brand[80],- },- "brand-lighter": {- light: baseColors.brand[5],- dark: baseColors.brand[90],- },- brand: {- light: settings.brand || baseColors.blue[40],- dark: settings.brand || baseColors.blue[40],- },- danger: {- light: baseColors.lobster[50],- dark: baseColors.lobster[50],- },- error: {- light: baseColors.lobster[50],- dark: baseColors.lobster[50],- },- filter: {- light: settings.filter || baseColors.octopus[50],- dark: settings.filter || baseColors.octopus[40],- },- focus: {- light: baseColors.blue[20],- dark: baseColors.blue[70],- },- "icon-primary": {- light: baseColors.brand[40],- dark: baseColors.brand[40],- },- "icon-disabled": {- light: baseColors.orionAlpha[30],- dark: baseColors.orionAlphaInverse[30],- },- "icon-secondary": {- light: baseColors.orionAlpha[50],- dark: baseColors.orionAlphaInverse[50],- },- "metabase-brand": {- light: baseColors.blue[40], // not for whitelabeling- dark: baseColors.blue[40], // not for whitelabeling- },- "saturated-blue": {- light: baseColors.ocean[60],- dark: baseColors.ocean[40],- },- "saturated-green": {- light: baseColors.palm[60],- dark: baseColors.palm[40],- },- "saturated-purple": {- light: baseColors.octopus[60],- dark: baseColors.octopus[40],- },- "saturated-red": {- light: baseColors.lobster[60],- dark: baseColors.lobster[40],- },- "saturated-yellow": {- light: baseColors.dubloon[30],- dark: baseColors.dubloon[30],- },- shadow: {- light: baseColors.orionAlpha[20],- dark: `color-mix(in srgb, ${baseColors.orion[110]} 20%, transparent)`,- },- "success-secondary": {- light: baseColors.palm[60],- dark: baseColors.palm[40],- },- success: {- light: baseColors.palm[50],- dark: baseColors.palm[50],- },- summarize: {- light: settings.summarize || baseColors.palm[50],- dark: settings.summarize || baseColors.palm[40],- },- "switch-off": {- light: baseColors.orionAlpha[20],- dark: baseColors.orionAlphaInverse[20],- },- "syntax-parameters-active": {- light: baseColors.mango[10],- dark: baseColors.mango[90],- },- "syntax-parameters": {- light: baseColors.mango[60],- dark: baseColors.mango[40],- },- "text-brand": {- light: baseColors.brand[50],- dark: baseColors.brand[40],- },- "text-tertiary": {- light: baseColors.orionAlpha[40],- dark: baseColors.orionAlphaInverse[40],- },- "text-tertiary-inverse": {- light: baseColors.orionAlphaInverse[40],- dark: baseColors.orionAlpha[40],- },- "text-hover": {- light: baseColors.brand[60],- dark: baseColors.brand[30], //CHANGED DOWN TO HERE- },-- //Used in gauge viz... there should be a better way to do this- "text-secondary-opaque": {- light: baseColors.orion[60],- dark: baseColors.orion[20],- },- "text-primary": {- light: baseColors.orionAlpha[80],- dark: baseColors.orionAlphaInverse[80],- },- "text-primary-inverse": {- light: baseColors.orionAlphaInverse[80],- dark: baseColors.orionAlpha[80],- },- "text-secondary": {- light: baseColors.orionAlpha[60],- dark: baseColors.orionAlphaInverse[60],- },- "text-secondary-inverse": {- light: baseColors.orionAlphaInverse[60],- dark: baseColors.orionAlpha[60],- },- "text-selected": {- light: baseColors.white,- dark: baseColors.white,- },- "tooltip-background-focused": {- light: `color-mix(in srgb, ${baseColors.orion[80]} 50%, #000)`,- dark: `color-mix(in srgb, ${baseColors.orion[70]} 50%, #000)`,- },- "tooltip-background": {- light: baseColors.orion[80], // references mb-color-background-primary-inverse- dark: baseColors.orion[70], // references mb-color-background-primary-inverse- },- "tooltip-text-secondary": {- //should be text-secondary-inverse- light: baseColors.orionAlphaInverse[60],- dark: baseColors.orionAlphaInverse[60],- },- "tooltip-text": {- light: baseColors.white,- dark: baseColors.orionAlphaInverse[80],- },- warning: {- light: baseColors.dubloon[30],- dark: baseColors.dubloon[30],- },-- "background-warning": {- light: baseColors.dubloon[5],- dark: baseColors.dubloon[90],- },-- info: {- light: baseColors.orion[40],- dark: baseColors.orion[50],- },-- "background-info": {- light: baseColors.orion[10],- dark: baseColors.orion[90],- },-- white: {- //should be changed to be semantic- light: baseColors.white,- dark: baseColors.orion[110],- },- // Legacy colors (keeping existing ones for backward compatibility)- accent0: {- light: "#509EE3",- dark: "#509EE3",- },- accent1: {- light: "#88BF4D",- dark: "#88BF4D",- },- accent2: {- light: "#A989C5",- dark: "#A989C5",- },- accent3: {- light: "#EF8C8C",- dark: "#EF8C8C",- },- accent4: {- light: "#F9D45C",- dark: "#F9D45C",- },- accent5: {- light: "#F2A86F",- dark: "#F2A86F",- },- accent6: {- light: "#98D9D9",- dark: "#98D9D9",- },- accent7: {- light: "#7172AD",- dark: "#7172AD",- },-- border: {- light: baseColors.orion[20],- dark: baseColors.orionAlphaInverse[20],- },- "border-strong": {- light: baseColors.orionAlpha[50],- dark: baseColors.orionAlphaInverse[50],- },- "border-subtle": {- light: baseColors.orionAlpha[10],- dark: baseColors.orionAlphaInverse[10],- },-- // one-off colors for data layers which are not part of Metabase color palette- // we got a blessing from the design team to use these colors 😇- copper: {- light: "#B87333",- dark: "#B87333",- },- bronze: {- light: "#CD7F32",- dark: "#CD7F32",- },- silver: {- light: "#C0C0C0",- dark: "#C0C0C0",- },- gold: {- light: "#FFD700",- dark: "#FFD700",- },-});--export const colorConfig = getColorConfig(whitelabelColors);--export const getColors = (settings?: ColorSettings) =>- ({- ...Object.fromEntries(- Object.entries(getColorConfig(settings)).map(([k, v]) => [k, v.light]),- ),- ...settings,- }) as Record<keyof typeof colorConfig, string>;--export const getDarkColors = (settings?: ColorSettings) =>- ({- ...Object.fromEntries(- Object.entries(getColorConfig(settings)).map(([k, v]) => [k, v.dark]),- ),- ...settings,- }) as Record<keyof typeof colorConfig, string>;+const baseColors = getBaseColorsForThemeDefinitionOnly();-export const colors = getColors(whitelabelColors);+export const getColors = (whitelabelColors?: ColorSettings) =>+ deriveFullMetabaseTheme({ colorScheme: "light", whitelabelColors }).colors;-export const mutateColors = (settings: ColorSettings) => {- Object.assign(colorConfig, getColorConfig(settings));+export const colors: Record<MetabaseColorKey, string> =+ getColors(whitelabelColors);+export const mutateColors = (whitelabelColors: ColorSettings) => {// Empty the `colors` object to make sure we don't hold onto previously defined (now undefined) valuesObject.keys(colors).forEach((key) => {delete colors[key as keyof typeof colors];});- Object.assign(colors, getColors(settings));+ Object.assign(colors, getColors(whitelabelColors));};export const staticVizOverrides = {diff --git a/frontend/src/metabase/lib/colors/constants/accent-colors.ts b/frontend/src/metabase/lib/colors/constants/accent-colors.tsnew file mode 100644index 00000000000..747bf71c0ba--- /dev/null+++ b/frontend/src/metabase/lib/colors/constants/accent-colors.ts@@ -0,0 +1,36 @@+/* eslint-disable no-color-literals -- we define chart colors here to avoid duplication */++import type { ChartColorV2 } from "../types";++import { getBaseColorsForThemeDefinitionOnly } from "./base-colors";++const baseColors = getBaseColorsForThemeDefinitionOnly();++export const DEFAULT_ACCENT_COLORS: ChartColorV2[] = [+ "#509EE3", // accent0 - blue+ "#88BF4D", // accent1 - green+ "#A989C5", // accent2 - purple+ "#EF8C8C", // accent3 - red+ "#F9D45C", // accent4 - yellow+ "#F2A86F", // accent5 - orange+ "#98D9D9", // accent6 - cyan+ "#7172AD", // accent7 - indigo+];++export const LIGHT_THEME_ACCENT_COLORS: ChartColorV2[] = [+ ...DEFAULT_ACCENT_COLORS,+ {+ base: baseColors.orion[10],+ tint: baseColors.orion[5],+ shade: baseColors.orion[20],+ },+];++export const DARK_THEME_ACCENT_COLORS: ChartColorV2[] = [+ ...DEFAULT_ACCENT_COLORS,+ {+ base: baseColors.orion[80],+ tint: baseColors.orion[80],+ shade: baseColors.orion[110],+ },+];diff --git a/frontend/src/metabase/lib/colors/constants/accents.ts b/frontend/src/metabase/lib/colors/constants/accents.tsnew file mode 100644index 00000000000..031999aaf89--- /dev/null+++ b/frontend/src/metabase/lib/colors/constants/accents.ts@@ -0,0 +1,29 @@+import type { ChartColorV2 } from "../types";++/**+ * Maps chart color indices to their accent color keys.+ * Each entry contains the base, tint (light), and shade (dark) variants.+ *+ * This makes it easier to find-and-replace in the future.+ */+export const ACCENT_COLOR_NAMES_MAP = [+ { base: "accent0", tint: "accent0-light", shade: "accent0-dark" },+ { base: "accent1", tint: "accent1-light", shade: "accent1-dark" },+ { base: "accent2", tint: "accent2-light", shade: "accent2-dark" },+ { base: "accent3", tint: "accent3-light", shade: "accent3-dark" },+ { base: "accent4", tint: "accent4-light", shade: "accent4-dark" },+ { base: "accent5", tint: "accent5-light", shade: "accent5-dark" },+ { base: "accent6", tint: "accent6-light", shade: "accent6-dark" },+ { base: "accent7", tint: "accent7-light", shade: "accent7-dark" },+ { base: "accent-gray", tint: "accent-gray-light", shade: "accent-gray-dark" },+] as const satisfies ChartColorV2[];++export const ALL_ACCENT_COLOR_NAMES = ACCENT_COLOR_NAMES_MAP.flatMap(+ ({ base, tint, shade }) => [base, tint, shade],+);++/**+ * How much to tint and shade the light and dark chart color variants for.+ * Matches the default factor of tint() and shade() used for legacy colors.+ */+export const CHART_TINT_SHADE_FACTOR = 0.125;diff --git a/frontend/src/metabase/lib/colors/constants/base-colors.ts b/frontend/src/metabase/lib/colors/constants/base-colors.tsnew file mode 100644index 00000000000..2759025d351--- /dev/null+++ b/frontend/src/metabase/lib/colors/constants/base-colors.ts@@ -0,0 +1,238 @@+/* eslint-disable no-color-literals */+// NOTE: DO NOT ADD COLORS WITHOUT EXTREMELY GOOD REASON AND DESIGN REVIEW++/**+ * Base color palette for Metabase themes.+ * These colors are used to define the light and dark themes.+ */+const baseColors = {+ white: "hsla(0, 0%, 100%, 1.00)",+ black: "hsla(0, 0%, 0%, 1.00)",++ // Brand colors (dynamic based on --mb-color-brand). Expanded to roughly match the values in the new color palette (but these should be reworked).+ brand: {+ 100: "color-mix(in srgb, var(--mb-color-brand), black 86%)",+ 90: "color-mix(in srgb, var(--mb-color-brand), black 75%)",+ 80: "color-mix(in srgb, var(--mb-color-brand), black 62%)",+ 70: "color-mix(in srgb, var(--mb-color-brand), black 47%)",+ 60: "color-mix(in srgb, var(--mb-color-brand), black 28%)",+ 50: "color-mix(in srgb, var(--mb-color-brand), black 12%)",+ 40: "var(--mb-color-brand)", // This is the base brand color+ 30: "color-mix(in srgb, var(--mb-color-brand), white 35%)",+ 20: "color-mix(in srgb, var(--mb-color-brand), white 70%)",+ 10: "color-mix(in srgb, var(--mb-color-brand), white 91%)",+ 5: "color-mix(in srgb, var(--mb-color-brand), white 96%)",+ },++ // Deprecated Blue+ blue: {+ 100: "hsla(208, 100%, 8%, 1.00)",+ 90: "hsla(208, 89%, 14%, 1.00)",+ 80: "hsla(208, 82%, 22%, 1.00)",+ 70: "hsla(208, 80%, 31%, 1.00)",+ 60: "hsla(208, 78%, 42%, 1.00)",+ 50: "hsla(208, 68%, 53%, 1.00)",+ 40: "hsla(208, 72%, 60%, 1.00)", // brand+ 30: "hsla(208, 73%, 74%, 1.00)",+ 20: "hsla(209, 73%, 88%, 1.00)", // focus+ 10: "hsla(208, 79%, 96%, 1.00)", // baby blue+ 5: "hsla(210, 75%, 98%, 1.00)",+ },++ // Deprecated Gray+ gray: {+ 100: "hsla(206, 16%, 8%, 1.00)", // background-primary-inverse+ 90: "hsla(202, 15%, 15%, 1.00)",+ 80: "hsla(205, 15%, 23%, 1.00)",+ 70: "hsla(206, 14%, 32%, 1.00)",+ 60: "hsla(207, 9%, 44%, 1.00)",+ 50: "hsla(208, 7%, 54%, 1.00)",+ 40: "hsla(208, 7%, 60%, 1.00)",+ 30: "hsla(208, 11%, 74%, 1.00)",+ 20: "hsla(210, 13%, 88%, 1.00)",+ 10: "hsla(210, 20%, 96%, 1.00)",+ 5: "hsla(210, 25%, 98%, 1.00)",+ },++ // Ocean+ ocean: {+ 100: "hsla(208, 100%, 9%, 1)",+ 90: "hsla(208, 89%, 15%, 1)",+ 80: "hsla(208, 82%, 22%, 1)",+ 70: "hsla(208, 80%, 31%, 1)",+ 60: "hsla(208, 78%, 42%, 1)",+ 50: "hsla(208, 68%, 53%, 1)",+ 40: "hsla(208, 72%, 60%, 1)",+ 30: "hsla(208, 73%, 74%, 1)",+ 20: "hsla(209, 73%, 88%, 1)",+ 10: "hsla(208, 79%, 96%, 1)",+ 5: "hsla(208, 75%, 98%, 1)",+ },++ // Orion+ orion: {+ 110: "hsla(205, 63%, 5%, 1)",+ 100: "hsla(204, 66%, 8%, 1)",+ 90: "hsla(204, 34%, 14%, 1)",+ 80: "hsla(205, 19%, 23%, 1)",+ 70: "hsla(204, 12%, 32%, 1)",+ 60: "hsla(205, 8%, 43%, 1)",+ 50: "hsla(203, 5%, 53%, 1)",+ 40: "hsla(205, 6%, 60%, 1)",+ 30: "hsla(203, 6%, 73%, 1)",+ 20: "hsla(195, 6%, 87%, 1)",+ 10: "hsla(240, 4%, 95%, 1)",+ 5: "hsla(240, 11%, 98%, 1)",+ },++ // Orion Alpha+ orionAlpha: {+ 100: "hsla(204, 68%, 8%, 1)",+ 90: "hsla(204, 66%, 8%, 0.93)",+ 80: "hsla(204, 66%, 8%, 0.84)",+ 70: "hsla(204, 66%, 8%, 0.74)",+ 60: "hsla(204, 66%, 8%, 0.62)",+ 50: "hsla(204, 66%, 8%, 0.51)",+ 40: "hsla(204, 66%, 8%, 0.44)",+ 30: "hsla(204, 66%, 8%, 0.29)",+ 20: "hsla(204, 66%, 8%, 0.17)",+ 10: "hsla(204, 66%, 8%, 0.05)",+ 5: "hsla(204, 66%, 8%, 0.02)",+ },++ // Ocean Alpha. These are not in use yet because of whitelabeling+ oceanAlpha: {+ 50: "hsla(208, 95%, 42%, 0.82)",+ 40: "hsla(208, 95%, 42%, 0.69)",+ 30: "hsla(208, 95%, 42%, 0.45)",+ 20: "hsla(208, 95%, 42%, 0.21)",+ 10: "hsla(208, 95%, 42%, 0.07)",+ 5: "hsla(208, 95%, 42%, 0.03)",+ },++ orionAlphaInverse: {+ 100: "hsla(0, 0%, 100%, 1.00)",+ 90: "hsla(0, 0%, 100%, 0.98)",+ 80: "hsla(0, 0%, 100%, 0.95)",+ 70: "hsla(0, 0%, 100%, 0.85)",+ 60: "hsla(0, 0%, 100%, 0.69)",+ 50: "hsla(0, 0%, 100%, 0.53)",+ 40: "hsla(0, 0%, 100%, 0.46)",+ 30: "hsla(0, 0%, 100%, 0.33)",+ 20: "hsla(0, 0%, 100%, 0.21)",+ 10: "hsla(0, 0%, 100%, 0.10)",+ 5: "hsla(0, 0%, 100%, .01)",+ },++ // Lobster+ lobster: {+ 100: "hsla(0, 81%, 11%, 1)",+ 90: "hsla(1, 75%, 17%, 1)",+ 80: "hsla(1, 71%, 26%, 1)",+ 70: "hsla(1, 69%, 37%, 1)",+ 60: "hsla(1, 67%, 49%, 1)",+ 50: "hsla(358, 71%, 62%, 1)",+ 40: "hsla(1, 84%, 69%, 1)",+ 30: "hsla(1, 85%, 81%, 1)",+ 20: "hsla(2, 67%, 90%, 1)",+ 10: "hsla(0, 76%, 97%, 1)",+ 5: "hsla(0, 100%, 99%, 1)",+ },++ // Flamingo+ flamingo: {+ 100: "hsla(334, 75%, 10%, 1)",+ 90: "hsla(334, 79%, 17%, 1)",+ 80: "hsla(334, 72%, 26%, 1)",+ 70: "hsla(334, 71%, 36%, 1)",+ 60: "hsla(334, 69%, 48%, 1)",+ 50: "hsla(334, 67%, 60%, 1)",+ 40: "hsla(334, 80%, 68%, 1)",+ 30: "hsla(334, 79%, 80%, 1)",+ 20: "hsla(335, 79%, 91%, 1)",+ 10: "hsla(335, 67%, 96%, 1)",+ 5: "hsla(330, 67%, 99%, 1)",+ },++ // Mango+ mango: {+ 100: "hsla(26, 89%, 7%, 1)",+ 90: "hsla(26, 79%, 13%, 1)",+ 80: "hsla(25, 73%, 20%, 1)",+ 70: "hsla(26, 70%, 29%, 1)",+ 60: "hsla(26, 69%, 39%, 1)",+ 50: "hsla(26, 68%, 48%, 1)",+ 40: "hsla(26, 79%, 54%, 1)",+ 30: "hsla(26, 84%, 70%, 1)",+ 20: "hsla(26, 88%, 87%, 1)",+ 10: "hsla(25, 100%, 95%, 1)",+ 5: "hsla(30, 100%, 98%, 1)",+ },++ // Dubloon+ dubloon: {+ 100: "hsla(45, 100%, 5%, 1)",+ 90: "hsla(46, 88%, 10%, 1)",+ 80: "hsla(46, 82%, 15%, 1)",+ 70: "hsla(46, 79%, 22%, 1)",+ 60: "hsla(46, 76%, 30%, 1)",+ 50: "hsla(46, 76%, 37%, 1)",+ 40: "hsla(46, 75%, 44%, 1)",+ 30: "hsla(46, 81%, 52%, 1)",+ 20: "hsla(46, 94%, 74%, 1)",+ 10: "hsla(46, 96%, 90%, 1)",+ 5: "hsla(45, 100%, 96%, 1)",+ },++ // Palm+ palm: {+ 100: "hsla(94, 85%, 5%, 1)",+ 90: "hsla(92, 62%, 10%, 1)",+ 80: "hsla(89, 54%, 16%, 1)",+ 70: "hsla(89, 50%, 24%, 1)",+ 60: "hsla(89, 48%, 32%, 1)",+ 50: "hsla(89, 48%, 40%, 1)",+ 40: "hsla(89, 47%, 45%, 1)",+ 30: "hsla(90, 47%, 60%, 1)",+ 20: "hsla(91, 51%, 81%, 1)",+ 10: "hsla(92, 65%, 92%, 1)",+ 5: "hsla(93, 73%, 97%, 1)",+ },++ // Seafoam+ seafoam: {+ 100: "hsla(180, 84%, 5%, 1)",+ 90: "hsla(180, 34%, 12%, 1)",+ 80: "hsla(180, 80%, 14%, 1)",+ 70: "hsla(180, 70%, 21%, 1)",+ 60: "hsla(180, 44%, 33%, 1)",+ 50: "hsla(180, 74%, 34%, 1)",+ 40: "hsla(180, 42%, 46%, 1)",+ 30: "hsla(180, 47%, 60%, 1)",+ 20: "hsla(180, 55%, 81%, 1)",+ 10: "hsla(180, 68%, 93%, 1)",+ 5: "hsla(180, 69%, 97%, 1)",+ },++ // Octopus+ octopus: {+ 100: "hsla(240, 7%, 9%, 1)",+ 90: "hsla(240, 7%, 9%, 1)",+ 80: "hsla(240, 43%, 33%, 1)",+ 70: "hsla(240, 40%, 46%, 1)",+ 60: "hsla(240, 46%, 58%, 1)",+ 50: "hsla(240, 65%, 69%, 1)",+ 40: "hsla(240, 69%, 74%, 1)",+ 30: "hsla(240, 49%, 81%, 1)",+ 20: "hsla(240, 66%, 92%, 1)",+ 10: "hsla(240, 100%, 97%, 1)",+ 5: "hsla(240, 100%, 99%, 1)",+ },+};++/**+ * These base colors are only for use in defining `light.ts` and `dark.ts` themes.+ *+ * Don't use it for anything else or you will be fired.+ */+export const getBaseColorsForThemeDefinitionOnly = () => baseColors;diff --git a/frontend/src/metabase/lib/colors/constants/color-names.ts b/frontend/src/metabase/lib/colors/constants/color-names.tsnew file mode 100644index 00000000000..699c2712c3a--- /dev/null+++ b/frontend/src/metabase/lib/colors/constants/color-names.ts@@ -0,0 +1,9 @@+import type { MetabaseColorKey } from "../types";++import { ALL_ACCENT_COLOR_NAMES } from "./accents";+import { METABASE_LIGHT_THEME } from "./themes/light";++/** All color names available in Metabase themes. */+export const ALL_COLOR_NAMES = Object.keys(METABASE_LIGHT_THEME.colors).concat(+ ALL_ACCENT_COLOR_NAMES,+) as MetabaseColorKey[];diff --git a/frontend/src/metabase/lib/colors/constants/protected-colors.ts b/frontend/src/metabase/lib/colors/constants/protected-colors.tsnew file mode 100644index 00000000000..4ed90631665--- /dev/null+++ b/frontend/src/metabase/lib/colors/constants/protected-colors.ts@@ -0,0 +1,33 @@+import type { MetabaseColorKey } from "../types/color-keys";++/**+ * Colors that should not be exposed to modular embedding.+ * For example, the Metabase brand color must not be modifiable.+ */+export const PROTECTED_COLORS = [+ // Metabase's own brand+ "metabase-brand",++ // Admin-only UI colors+ "admin-navbar",+ "admin-navbar-secondary",+ "admin-navbar-inverse",++ // Colors based on specific base colors+ "bg-ocean-alpha-light",++ // Accent colors must be set thru the `chartColors` API, not set directly+ "accent0",+ "accent1",+ "accent2",+ "accent3",+ "accent4",+ "accent5",+ "accent6",+ "accent7",++ // Grey accent colors+ "accent-gray",+ "accent-gray-dark",+ "accent-gray-light",+] as const satisfies readonly MetabaseColorKey[];diff --git a/frontend/src/metabase/lib/colors/constants/themes/dark.ts b/frontend/src/metabase/lib/colors/constants/themes/dark.tsnew file mode 100644index 00000000000..3aab68fe346--- /dev/null+++ b/frontend/src/metabase/lib/colors/constants/themes/dark.ts@@ -0,0 +1,93 @@+/* eslint-disable no-color-literals */+import type { MetabaseThemeV2 } from "../../types";+import { DARK_THEME_ACCENT_COLORS } from "../accent-colors";+import { getBaseColorsForThemeDefinitionOnly } from "../base-colors";++const baseColors = getBaseColorsForThemeDefinitionOnly();++/**+ * The default dark theme for Metabase.+ */+export const METABASE_DARK_THEME: MetabaseThemeV2 = {+ version: 2,+ chartColors: DARK_THEME_ACCENT_COLORS,+ colors: {+ "admin-navbar": baseColors.octopus[80],+ "admin-navbar-secondary": baseColors.octopus[60],+ "admin-navbar-inverse": baseColors.octopus[60],+ "background-brand": baseColors.brand[90],+ "background-disabled": baseColors.orionAlphaInverse[10],+ "background-disabled-inverse": baseColors.orionAlpha[10],+ "background-error-secondary": baseColors.lobster[90],+ "background-hover":+ "color-mix(in srgb, var(--mb-color-brand) 21%, transparent)",+ "background-hover-light":+ "color-mix(in srgb, var(--mb-color-brand) 7%, transparent)",+ "background-selected": baseColors.brand[40],+ "background-primary": baseColors.orion[100],+ "background-secondary": baseColors.orion[110],+ "background-tertiary": baseColors.orion[80],+ "background-primary-inverse": baseColors.orion[20],+ "background-secondary-inverse": baseColors.orion[30],+ "background-tertiary-inverse": baseColors.orion[70],+ overlay: baseColors.orionAlpha[70],+ "bg-ocean-alpha-light": baseColors.oceanAlpha[20],+ "background-error": baseColors.lobster[90],+ "background-success": baseColors.palm[90],+ "brand-alpha-04":+ "color-mix(in srgb, var(--mb-color-brand) 4%, transparent)",+ "brand-alpha-88":+ "color-mix(in srgb, var(--mb-color-brand) 88%, transparent)",+ "brand-dark": baseColors.brand[30],+ "brand-darker": baseColors.brand[20],+ "brand-light": baseColors.brand[80],+ "brand-lighter": baseColors.brand[90],+ brand: baseColors.blue[40],+ danger: baseColors.lobster[50],+ error: baseColors.lobster[50],+ filter: baseColors.octopus[40],+ focus: baseColors.blue[70],+ "icon-primary": baseColors.brand[40],+ "icon-disabled": baseColors.orionAlphaInverse[30],+ "icon-secondary": baseColors.orionAlphaInverse[50],+ "metabase-brand": baseColors.blue[40],+ "saturated-blue": baseColors.ocean[40],+ "saturated-green": baseColors.palm[40],+ "saturated-purple": baseColors.octopus[40],+ "saturated-red": baseColors.lobster[40],+ "saturated-yellow": baseColors.dubloon[30],+ shadow: `color-mix(in srgb, ${baseColors.orion[110]} 20%, transparent)`,+ "success-secondary": baseColors.palm[40],+ success: baseColors.palm[50],+ summarize: baseColors.palm[40],+ "switch-off": baseColors.orionAlphaInverse[20],+ "syntax-parameters-active": baseColors.mango[90],+ "syntax-parameters": baseColors.mango[40],+ "text-brand": baseColors.brand[40],+ "text-tertiary": baseColors.orionAlphaInverse[40],+ "text-tertiary-inverse": baseColors.orionAlpha[40],+ "text-hover": baseColors.brand[30],+ "text-secondary-opaque": baseColors.orion[20],+ "text-primary": baseColors.orionAlphaInverse[80],+ "text-primary-inverse": baseColors.orionAlpha[80],+ "text-secondary": baseColors.orionAlphaInverse[60],+ "text-secondary-inverse": baseColors.orionAlpha[60],+ "text-selected": baseColors.white,+ "tooltip-background-focused": `color-mix(in srgb, ${baseColors.orion[70]} 50%, #000)`,+ "tooltip-background": baseColors.orion[70],+ "tooltip-text-secondary": baseColors.orionAlphaInverse[60],+ "tooltip-text": baseColors.orionAlphaInverse[80],+ warning: baseColors.dubloon[30],+ "background-warning": baseColors.dubloon[90],+ info: baseColors.orion[50],+ "background-info": baseColors.orion[90],+ white: baseColors.orion[110],+ border: baseColors.orionAlphaInverse[20],+ "border-strong": baseColors.orionAlphaInverse[50],+ "border-subtle": baseColors.orionAlphaInverse[10],+ copper: "#B87333",+ bronze: "#CD7F32",+ silver: "#C0C0C0",+ gold: "#FFD700",+ },+};diff --git a/frontend/src/metabase/lib/colors/constants/themes/light.ts b/frontend/src/metabase/lib/colors/constants/themes/light.tsnew file mode 100644index 00000000000..f42d14c3c70--- /dev/null+++ b/frontend/src/metabase/lib/colors/constants/themes/light.ts@@ -0,0 +1,93 @@+/* eslint-disable no-color-literals */+import type { MetabaseThemeV2 } from "../../types";+import { LIGHT_THEME_ACCENT_COLORS } from "../accent-colors";+import { getBaseColorsForThemeDefinitionOnly } from "../base-colors";++const baseColors = getBaseColorsForThemeDefinitionOnly();++/**+ * The default light theme for Metabase.+ */+export const METABASE_LIGHT_THEME: MetabaseThemeV2 = {+ version: 2,+ chartColors: LIGHT_THEME_ACCENT_COLORS,+ colors: {+ "admin-navbar": baseColors.octopus[60],+ "admin-navbar-secondary": baseColors.octopus[40],+ "admin-navbar-inverse": baseColors.octopus[80],+ "background-brand": baseColors.brand[10],+ "background-disabled": baseColors.orionAlpha[10],+ "background-disabled-inverse": baseColors.orionAlphaInverse[10],+ "background-error-secondary": baseColors.lobster[5],+ "background-hover":+ "color-mix(in srgb, var(--mb-color-brand) 21%, transparent)",+ "background-hover-light":+ "color-mix(in srgb, var(--mb-color-brand) 7%, transparent)",+ "background-selected": baseColors.brand[50],+ "background-primary": baseColors.white,+ "background-secondary": baseColors.orion[5],+ "background-tertiary": baseColors.orion[10],+ "background-primary-inverse": baseColors.orion[80],+ "background-secondary-inverse": baseColors.orion[70],+ "background-tertiary-inverse": baseColors.orion[40],+ overlay: baseColors.orionAlpha[60],+ "bg-ocean-alpha-light": baseColors.oceanAlpha[5],+ "background-error": baseColors.lobster[10],+ "background-success": baseColors.palm[5],+ "brand-alpha-04":+ "color-mix(in srgb, var(--mb-color-brand) 4%, transparent)",+ "brand-alpha-88":+ "color-mix(in srgb, var(--mb-color-brand) 88%, transparent)",+ "brand-dark": baseColors.brand[60],+ "brand-darker": baseColors.brand[70],+ "brand-light": baseColors.brand[10],+ "brand-lighter": baseColors.brand[5],+ brand: baseColors.blue[40],+ danger: baseColors.lobster[50],+ error: baseColors.lobster[50],+ filter: baseColors.octopus[50],+ focus: baseColors.blue[20],+ "icon-primary": baseColors.brand[40],+ "icon-disabled": baseColors.orionAlpha[30],+ "icon-secondary": baseColors.orionAlpha[50],+ "metabase-brand": baseColors.blue[40],+ "saturated-blue": baseColors.ocean[60],+ "saturated-green": baseColors.palm[60],+ "saturated-purple": baseColors.octopus[60],+ "saturated-red": baseColors.lobster[60],+ "saturated-yellow": baseColors.dubloon[30],+ shadow: baseColors.orionAlpha[20],+ "success-secondary": baseColors.palm[60],+ success: baseColors.palm[50],+ summarize: baseColors.palm[50],+ "switch-off": baseColors.orionAlpha[20],+ "syntax-parameters-active": baseColors.mango[10],+ "syntax-parameters": baseColors.mango[60],+ "text-brand": baseColors.brand[50],+ "text-tertiary": baseColors.orionAlpha[40],+ "text-tertiary-inverse": baseColors.orionAlphaInverse[40],+ "text-hover": baseColors.brand[60],+ "text-secondary-opaque": baseColors.orion[60],+ "text-primary": baseColors.orionAlpha[80],+ "text-primary-inverse": baseColors.orionAlphaInverse[80],+ "text-secondary": baseColors.orionAlpha[60],+ "text-secondary-inverse": baseColors.orionAlphaInverse[60],+ "text-selected": baseColors.white,+ "tooltip-background-focused": `color-mix(in srgb, ${baseColors.orion[80]} 50%, #000)`,+ "tooltip-background": baseColors.orion[80],+ "tooltip-text-secondary": baseColors.orionAlphaInverse[60],+ "tooltip-text": baseColors.white,+ warning: baseColors.dubloon[30],+ "background-warning": baseColors.dubloon[5],+ info: baseColors.orion[40],+ "background-info": baseColors.orion[10],+ white: baseColors.white,+ border: baseColors.orion[20],+ "border-strong": baseColors.orionAlpha[50],+ "border-subtle": baseColors.orionAlpha[10],+ copper: "#B87333",+ bronze: "#CD7F32",+ silver: "#C0C0C0",+ gold: "#FFD700",+ },+};diff --git a/frontend/src/metabase/lib/colors/derive-theme.ts b/frontend/src/metabase/lib/colors/derive-theme.tsnew file mode 100644index 00000000000..0656df7d03d--- /dev/null+++ b/frontend/src/metabase/lib/colors/derive-theme.ts@@ -0,0 +1,51 @@+import _ from "underscore";++import type { MetabaseEmbeddingThemeV2 } from "metabase/embedding-sdk/theme";+import type { ColorSettings } from "metabase-types/api";++import type { ResolvedColorScheme } from "../color-scheme";++import { mapChartColorsToAccents } from "./accents";+import { PROTECTED_COLORS } from "./constants/protected-colors";+import { getThemeFromColorScheme } from "./theme-from-color-scheme";+import type { MetabaseColorKey, MetabaseDerivedThemeV2 } from "./types";++/**+ * Derives the _full_ metabase themes given a theme configuration.+ * Applies to both the main app and modular embedding.+ *+ * Priority: base theme colors < appearance settings whitelabel colors < modular embedding theme overrides+ *+ * TODO(EMB-984): generate lightness stops based on a single color+ * TODO(EMB-1013): generate square and octagonal color harmonies+ * TODO(EMB-1016): derive full color palette based on the given color object+ */+export function deriveFullMetabaseTheme({+ colorScheme,+ whitelabelColors,+ embeddingThemeOverride,+}: {+ colorScheme: ResolvedColorScheme;+ whitelabelColors?: ColorSettings | null;+ embeddingThemeOverride?: MetabaseEmbeddingThemeV2;+}): MetabaseDerivedThemeV2 {+ const baseTheme = getThemeFromColorScheme(colorScheme);++ // Filter out protected colors from embedding theme overrides.+ // Some colors (such as the Metabase brand color) should not be modifiable.+ const filteredEmbeddingColors = _.omit(+ embeddingThemeOverride?.colors,+ ...PROTECTED_COLORS,+ );++ return {+ version: 2,+ colors: {+ ...baseTheme.colors,+ ...mapChartColorsToAccents(baseTheme.chartColors),+ ...whitelabelColors,+ ...filteredEmbeddingColors,+ ...mapChartColorsToAccents(embeddingThemeOverride?.chartColors ?? []),+ } as Record<MetabaseColorKey, string>,+ };+}diff --git a/frontend/src/metabase/lib/colors/derive-theme.unit.spec.ts b/frontend/src/metabase/lib/colors/derive-theme.unit.spec.tsnew file mode 100644index 00000000000..fd7ab06473c--- /dev/null+++ b/frontend/src/metabase/lib/colors/derive-theme.unit.spec.ts@@ -0,0 +1,87 @@+import { PROTECTED_COLORS } from "./constants/protected-colors";+import { METABASE_LIGHT_THEME } from "./constants/themes/light";+import { deriveFullMetabaseTheme } from "./derive-theme";++describe("deriveFullMetabaseTheme", () => {+ it("applies whitelabel colors over the base theme", () => {+ const derived = deriveFullMetabaseTheme({+ colorScheme: "light",+ whitelabelColors: { brand: "#ff0000" },+ });++ // The whitelabel color should override the base theme color+ expect(derived.colors["brand"]).toBe("#ff0000");++ // Other colors should remain from base theme+ expect(derived.colors["text-primary"]).toBe(+ METABASE_LIGHT_THEME.colors["text-primary"],+ );+ });++ it("applies embedding theme overrides over whitelabel colors", () => {+ const derived = deriveFullMetabaseTheme({+ colorScheme: "light",+ whitelabelColors: { brand: "#ff0000" },+ embeddingThemeOverride: { version: 2, colors: { brand: "#00ff00" } },+ });++ // User overrides takes precedence over instance whitelabel colors+ expect(derived.colors["brand"]).toBe("#00ff00");+ });++ it("filters out all internal colors from embedding overrides", () => {+ const derivedBaseLightTheme = deriveFullMetabaseTheme({+ colorScheme: "light",+ });++ const embeddingColors: Record<string, string> = {};++ // modular embedding user tries to override the protected colors+ for (const protectedColorKey of PROTECTED_COLORS) {+ embeddingColors[protectedColorKey] = "#ff0000";+ }++ const derived = deriveFullMetabaseTheme({+ colorScheme: "light",+ embeddingThemeOverride: { version: 2, colors: embeddingColors },+ });++ // All protected colors must remain unchanged+ for (const protectedColorKey of PROTECTED_COLORS) {+ expect(derived.colors[protectedColorKey]).toBe(+ derivedBaseLightTheme.colors[protectedColorKey],+ );+ }+ });++ it("maps chartColors to accent colors", () => {+ const derived = deriveFullMetabaseTheme({+ colorScheme: "light",+ embeddingThemeOverride: {+ version: 2,+ chartColors: ["#ff0000", "#00ff00"],+ },+ });++ expect(derived.colors["accent0"]).toBe("#ff0000");+ expect(derived.colors["accent1"]).toBe("#00ff00");+ });++ it("overrides accent colors via chartColors", () => {+ const result = deriveFullMetabaseTheme({+ colorScheme: "light",+ embeddingThemeOverride: {+ version: 2,+ chartColors: [{ base: "#ff0000", tint: "#ff8888", shade: "#880000" }],+ },+ });++ // Cast to Record<string, string> to access tint/shade keys+ // which are outside of the core MetabaseColorKey type+ const colors = result.colors as Record<string, string>;++ expect(colors["accent0"]).toBe("#ff0000");+ expect(colors["accent0-light"]).toBe("#ff8888");+ expect(colors["accent0-dark"]).toBe("#880000");+ });+});diff --git a/frontend/src/metabase/lib/colors/index.ts b/frontend/src/metabase/lib/colors/index.tsindex deae28fc43f..d892d76c5d8 100644--- a/frontend/src/metabase/lib/colors/index.ts+++ b/frontend/src/metabase/lib/colors/index.ts@@ -1,2 +1,10 @@export * from "./palette";export * from "./colors";++export { METABASE_DARK_THEME } from "./constants/themes/dark";+export { METABASE_LIGHT_THEME } from "./constants/themes/light";+export { ALL_COLOR_NAMES } from "./constants/color-names";++export type * from "./types";++export { deriveFullMetabaseTheme } from "./derive-theme";diff --git a/frontend/src/metabase/lib/colors/theme-from-color-scheme.ts b/frontend/src/metabase/lib/colors/theme-from-color-scheme.tsnew file mode 100644index 00000000000..22bdfb69a2c--- /dev/null+++ b/frontend/src/metabase/lib/colors/theme-from-color-scheme.ts@@ -0,0 +1,11 @@+import type { ResolvedColorScheme } from "../color-scheme";++import { METABASE_DARK_THEME } from "./constants/themes/dark";+import { METABASE_LIGHT_THEME } from "./constants/themes/light";+import type { MetabaseThemeV2 } from "./types";++/** Returns the theme definition for a color scheme. */+export const getThemeFromColorScheme = (+ colorScheme: ResolvedColorScheme,+): MetabaseThemeV2 =>+ colorScheme === "dark" ? METABASE_DARK_THEME : METABASE_LIGHT_THEME;diff --git a/frontend/src/metabase/lib/colors/types.ts b/frontend/src/metabase/lib/colors/types.tsdeleted file mode 100644index f407da3dfb7..00000000000--- a/frontend/src/metabase/lib/colors/types.ts+++ /dev/null@@ -1,13 +0,0 @@-import type { colorConfig } from "./colors";--export type ColorPalette = Partial<Record<keyof typeof colorConfig, string>>;--export type ColorName = keyof typeof colorConfig;--export interface AccentColorOptions {- main?: boolean;- light?: boolean;- dark?: boolean;- harmony?: boolean;- gray?: boolean;-}diff --git a/frontend/src/metabase/lib/colors/types/accent-color-options.ts b/frontend/src/metabase/lib/colors/types/accent-color-options.tsnew file mode 100644index 00000000000..b59fefd1c36--- /dev/null+++ b/frontend/src/metabase/lib/colors/types/accent-color-options.ts@@ -0,0 +1,7 @@+export interface AccentColorOptions {+ main?: boolean;+ light?: boolean;+ dark?: boolean;+ harmony?: boolean;+ gray?: boolean;+}diff --git a/frontend/src/metabase/lib/colors/types/color-keys.ts b/frontend/src/metabase/lib/colors/types/color-keys.tsnew file mode 100644index 00000000000..8b611138a7b--- /dev/null+++ b/frontend/src/metabase/lib/colors/types/color-keys.ts@@ -0,0 +1,106 @@+import type { ALL_ACCENT_COLOR_NAMES } from "../constants/accents";++/**+ * All color keys available in Metabase themes.+ *+ * Both the light and dark theme must define all of these colors.+ *+ * @inline+ * @category Theming+ */+export type MetabaseColorKey =+ | MetabaseAccentColorKey+ | ProtectedColorKey+ | "background-brand"+ | "background-disabled"+ | "background-disabled-inverse"+ | "background-error"+ | "background-error-secondary"+ | "background-hover"+ | "background-hover-light"+ | "background-info"+ | "background-primary"+ | "background-primary-inverse"+ | "background-secondary"+ | "background-secondary-inverse"+ | "background-selected"+ | "background-success"+ | "background-tertiary"+ | "background-tertiary-inverse"+ | "background-warning"+ | "border"+ | "border-strong"+ | "border-subtle"+ | "brand"+ | "brand-alpha-04"+ | "brand-alpha-88"+ | "brand-dark"+ | "brand-darker"+ | "brand-light"+ | "brand-lighter"+ | "bronze"+ | "copper"+ | "danger"+ | "error"+ | "filter"+ | "focus"+ | "gold"+ | "icon-disabled"+ | "icon-primary"+ | "icon-secondary"+ | "info"+ | "overlay"+ | "saturated-blue"+ | "saturated-green"+ | "saturated-purple"+ | "saturated-red"+ | "saturated-yellow"+ | "shadow"+ | "silver"+ | "success"+ | "success-secondary"+ | "summarize"+ | "switch-off"+ | "syntax-parameters"+ | "syntax-parameters-active"+ | "text-brand"+ | "text-hover"+ | "text-primary"+ | "text-primary-inverse"+ | "text-secondary"+ | "text-secondary-inverse"+ | "text-secondary-opaque"+ | "text-selected"+ | "text-tertiary"+ | "text-tertiary-inverse"+ | "tooltip-background"+ | "tooltip-background-focused"+ | "tooltip-text"+ | "tooltip-text-secondary"+ | "warning"+ | "white";++/**+ * @inline+ */+export type MetabaseAccentColorKey = (typeof ALL_ACCENT_COLOR_NAMES)[number];++/**+ * Color keys that are protected and should not be exposed to embedding.+ *+ * Do not derive this from `PROTECTED_COLORS` or doc generation will fail.+ */+export type ProtectedColorKey =+ | "metabase-brand"+ | "admin-navbar"+ | "admin-navbar-secondary"+ | "admin-navbar-inverse"+ | "bg-ocean-alpha-light"+ | "accent0"+ | "accent1"+ | "accent2"+ | "accent3"+ | "accent4"+ | "accent5"+ | "accent6"+ | "accent7";diff --git a/frontend/src/metabase/lib/colors/types/index.ts b/frontend/src/metabase/lib/colors/types/index.tsnew file mode 100644index 00000000000..6c3b95e3714--- /dev/null+++ b/frontend/src/metabase/lib/colors/types/index.ts@@ -0,0 +1,13 @@+export type {+ ChartColorV2,+ MetabaseThemeV2,+ MetabaseDerivedThemeV2,+} from "./theme";++import type { MetabaseColorKey } from "./color-keys";++export type ColorPalette = Partial<Record<MetabaseColorKey, string>>;+export type ColorName = MetabaseColorKey;++export type * from "./color-keys";+export type * from "./accent-color-options";diff --git a/frontend/src/metabase/lib/colors/types/theme.ts b/frontend/src/metabase/lib/colors/types/theme.tsnew file mode 100644index 00000000000..9ba7d599144--- /dev/null+++ b/frontend/src/metabase/lib/colors/types/theme.ts@@ -0,0 +1,53 @@+import type { MetabaseAccentColorKey, MetabaseColorKey } from "./color-keys";++/**+ * A complete Metabase theme definition.+ *+ * - `colors` contains all color keys+ * - `chartColors` contains chart color definitions+ */+export interface MetabaseThemeV2 {+ version: 2;++ colors: Record<MetabaseColorKeyWithoutAccents, string>;+ chartColors: ChartColorV2[];+}++/**+ * A fully derived theme with all color values filled in.+ * This is the output of `deriveFullMetabaseTheme`.+ */+export interface MetabaseDerivedThemeV2 {+ version: 2;++ colors: Record<MetabaseColorKey, string>;+}++/**+ * Chart color definition for V2 themes.+ *+ * Can be a simple color string or an object with base/tint/shade variants.+ *+ * @category Theming+ */+export type ChartColorV2 =+ | string+ | {+ base: string;++ /** Lighter variation of the base color */+ tint?: string;++ /** Darker variation of the base color */+ shade?: string;+ }+ | null;++/**+ * Metabase color keys without accent0 - accent7.+ * Those will be transformed from `chartColors`.+ */+type MetabaseColorKeyWithoutAccents = Exclude<+ MetabaseColorKey,+ MetabaseAccentColorKey+>;diff --git a/frontend/src/metabase/lib/settings.ts b/frontend/src/metabase/lib/settings.tsindex 1610685dcba..ea88b6a7947 100644--- a/frontend/src/metabase/lib/settings.ts+++ b/frontend/src/metabase/lib/settings.ts@@ -3,6 +3,7 @@ import _ from "underscore";import { numberToWord } from "metabase/lib/utils";import type {+ ColorSettings,PasswordComplexity,SettingKey,Settings,@@ -278,6 +279,15 @@ class MetabaseSettings {const setting = this.get("subscription-allowed-domains") || "";return setting ? setting.split(",") : [];}++ /**+ * @deprecated use getSetting(state, "application-colors")+ *+ * Only use this when Redux store is not always available, e.g. in ThemeProvider+ */+ applicationColors(): ColorSettings {+ return this.get("application-colors" as SettingKey) as ColorSettings;+ }}function makeRegexTest(property: string, regex: RegExp) {diff --git a/frontend/src/metabase/styled-components/containers/GlobalStyles/GlobalStyles.tsx b/frontend/src/metabase/styled-components/containers/GlobalStyles/GlobalStyles.tsxindex f4ec897b80d..ccaceaf4cf6 100644--- a/frontend/src/metabase/styled-components/containers/GlobalStyles/GlobalStyles.tsx+++ b/frontend/src/metabase/styled-components/containers/GlobalStyles/GlobalStyles.tsx@@ -2,6 +2,7 @@import { Global, css } from "@emotion/react";import { useMemo } from "react";+import { useSetting } from "metabase/common/hooks";import { baseStyle, rootStyle } from "metabase/css/core/base.styled";import { defaultFontFiles } from "metabase/css/core/fonts.styled";import {@@ -19,13 +20,16 @@ import { getFont, getFontFiles } from "../../selectors";export const GlobalStyles = (): JSX.Element => {const font = useSelector(getFont);const fontFiles = useSelector(getFontFiles);+ const whitelabelColors = useSetting("application-colors");const sitePath = getSitePath();const theme = useMantineTheme();const { colorScheme } = theme.other;// This can get expensive so we should memoize it separately- const cssVariables = useMemo(() => getMetabaseCssVariables(theme), [theme]);+ const cssVariables = useMemo(() => {+ return getMetabaseCssVariables({ theme, whitelabelColors });+ }, [theme, whitelabelColors]);const styles = useMemo(() => {return css`diff --git a/frontend/src/metabase/styled-components/theme/css-variables.ts b/frontend/src/metabase/styled-components/theme/css-variables.tsindex 049a11c31d6..48a9397fc2a 100644--- a/frontend/src/metabase/styled-components/theme/css-variables.ts+++ b/frontend/src/metabase/styled-components/theme/css-variables.ts@@ -9,19 +9,36 @@ import {SDK_TO_MAIN_APP_TOOLTIP_COLORS_MAPPING,SDK_UNCHANGEABLE_COLORS,} from "metabase/embedding-sdk/theme/embedding-color-palette";-import { colorConfig } from "metabase/lib/colors";+import type { ResolvedColorScheme } from "metabase/lib/color-scheme";+import { deriveFullMetabaseTheme } from "metabase/lib/colors";import type { ColorName } from "metabase/lib/colors/types";import type { MantineTheme } from "metabase/ui";+import type { ColorSettings } from "metabase-types/api";-const createColorVars = (colorScheme: "light" | "dark"): string =>- Object.entries(colorConfig)- .map(([name, value]) => `--mb-color-${name}: ${value[colorScheme]};`)+const createColorVars = (+ colorScheme: ResolvedColorScheme,+ whitelabelColors?: ColorSettings | null,+): string => {+ const theme = deriveFullMetabaseTheme({+ colorScheme,+ whitelabelColors,+ });++ return Object.entries(theme.colors)+ .map(([name, value]) => `--mb-color-${name}: ${value};`).join("\n");+};/*** Defines the CSS variables used across Metabase.*/-export function getMetabaseCssVariables(theme: MantineTheme) {+export function getMetabaseCssVariables({+ theme,+ whitelabelColors,+}: {+ theme: MantineTheme;+ whitelabelColors?: ColorSettings | null;+}) {const colorScheme = theme.other?.colorScheme || "light";return css`@@ -29,18 +46,26 @@ export function getMetabaseCssVariables(theme: MantineTheme) {--mb-default-monospace-font-family: ${theme.fontFamilyMonospace};/* Semantic colors */- ${createColorVars(colorScheme)}+ ${createColorVars(colorScheme, whitelabelColors)}${getThemeSpecificCssVariables(theme)}${getDynamicCssVariables(theme)}}`;}-export function getMetabaseSdkCssVariables(theme: MantineTheme, font: string) {+export function getMetabaseSdkCssVariables({+ theme,+ font,+ whitelabelColors,+}: {+ theme: MantineTheme;+ font: string;+ whitelabelColors?: ColorSettings | null;+}) {return css`:root {--mb-default-font-family: ${font};- ${createColorVars("light")}+ ${createColorVars("light", whitelabelColors)}${getSdkDesignSystemCssVariables(theme)}${getDynamicCssVariables(theme)}${getThemeSpecificCssVariables(theme)}diff --git a/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsx b/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsxindex 30ebc1cbf1e..840b5cfc3ce 100644--- a/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsx+++ b/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsx@@ -56,12 +56,17 @@ interface ThemeProviderProps {const ThemeProviderInner = (props: ThemeProviderProps) => {const { resolvedColorScheme } = useColorScheme();- const [themeCacheBuster, setThemeCacheBuster] = useState(1);++ // We cannot use `useSetting` here due to circular dependencies,+ // and `useSelector` throws as the redux provider is not always wrapped+ const [whitelabelColors, setWhitelabelColors] = useState(+ MetabaseSettings.applicationColors(),+ );// Merge default theme overrides with user-provided theme overridesconst theme = useMemo(() => {const theme = merge(- getThemeOverrides(resolvedColorScheme),+ getThemeOverrides(resolvedColorScheme, whitelabelColors),props.theme,) as MantineTheme;@@ -69,9 +74,9 @@ const ThemeProviderInner = (props: ThemeProviderProps) => {...theme,other: {...theme.other,- updateColorSettings: (newValue) => {- mutateColors(newValue);- setThemeCacheBuster(themeCacheBuster + 1);+ updateColorSettings: (nextWhitelabeledColors) => {+ mutateColors(nextWhitelabeledColors);+ setWhitelabelColors(nextWhitelabeledColors);},},fn: {@@ -84,7 +89,7 @@ const ThemeProviderInner = (props: ThemeProviderProps) => {},},} as MantineTheme;- }, [props.theme, resolvedColorScheme, themeCacheBuster]);+ }, [props.theme, resolvedColorScheme, whitelabelColors]);const { withCssVariables, withGlobalClasses } =useContext(ThemeProviderContext);diff --git a/frontend/src/metabase/ui/theme.ts b/frontend/src/metabase/ui/theme.tsindex e75fdb29549..46ae9081811 100644--- a/frontend/src/metabase/ui/theme.ts+++ b/frontend/src/metabase/ui/theme.ts@@ -2,6 +2,7 @@ import type { MantineThemeOverride } from "@mantine/core";import { rem } from "@mantine/core";import { DEFAULT_METABASE_COMPONENT_THEME } from "metabase/embedding-sdk/theme";+import type { ColorSettings } from "metabase-types/api";import Styles from "./Theme.module.css";import {@@ -57,7 +58,7 @@ import {titleOverrides,tooltipOverrides,} from "./components";-import { getThemeColors } from "./utils/colors";+import { getMantineThemeColors } from "./utils/colors";export const breakpoints = {xs: "23em",@@ -70,10 +71,11 @@ export type BreakpointName = keyof typeof breakpoints;export const getThemeOverrides = (colorScheme: "light" | "dark" = "light",+ whitelabelColors?: ColorSettings | null,): MantineThemeOverride => ({focusClassName: Styles.focus,breakpoints,- colors: getThemeColors(colorScheme),+ colors: getMantineThemeColors(colorScheme, whitelabelColors),primaryColor: "brand",primaryShade: 0,// Store colorScheme in other property for access laterdiff --git a/frontend/src/metabase/ui/utils/colors.ts b/frontend/src/metabase/ui/utils/colors.tsindex 2a8020dcb4e..af1079a8a08 100644--- a/frontend/src/metabase/ui/utils/colors.ts+++ b/frontend/src/metabase/ui/utils/colors.ts@@ -1,9 +1,9 @@import type { MantineColorsTuple } from "@mantine/core";-import { colorConfig } from "metabase/lib/colors";-import type { ColorName } from "metabase/lib/colors/types";--export const ALL_COLOR_NAMES = Object.keys(colorConfig);+import type { ResolvedColorScheme } from "metabase/lib/color-scheme";+import { ALL_COLOR_NAMES, deriveFullMetabaseTheme } from "metabase/lib/colors";+import type { ColorName, MetabaseColorKey } from "metabase/lib/colors/types";+import type { ColorSettings } from "metabase-types/api";const ORIGINAL_COLORS = ["dark",@@ -38,17 +38,20 @@ export function getColorShades(colorName: string): MantineColorsTuple {];}-export function getThemeColors(- colorScheme: "light" | "dark",+export function getMantineThemeColors(+ colorScheme: ResolvedColorScheme,+ whitelabelColors?: ColorSettings | null,): Record<string, MantineColorsTuple> {+ const { colors } = deriveFullMetabaseTheme({ colorScheme, whitelabelColors });+return {...Object.fromEntries(ORIGINAL_COLORS.map((name) => [name, getColorShades("transparent")]),),...Object.fromEntries(- Object.entries(colorConfig).map(([name, colors]) => [+ Object.entries(colors).map(([name, value]) => [name,- getColorShades(colors[colorScheme] || colors.light),+ getColorShades(value),]),),};@@ -64,7 +67,7 @@ export function color(colorName: ColorName): string {}export const isColorName = (name?: string | null): name is ColorName => {- return !!name && ALL_COLOR_NAMES.includes(name);+ return !!name && ALL_COLOR_NAMES.includes(name as MetabaseColorKey);};/**diff --git a/frontend/test/__support__/ui.tsx b/frontend/test/__support__/ui.tsxindex df56abb1731..fbca4786697 100644--- a/frontend/test/__support__/ui.tsx+++ b/frontend/test/__support__/ui.tsx@@ -228,7 +228,11 @@ export function getTestStoreAndWrapper({**/const GlobalStylesForTest = () => {const theme = useMantineTheme();- const cssVariables = useMemo(() => getMetabaseCssVariables(theme), [theme]);++ const cssVariables = useMemo(() => {+ return getMetabaseCssVariables({ theme });+ }, [theme]);+return <Global styles={[baseStyle, cssVariables]} />;};