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
Use Ocean stops for the default brand ramp (#82853)
Oleh Ke22d727172aa
diff --git a/enterprise/frontend/src/metabase-enterprise/user_provisioning/components/ScimInputs.tsx b/enterprise/frontend/src/metabase-enterprise/user_provisioning/components/ScimInputs.tsxindex 150fc66837f..991a71e821b 100644--- a/enterprise/frontend/src/metabase-enterprise/user_provisioning/components/ScimInputs.tsx+++ b/enterprise/frontend/src/metabase-enterprise/user_provisioning/components/ScimInputs.tsx@@ -2,10 +2,6 @@ import { match } from "ts-pattern";import type { CopyTextInputProps } from "metabase/common/components/CopyTextInput";import { CopyTextInput } from "metabase/common/components/CopyTextInput";-import { getThemeOverrides } from "metabase/ui/theme";--// Unjustified type cast. FIXME-const fontFamilyMonospace = getThemeOverrides().fontFamilyMonospace as string;// why are we overriding the default styles?export const getTextInputStyles = (params: {@@ -23,7 +19,7 @@ export const getTextInputStyles = (params: {() => `var(--mb-color-text-primary) !important`,).otherwise(() => `var(--mb-color-text-primary) !important`),- fontFamily: fontFamilyMonospace,+ fontFamily: "var(--mb-default-monospace-font-family)",},});diff --git a/enterprise/frontend/src/metabase-enterprise/whitelabel/components/ColorSettings/ColorSettings.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/whitelabel/components/ColorSettings/ColorSettings.unit.spec.tsxindex 0ffc3677a12..41aab6b66d4 100644--- a/enterprise/frontend/src/metabase-enterprise/whitelabel/components/ColorSettings/ColorSettings.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/whitelabel/components/ColorSettings/ColorSettings.unit.spec.tsx@@ -2,105 +2,96 @@ import userEvent from "@testing-library/user-event";import Color from "color";import { render, screen } from "__support__/ui";-import { colors, staticVizOverrides } from "metabase/ui/colors/colors";+import { colors } from "metabase/ui/colors/colors";import { color } from "metabase/ui/colors/palette";+import type { ColorSettings as ColorSettingsType } from "metabase-types/api";import { ColorSettings } from "./ColorSettings";-describe("ColorSettings", () => {- const textMediumHex = Color(- color("text-secondary", staticVizOverrides),- ).hex();- const textLightHex = Color(color("text-disabled", staticVizOverrides)).hex();+const BRAND = "#123456";+const ACCENT1 = "#2A9D8F";+const NEW_ACCENT1 = "#E76F51";+const NEW_SUMMARIZE = "#8E44AD";++const DEFAULT_COLORS = {+ brand: BRAND,+ accent1: ACCENT1,+};++interface SetupOpts {+ initialColors?: ColorSettingsType;+}++const setup = ({ initialColors = DEFAULT_COLORS }: SetupOpts = {}) => {+ const onChange = jest.fn();- const initialColors = {- brand: color("core-filter"),- accent1: textMediumHex,- };+ render(+ <ColorSettings+ initialColors={initialColors}+ themeColors={colors}+ onChange={onChange}+ />,+ );+ return { onChange };+};++describe("ColorSettings", () => {it("should update brand colors", async () => {- const onChange = jest.fn();-- render(- <ColorSettings- initialColors={initialColors}- themeColors={colors}- onChange={onChange}- />,- );+ const { onChange } = setup();const input = screen.getByPlaceholderText(Color(color("core-summarize")).hex(),);await userEvent.clear(input);- await userEvent.type(input, color("feedback-negative"));+ await userEvent.type(input, NEW_SUMMARIZE);expect(onChange).toHaveBeenLastCalledWith({- brand: color("core-filter"),- /* Needs to convert this to hex because the input is transform to hex,- * but we want to use hsla for our new colors, this is to allow better text search. */- summarize: Color(color("feedback-negative")).hex(),- accent1: textMediumHex,+ brand: BRAND,+ summarize: NEW_SUMMARIZE,+ accent1: ACCENT1,});});+ it("should drop the key when a brand color is cleared", async () => {+ const { onChange } = setup();++ await userEvent.clear(screen.getByDisplayValue(BRAND));++ expect(onChange).toHaveBeenLastCalledWith({ accent1: ACCENT1 });+ });+it("should update chart colors", async () => {- const onChange = jest.fn();-- render(- <ColorSettings- initialColors={initialColors}- themeColors={colors}- onChange={onChange}- />,- );+ const { onChange } = setup();- const input = screen.getByDisplayValue(textMediumHex);+ const input = screen.getByDisplayValue(ACCENT1);await userEvent.clear(input);- await userEvent.type(input, textLightHex);+ await userEvent.type(input, NEW_ACCENT1);expect(onChange).toHaveBeenLastCalledWith({- brand: color("core-filter"),- accent1: textLightHex,+ brand: BRAND,+ accent1: NEW_ACCENT1,});});it("should reset chart colors", async () => {- const onChange = jest.fn();-- render(- <ColorSettings- initialColors={initialColors}- themeColors={colors}- onChange={onChange}- />,- );+ const { onChange } = setup();await userEvent.click(screen.getByText("Reset to default colors"));await userEvent.click(screen.getByText("Reset"));- expect(onChange).toHaveBeenLastCalledWith({- brand: color("core-filter"),- });+ expect(onChange).toHaveBeenLastCalledWith({ brand: BRAND });});it("should generate chart colors", async () => {- const onChange = jest.fn();-- render(- <ColorSettings- initialColors={initialColors}- themeColors={colors}- onChange={onChange}- />,- );+ const { onChange } = setup();await userEvent.click(screen.getByText("Generate chart colors"));expect(onChange).toHaveBeenLastCalledWith({- brand: color("core-filter"),+ brand: BRAND,accent0: expect.any(String),- accent1: textMediumHex,+ accent1: ACCENT1,accent2: expect.any(String),accent3: expect.any(String),accent4: expect.any(String),diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.tsxindex ba8d296b3b5..c25d5abb7c1 100644--- a/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.tsx+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.tsx@@ -9,6 +9,7 @@ import { EnsureSingleInstance } from "embedding-sdk-shared/components/EnsureSingimport {type MetabaseEmbeddingTheme,isEmbeddingThemeV1,+ isEmbeddingThemeV2,} from "metabase/embedding-sdk/theme";import { MetabaseReduxProvider, useSelector } from "metabase/redux";import { useSetting } from "metabase/settings";@@ -39,6 +40,16 @@ export const SdkThemeProvider = ({ theme, children }: Props) => {const resolvedColorScheme = getResolvedColorSchemeFromTheme(theme);+ const whitelabelColors = useSetting("application-colors");++ const themeBrandColor = isEmbeddingThemeV2(theme)+ ? (theme.colors?.["core-brand"] ?? theme.colors?.brand)+ : theme?.colors?.brand;++ const hasCustomBrandColor = Boolean(+ themeBrandColor ?? whitelabelColors?.brand,+ );+const { withCssVariables, withGlobalClasses } =useContext(ThemeProviderContext);@@ -60,8 +71,13 @@ export const SdkThemeProvider = ({ theme, children }: Props) => {theme={themeOverride}resolvedColorScheme={resolvedColorScheme}cssVariablesSelector=".mb-wrapper"+ forceDynamicBrandRamp={hasCustomBrandColor}>- {isInstanceToRender && <GlobalSdkCssVariables />}+ {isInstanceToRender && (+ <GlobalSdkCssVariables+ forceDynamicBrandRamp={hasCustomBrandColor}+ />+ )}{children}</ThemeProvider>@@ -88,7 +104,11 @@ export const SdkThemeProviderWithStore = ({</MetabaseReduxProvider>);-function GlobalSdkCssVariables() {+function GlobalSdkCssVariables({+ forceDynamicBrandRamp,+}: {+ forceDynamicBrandRamp: boolean;+}) {const theme = useMantineTheme();const whitelabelColors = useSetting("application-colors");@@ -96,8 +116,13 @@ function GlobalSdkCssVariables() {const font = useSelector(getFont) ?? DEFAULT_FONT;const styles = useMemo(() => {- return getMetabaseSdkCssVariables({ theme, font, whitelabelColors });- }, [theme, font, whitelabelColors]);+ return getMetabaseSdkCssVariables({+ theme,+ font,+ whitelabelColors,+ forceDynamicBrandRamp,+ });+ }, [theme, font, whitelabelColors, forceDynamicBrandRamp]);return <Global styles={styles} />;}diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.unit.spec.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.unit.spec.tsxindex 466bebc7e2c..3a5b82b6e70 100644--- a/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.unit.spec.tsx+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.unit.spec.tsx@@ -1,18 +1,22 @@import { waitFor } from "@testing-library/react";import { useEffect } from "react";+import { mockSettings } from "__support__/settings";+import { createMockState } from "__support__/state";import { renderWithProviders } from "__support__/ui";import { SdkThemeProvider } from "embedding-sdk-bundle/components/private/SdkThemeProvider";import { DEFAULT_FONT } from "embedding-sdk-bundle/config";import { ensureMetabaseProviderPropsStore } from "embedding-sdk-shared/lib/ensure-metabase-provider-props-store";+import type { MetabaseEmbeddingTheme } from "metabase/embedding-sdk/theme";import { getMetabaseSdkCssVariables } from "metabase/styled-components/theme/css-variables";import { useMantineTheme } from "metabase/ui";-import { METABASE_DARK_THEME, METABASE_LIGHT_THEME } from "metabase/ui/colors";+import { getDarkTheme, getLightTheme } from "metabase/ui/colors";+import { getBaseColorsForThemeDefinitionOnly } from "metabase/ui/colors/constants/base-colors";const EXAMPLE_COLOR = "background_page-primary-inverse";-const LIGHT_EXAMPLE_VALUE = METABASE_LIGHT_THEME.colors[EXAMPLE_COLOR];-const DARK_EXAMPLE_VALUE = METABASE_DARK_THEME.colors[EXAMPLE_COLOR];+const LIGHT_EXAMPLE_VALUE = getLightTheme().colors[EXAMPLE_COLOR];+const DARK_EXAMPLE_VALUE = getDarkTheme().colors[EXAMPLE_COLOR];const THEME_CASES = [// V1 themes@@ -69,16 +73,30 @@ const SdkCssVariablesTester = ({};const renderSdkThemeProvider = (- theme: React.ComponentProps<typeof SdkThemeProvider>["theme"],+ theme: MetabaseEmbeddingTheme | undefined,onCssVariablesChange: (cssVariables: string) => void,+ whitelabelColors?: Record<string, string>,) =>renderWithProviders(<SdkThemeProvider theme={theme}><div className="mb-wrapper">SDK content</div><SdkCssVariablesTester onChange={onCssVariablesChange} /></SdkThemeProvider>,+ whitelabelColors && {+ storeInitialState: createMockState({+ settings: mockSettings({ "application-colors": whitelabelColors }),+ }),+ },);+// Emitted styles can contain redefinition of same variable with different value, so we can't rely on simple+// `.toContain` checks, instead we need to extract last definition which is what would be actually applied by browser+const getLastCssVariableValue = (cssVariables: string, variable: string) =>+ [...cssVariables.matchAll(new RegExp(`${variable}:\\s*([^;]+);`, "g"))]+ .at(-1)+ ?.at(1)+ ?.trim();+describe("SdkThemeProvider", () => {beforeEach(() => {ensureMetabaseProviderPropsStore().cleanup();@@ -106,6 +124,118 @@ describe("SdkThemeProvider", () => {);});+ describe("brand ramp", () => {+ const { ocean } = getBaseColorsForThemeDefinitionOnly();++ // Light defines `text-hover`/`text-brand` off brand[60]/[50], dark off brand[30]/[40]+ const LIGHT_OCEAN = { textHover: ocean[60], textBrand: ocean[50] };+ const DARK_OCEAN = { textHover: ocean[30], textBrand: ocean[40] };++ // We need to check what was actually injected into page, thus+ // direct query (unlike other tests that use SdkCssVariablesTester)+ const emittedStyles = () =>+ // eslint-disable-next-line testing-library/no-node-access -- emotion writes these <style> tags; there is no Testing Library query for them+ [...document.querySelectorAll("style")]+ .map((element) => element.textContent ?? "")+ .join("\n");++ const setup = async (+ theme: MetabaseEmbeddingTheme | undefined,+ whitelabelColors?: Record<string, string>,+ ) => {+ renderSdkThemeProvider(theme, jest.fn(), whitelabelColors);++ await waitFor(() =>+ expect(emittedStyles()).toContain("--mb-color-text-brand:"),+ );++ return {+ getCssVariable: (variable: string) =>+ getLastCssVariableValue(emittedStyles(), variable),+ };+ };++ it.each([+ ["a V1 theme", { colors: { brand: "#DF75E9" } }],+ ["a V2 theme", { version: 2 as const, colors: { brand: "#DF75E9" } }],+ [+ "a dark V1 theme",+ { preset: "dark" as const, colors: { brand: "#DF75E9" } },+ ],+ ])("tracks a brand color from %s", async (_name, theme) => {+ const { getCssVariable } = await setup(theme);++ expect(getCssVariable("--mb-color-core-brand")).toBe("#DF75E9");+ expect(getCssVariable("--mb-color-text-hover")).toContain(+ "var(--mb-color-core-brand)",+ );+ expect(getCssVariable("--mb-color-text-brand-hover")).toContain(+ "var(--mb-color-core-brand)",+ );+ expect(getCssVariable("--mb-color-text-brand")).toContain(+ "var(--mb-color-core-brand)",+ );+ });++ it.each([+ ["no theme", undefined],+ [+ "a theme that sets a different color",+ { colors: { border: "#3B3F3F" } },+ ],+ ])("tracks a whitelabel brand color given %s", async (_name, theme) => {+ const { getCssVariable } = await setup(theme, { brand: "#DF75E9" });++ expect(getCssVariable("--mb-color-text-hover")).toContain(+ "var(--mb-color-core-brand)",+ );+ expect(getCssVariable("--mb-color-text-brand")).toContain(+ "var(--mb-color-core-brand)",+ );+ });++ it("keeps the SDK theme brand when whitelabel also sets one", async () => {+ const { getCssVariable } = await setup(+ { colors: { brand: "#DF75E9" } },+ {+ brand: "#00FF00",+ },+ );++ expect(getCssVariable("--mb-color-core-brand")).toBe("#DF75E9");+ expect(getCssVariable("--mb-color-text-brand")).toContain(+ "var(--mb-color-core-brand)",+ );+ });++ it.each([+ ["no theme", undefined, LIGHT_OCEAN],+ [+ "a V1 theme without a brand",+ { colors: { "text-primary": "#111111" } },+ LIGHT_OCEAN,+ ],+ [+ "a V2 theme without a brand",+ { version: 2 as const, colors: { "text-primary": "#111111" } },+ LIGHT_OCEAN,+ ],+ ["a dark theme without a brand", { preset: "dark" as const }, DARK_OCEAN],+ ])(+ "replaces the brand ramp with Ocean given %s",+ async (_name, theme, expected) => {+ const { getCssVariable } = await setup(theme);++ expect(getCssVariable("--mb-color-text-hover")).toBe(+ expected.textHover,+ );+ expect(getCssVariable("--mb-color-text-brand")).toBe(+ expected.textBrand,+ );+ },+ );+ });+it.each(THEME_CASES)("$themeName base color variables are color scheme dependent",async ({ theme, expectedColor, unexpectedColor }) => {diff --git a/frontend/src/embedding-sdk-shared/test/storybook-themes.ts b/frontend/src/embedding-sdk-shared/test/storybook-themes.tsindex a991f23204c..fe6f445412d 100644--- a/frontend/src/embedding-sdk-shared/test/storybook-themes.ts+++ b/frontend/src/embedding-sdk-shared/test/storybook-themes.ts@@ -2,7 +2,7 @@ import {type MetabaseEmbeddingTheme,defineMetabaseTheme,} from "metabase/embedding-sdk/theme";-import { METABASE_DARK_THEME } from "metabase/ui/colors/constants/themes/dark";+import { getDarkTheme } from "metabase/ui/colors/constants/themes/dark";export const darkColors = {primary: "#DF75E9",@@ -317,7 +317,7 @@ export const storybookThemes: Record<> = {default: undefined,dark: darkTheme,- "dark-v2": METABASE_DARK_THEME,+ "dark-v2": getDarkTheme(),pug: pugTheme,stitch: stitchTheme,luminara: luminaraTheme,diff --git a/frontend/src/metabase/admin/embedding/hooks/use-default-embedding-themes.ts b/frontend/src/metabase/admin/embedding/hooks/use-default-embedding-themes.tsindex 1bb273206d4..2957905a752 100644--- a/frontend/src/metabase/admin/embedding/hooks/use-default-embedding-themes.ts+++ b/frontend/src/metabase/admin/embedding/hooks/use-default-embedding-themes.ts@@ -8,8 +8,8 @@ import { deriveSdkThemeSettings } from "../utils/derive-sdk-theme-settings";/*** Returns the default `Light` and `Dark` embedding theme payloads, ready to be sent to the- * `POST /api/embed-theme/seed-defaults` endpoint. Colors are derived from `METABASE_LIGHT_THEME`- * / `METABASE_DARK_THEME` via `deriveFullMetabaseTheme`, with whitelabel overrides applied on top.+ * `POST /api/embed-theme/seed-defaults` endpoint. Colors are derived from `getLightTheme`+ * / `getDarkTheme` via `deriveFullMetabaseTheme`, with whitelabel overrides applied on top.*/export function useDefaultEmbeddingThemes(): CreateEmbeddingThemeRequest[] {const whitelabelColors = useSetting("application-colors");diff --git a/frontend/src/metabase/admin/settings/components/ApiKeys/EditApiKeyModal.tsx b/frontend/src/metabase/admin/settings/components/ApiKeys/EditApiKeyModal.tsxindex 26d7197024a..52f082eecbc 100644--- a/frontend/src/metabase/admin/settings/components/ApiKeys/EditApiKeyModal.tsx+++ b/frontend/src/metabase/admin/settings/components/ApiKeys/EditApiKeyModal.tsx@@ -10,7 +10,6 @@ import {FormTextInput,} from "metabase/forms";import { Button, Group, Modal, Paper, Stack, Text } from "metabase/ui";-import { getThemeOverrides } from "metabase/ui/theme";import type { ApiKey, UpdateApiKeyRequest } from "metabase-types/api";import {@@ -22,8 +21,6 @@ import S from "./EditApiKeyModal.module.css";import { SecretKeyModal } from "./SecretKeyModal";import { getApiKeyValidationSchema } from "./utils";-const { fontFamilyMonospace } = getThemeOverrides();-type EditModalName = "edit" | "regenerate" | "secretKey";const RegenerateKeyModal = ({@@ -161,8 +158,7 @@ export const EditApiKeyModal = ({input: {// override the disabled-gray so the masked key stays readable in both themescolor: "var(--mb-color-text-primary) !important",- // Unjustified type cast. FIXME- fontFamily: fontFamilyMonospace as string,+ fontFamily: "var(--mb-default-monospace-font-family)",},}}disableddiff --git a/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.tsx b/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.tsxindex 4f3cf926bab..81e5b059af5 100644--- a/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.tsx+++ b/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.tsx@@ -22,7 +22,6 @@ import {type TreeTableColumnDef,useTreeTableInstance,} from "metabase/ui";-import { getThemeOverrides } from "metabase/ui/theme";import { formatDateTimeWithUnit } from "metabase/value-formatting";import type { ApiKey } from "metabase-types/api";@@ -34,8 +33,6 @@ import { EditApiKeyModal } from "./EditApiKeyModal";import S from "./ManageApiKeys.module.css";import { formatMaskedKey } from "./utils";-const { fontFamilyMonospace } = getThemeOverrides();-type Modal = null | "create" | "edit" | "delete";const getNodeId = (apiKey: ApiKey) => String(apiKey.id);@@ -128,7 +125,7 @@ function useApiKeyColumns({enableSorting: false,accessorFn: (apiKey) => apiKey.masked_key,cell: ({ row }) => (- <Text ff={fontFamilyMonospace}>+ <Text ff="var(--mb-default-monospace-font-family)">{formatMaskedKey(row.original.masked_key)}</Text>),diff --git a/frontend/src/metabase/querying/components/expressions/CombineColumns/ColumnAndSeparatorRow/ColumnAndSeparatorRow.tsx b/frontend/src/metabase/querying/components/expressions/CombineColumns/ColumnAndSeparatorRow/ColumnAndSeparatorRow.tsxindex 50ba53b0846..978b6149edc 100644--- a/frontend/src/metabase/querying/components/expressions/CombineColumns/ColumnAndSeparatorRow/ColumnAndSeparatorRow.tsx+++ b/frontend/src/metabase/querying/components/expressions/CombineColumns/ColumnAndSeparatorRow/ColumnAndSeparatorRow.tsx@@ -3,7 +3,6 @@ import { useState } from "react";import { t } from "ttag";import { Button, Flex, Icon, Text, TextInput, rem } from "metabase/ui";-import { getThemeOverrides } from "metabase/ui/theme";import type * as Lib from "metabase-lib";import { formatSeparator, label } from "../util";@@ -77,8 +76,6 @@ export const ColumnAndSeparatorRow = ({);};-const { fontFamilyMonospace } = getThemeOverrides();-function SeparatorInput({showSeparator,value,@@ -121,8 +118,7 @@ function SeparatorInput({onBlur={handleBlur}styles={{input: {- // Unjustified type cast. FIXME- fontFamily: fontFamilyMonospace as string,+ fontFamily: "var(--mb-default-monospace-font-family)",},}}/>diff --git a/frontend/src/metabase/querying/components/expressions/CombineColumns/ColumnAndSeparatorRow/ColumnInput.tsx b/frontend/src/metabase/querying/components/expressions/CombineColumns/ColumnAndSeparatorRow/ColumnInput.tsxindex 33907f3b739..6066798641e 100644--- a/frontend/src/metabase/querying/components/expressions/CombineColumns/ColumnAndSeparatorRow/ColumnInput.tsx+++ b/frontend/src/metabase/querying/components/expressions/CombineColumns/ColumnAndSeparatorRow/ColumnInput.tsx@@ -4,9 +4,15 @@ import { useMemo, useRef, useState } from "react";import { t } from "ttag";import { QueryColumnPicker } from "metabase/querying/common/components/QueryColumnPicker";-import { Button, FocusTrap, Icon, Input, Popover } from "metabase/ui";+import {+ Button,+ FocusTrap,+ Icon,+ Input,+ Popover,+ useMantineTheme,+} from "metabase/ui";import { color } from "metabase/ui/colors";-import { getThemeOverrides } from "metabase/ui/theme";import * as Lib from "metabase-lib";import styles from "./ColumnInput.module.css";@@ -20,8 +26,6 @@ type ColumnInputProps = {onChange: (column: Lib.ColumnMetadata | null) => void;};-const theme = getThemeOverrides();-export function ColumnInput({query,stageIndex,@@ -30,6 +34,7 @@ export function ColumnInput({value,onChange,}: ColumnInputProps) {+ const theme = useMantineTheme();const columnGroups = useMemo(() => Lib.groupColumns(columns), [columns]);const [open, setOpen] = useState(false);@@ -98,8 +103,8 @@ export function ColumnInput({styles={{root: { width: "100%" },label: {- marginBottom: theme.spacing?.xxs,- fontSize: theme.fontSizes?.md,+ marginBottom: theme.spacing.xxs,+ fontSize: theme.fontSizes.md,color: color("text-secondary"),},}}diff --git a/frontend/src/metabase/styled-components/theme/css-variables.ts b/frontend/src/metabase/styled-components/theme/css-variables.tsindex 9a69079391f..5e28ec8fb5d 100644--- a/frontend/src/metabase/styled-components/theme/css-variables.ts+++ b/frontend/src/metabase/styled-components/theme/css-variables.ts@@ -22,13 +22,19 @@ import type { ResolvedColorScheme } from "metabase/utils/color-scheme";import { getFontFamilyValue } from "metabase/utils/fonts";import type { ColorSettings } from "metabase-types/api";-const createColorVars = (- colorScheme: ResolvedColorScheme,- whitelabelColors?: ColorSettings | null,-): string => {+const createColorVars = ({+ colorScheme,+ whitelabelColors,+ forceDynamicBrandRamp,+}: {+ colorScheme: ResolvedColorScheme;+ whitelabelColors?: ColorSettings | null;+ forceDynamicBrandRamp?: boolean;+}): string => {const theme = deriveFullMetabaseTheme({colorScheme,whitelabelColors,+ forceDynamicBrandRamp,});return Object.entries(theme.colors)@@ -53,7 +59,7 @@ export function getMetabaseCssVariables({--mb-default-monospace-font-family: ${theme.fontFamilyMonospace};/* Semantic colors */- ${createColorVars(colorScheme, whitelabelColors)}+ ${createColorVars({ colorScheme, whitelabelColors })}${getThemeSpecificCssVariables(theme)}${getDynamicCssVariables(theme)}}@@ -64,10 +70,12 @@ export function getMetabaseSdkCssVariables({theme,font,whitelabelColors,+ forceDynamicBrandRamp,}: {theme: MantineTheme;font: string;whitelabelColors?: ColorSettings | null;+ forceDynamicBrandRamp?: boolean;}) {const colorScheme = getIsDarkThemeFromPalette(theme) ? "dark" : "light";@@ -75,7 +83,11 @@ export function getMetabaseSdkCssVariables({:root {--mb-default-font-family: ${getFontFamilyValue(font)};--mb-default-monospace-font-family: ${theme.fontFamilyMonospace};- ${createColorVars(colorScheme, whitelabelColors)}+ ${createColorVars({+ colorScheme,+ whitelabelColors,+ forceDynamicBrandRamp,+ })}${getSdkDesignSystemCssVariables(theme)}${getDynamicCssVariables(theme)}${getThemeSpecificCssVariables(theme)}diff --git a/frontend/src/metabase/styled-components/theme/css-variables.unit.spec.ts b/frontend/src/metabase/styled-components/theme/css-variables.unit.spec.tsindex dfd208460da..2ddfea52e75 100644--- a/frontend/src/metabase/styled-components/theme/css-variables.unit.spec.ts+++ b/frontend/src/metabase/styled-components/theme/css-variables.unit.spec.ts@@ -1,6 +1,28 @@import type { MantineTheme } from "metabase/ui";+import { getBaseColorsForThemeDefinitionOnly } from "metabase/ui/colors/constants/base-colors";-import { getThemeSpecificCssVariables } from "./css-variables";+import {+ getMetabaseSdkCssVariables,+ getThemeSpecificCssVariables,+} from "./css-variables";++const baseColors = getBaseColorsForThemeDefinitionOnly();++// `text-brand` is defined off `brand[50]`, so it is dynamic or Ocean depending on+// whether a brand color is in play.+const TEXT_BRAND_RAMP = baseColors.brand[50];+const TEXT_BRAND_OCEAN = baseColors.ocean[50];++const createSdkTheme = (colors: Record<string, string>) =>+ // The helpers under test read only these fields off the theme, so a stub carrying+ // them stands in for a full Mantine theme.+ ({+ fontFamilyMonospace: "monospace",+ fn: {+ themeColor: (name: string) => colors[name] ?? "#ffffff",+ },+ other: {},+ }) as MantineTheme;describe("getThemeSpecificCssVariables", () => {it("returns the correct CSS variables", () => {@@ -22,3 +44,25 @@ describe("getThemeSpecificCssVariables", () => {expect(styles).toContain("--mb-color-bg-dashboard-card: purple;");});});++describe("getMetabaseSdkCssVariables", () => {+ it("keeps the brand ramp dynamic when forceDynamicBrandRamp is set", () => {+ const styles = getMetabaseSdkCssVariables({+ theme: createSdkTheme({ "core-brand": "#DF75E9" }),+ font: "Lato",+ forceDynamicBrandRamp: true,+ }).styles;++ expect(styles).toContain(`--mb-color-text-brand: ${TEXT_BRAND_RAMP};`);+ expect(styles).not.toContain(`--mb-color-text-brand: ${TEXT_BRAND_OCEAN};`);+ });++ it("replaces the brand ramp with Ocean when forceDynamicBrandRamp is not set", () => {+ const styles = getMetabaseSdkCssVariables({+ theme: createSdkTheme({}),+ font: "Lato",+ }).styles;++ expect(styles).toContain(`--mb-color-text-brand: ${TEXT_BRAND_OCEAN};`);+ });+});diff --git a/frontend/src/metabase/ui/colors/constants/color-names.ts b/frontend/src/metabase/ui/colors/constants/color-names.tsindex 441e0c9a177..89ed790ab54 100644--- a/frontend/src/metabase/ui/colors/constants/color-names.ts+++ b/frontend/src/metabase/ui/colors/constants/color-names.ts@@ -2,9 +2,9 @@ import type { MetabaseColorKey } from "../types";import { DERIVED_COLOR_KEYS } from "../types/theme";import { ALL_ACCENT_COLOR_NAMES } from "./accents";-import { METABASE_LIGHT_THEME } from "./themes/light";+import { getLightTheme } from "./themes/light";/** All color names available in Metabase themes. */-export const ALL_COLOR_NAMES = Object.keys(METABASE_LIGHT_THEME.colors)+export const ALL_COLOR_NAMES = Object.keys(getLightTheme().colors).concat(ALL_ACCENT_COLOR_NAMES).concat(DERIVED_COLOR_KEYS) as MetabaseColorKey[];diff --git a/frontend/src/metabase/ui/colors/constants/themes/dark.ts b/frontend/src/metabase/ui/colors/constants/themes/dark.tsindex e5c2c2f54b0..78e2e24b8a1 100644--- a/frontend/src/metabase/ui/colors/constants/themes/dark.ts+++ b/frontend/src/metabase/ui/colors/constants/themes/dark.ts@@ -5,17 +5,19 @@ import { getBaseColorsForThemeDefinitionOnly } from "../base-colors";const baseColors = getBaseColorsForThemeDefinitionOnly();+type BrandRamp = typeof baseColors.brand;+// `orion[110]` at 20% opacity. Kept off the alpha scale because `orionAlpha` is// based on `orion[100]`.const ORION_110_ALPHA_20 = "hsla(205, 63%, 5%, 0.2)";// To be removed once the rename in GDGT-2517 is complete. Prefer the keys in// `actualColors` below.-const deprecatedColors = {+const getDeprecatedColors = (brand: BrandRamp) => ({"admin-navbar": baseColors.octopus[80],"admin-navbar-secondary": baseColors.octopus[60],"admin-navbar-inverse": baseColors.octopus[60],- "background-brand": baseColors.brand[90],+ "background-brand": brand[90],"background-filter": baseColors.filter[90],"background-disabled": baseColors.orionAlphaInverse[10],"background-disabled-inverse": baseColors.orionAlpha[10],@@ -37,21 +39,21 @@ const deprecatedColors = {"background-success": baseColors.palm[90],"background-success-secondary": baseColors.palm[70],brand: baseColors.blue[40],- "brand-hover": baseColors.brand[30],+ "brand-hover": brand[30],danger: baseColors.lobster[50],error: baseColors.lobster[50],filter: baseColors.octopus[40],focus: baseColors.blue[70],- "icon-brand": baseColors.brand[40], // Matches text-brand- "icon-brand-inverse": baseColors.brand[50],+ "icon-brand": brand[40], // Matches text-brand+ "icon-brand-inverse": brand[50],"icon-primary": baseColors.orionAlphaInverse[80], // Matches text-primary"icon-primary-inverse": baseColors.orionAlpha[80], // Matches text-primary-inverse"icon-disabled": baseColors.orionAlphaInverse[40], // Matches text-disabled"icon-disabled-inverse": baseColors.orionAlpha[40], // Matches text-disabled-inverse"icon-secondary": baseColors.orionAlphaInverse[60], // Matches text-secondary"icon-secondary-inverse": baseColors.orionAlpha[60], // Matches text-secondary-inverse- "illustration-brand-secondary": baseColors.brand[80],- "illustration-brand-tertiary": baseColors.brand[90],+ "illustration-brand-secondary": brand[80],+ "illustration-brand-tertiary": brand[90],"metabase-brand": baseColors.blue[40],"metabase-brand-hover": baseColors.blue[50],"saturated-blue": baseColors.ocean[40],@@ -67,7 +69,7 @@ const deprecatedColors = {"syntax-parameters": baseColors.mango[40],"text-tertiary": baseColors.orionAlphaInverse[40],"text-tertiary-inverse": baseColors.orionAlpha[40],- "text-hover": baseColors.brand[30],+ "text-hover": brand[30],"text-secondary-opaque": baseColors.orion[20],warning: baseColors.dubloon[30],"background-warning": baseColors.dubloon[90],@@ -83,9 +85,9 @@ const deprecatedColors = {"upsell-primary": baseColors.ocean[30],"upsell-secondary": baseColors.ocean[80],"upsell-gem": baseColors.upsellGem,-};+});-const actualColors = {+const getActualColors = (brand: BrandRamp) => ({"background_page-filter": baseColors.filter[90],"background_page-highlighted":"color-mix(in srgb, var(--mb-color-core-brand) 7%, transparent)",@@ -95,9 +97,9 @@ const actualColors = {"background_page-secondary-inverse": baseColors.orion[5],"background_page-tertiary": baseColors.orion[110],"background_page-tertiary-inverse": baseColors.orion[10],- "background_surface-brand-strong": baseColors.brand[20],- "background_surface-brand-strong-hover": baseColors.brand[10],- "background_surface-brand-strong-pressed": baseColors.brand[20],+ "background_surface-brand-strong": brand[20],+ "background_surface-brand-strong-hover": brand[10],+ "background_surface-brand-strong-pressed": brand[20],"background_surface-brand-subtle":"color-mix(in srgb, var(--mb-color-core-brand) 10%, transparent)","background_surface-brand-subtle-hover":@@ -127,9 +129,9 @@ const actualColors = {"background_surface-success": baseColors.palm[90],"background_surface-warning": baseColors.dubloon[90],"background_surface-warning-strong": baseColors.dubloon[70],- "border-brand": baseColors.brand[80],+ "border-brand": brand[80],"border-filter": baseColors.filter[80],- "border-highlight": baseColors.brand[30],+ "border-highlight": brand[30],"border-neutral": baseColors.orionAlphaInverse[20],"border-neutral-inverse-strong": baseColors.orionAlpha[30],"border-neutral-strong": baseColors.orionAlphaInverse[30],@@ -139,9 +141,9 @@ const actualColors = {"button-default-neutral-default": baseColors.orion[95], // Matches background_surface-primary"button-default-neutral-hover": baseColors.orionAlphaInverse[20], // Matches background_surface-primary-hover"button-default-neutral-pressed": baseColors.orionAlphaInverse[10], // Matches background_surface-primary-pressed- "button-filled-brand-default": baseColors.brand[20],- "button-filled-brand-hover": baseColors.brand[10],- "button-filled-brand-pressed": baseColors.brand[20],+ "button-filled-brand-default": brand[20],+ "button-filled-brand-hover": brand[10],+ "button-filled-brand-pressed": brand[20],"button-filled-filter-default": baseColors.filter[20],"button-filled-filter-hover": baseColors.filter[10],"button-filled-filter-pressed": baseColors.filter[20],@@ -189,13 +191,13 @@ const actualColors = {"button-subtle-positive-hover": baseColors.orionAlphaInverse[20],"button-subtle-positive-pressed": baseColors.orionAlphaInverse[10],"button_label-default-neutral-default": baseColors.orionAlphaInverse[80], // Matches text-primary- "button_label-filled-brand-default": baseColors.brand[80],+ "button_label-filled-brand-default": brand[80],"button_label-filled-filter-default": baseColors.filter[80],"button_label-filled-negative-default": baseColors.lobster[80],"button_label-filled-positive-default": baseColors.palm[80],"button_label-filled-warning-default": baseColors.lobster[80],- "button_label-light-brand-default": baseColors.brand[30],- "button_label-light-brand-hover": baseColors.brand[20],+ "button_label-light-brand-default": brand[30],+ "button_label-light-brand-hover": brand[20],"button_label-light-filter-default": baseColors.filter[30],"button_label-light-filter-hover": baseColors.filter[20],"button_label-light-negative-default": baseColors.lobster[30],@@ -206,15 +208,15 @@ const actualColors = {"button_label-on_dark-disabled": baseColors.orionAlphaInverse[40],"button_label-on_dark-primary": baseColors.orionAlpha[80],"button_label-on_dark-secondary": baseColors.white,- "button_label-subtle-brand-default": baseColors.brand[30],- "button_label-subtle-brand-hover": baseColors.brand[20],+ "button_label-subtle-brand-default": brand[30],+ "button_label-subtle-brand-hover": brand[20],"button_label-subtle-negative-default": baseColors.lobster[30],"button_label-subtle-negative-hover": baseColors.lobster[20],"button_label-subtle-neutral-default": baseColors.orionAlphaInverse[80], // Matches text-primary"button_label-subtle-positive-default": baseColors.palm[30],"button_label-subtle-positive-hover": baseColors.palm[20],"core-blue-saturated": baseColors.ocean[40],- "core-brand-hover": baseColors.brand[30],+ "core-brand-hover": brand[30],"core-filter-strong": baseColors.filter[20],"core-gold": baseColors.gold,"core-green-saturated": baseColors.palm[40],@@ -234,8 +236,8 @@ const actualColors = {"feedback-positive-strong": baseColors.palm[20],"feedback-warning": baseColors.dubloon[30],"feedback-warning-strong": baseColors.dubloon[20],- "illustration-secondary-brand": baseColors.brand[80],- "illustration-tertiary-brand": baseColors.brand[90],+ "illustration-secondary-brand": brand[80],+ "illustration-tertiary-brand": brand[90],"input-background": baseColors.orionAlphaInverse[10],"input-focus": baseColors.blue[70],"modal-overlay": baseColors.orionAlpha[70],@@ -243,14 +245,14 @@ const actualColors = {"navbar-admin-inverse": baseColors.octopus[60],"navbar-admin-secondary": baseColors.octopus[60],"shadow-default": ORION_110_ALPHA_20,- "switch-checked": baseColors.brand[30],+ "switch-checked": brand[30],"switch-disabled": baseColors.orionAlphaInverse[20],"switch-unchecked": baseColors.orionAlphaInverse[40],"switch_thumb-disabled": baseColors.orionAlphaInverse[40],- "text-brand": baseColors.brand[40],- "text-brand-hover": baseColors.brand[30],- "text-brand-strong": baseColors.brand[20],- "text-brand-strong-hover": baseColors.brand[10],+ "text-brand": brand[40],+ "text-brand-hover": brand[30],+ "text-brand-strong": brand[20],+ "text-brand-strong-hover": brand[10],"text-disabled": baseColors.orionAlphaInverse[40],"text-disabled-inverse": baseColors.orionAlpha[40],"text-filter": baseColors.filter[30],@@ -265,16 +267,18 @@ const actualColors = {"tooltip-background-focused": baseColors.orion[80],"tooltip-text": baseColors.orionAlphaInverse[80],"tooltip-text-secondary": baseColors.orionAlphaInverse[60],-};+});/*** The default dark theme for Metabase.*/-export const METABASE_DARK_THEME: MetabaseThemeV2 = {+export const getDarkTheme = (+ brand: BrandRamp = baseColors.brand,+): MetabaseThemeV2 => ({version: 2,chartColors: DARK_THEME_ACCENT_COLORS,colors: {- ...deprecatedColors,- ...actualColors,+ ...getDeprecatedColors(brand),+ ...getActualColors(brand),},-};+});diff --git a/frontend/src/metabase/ui/colors/constants/themes/light.ts b/frontend/src/metabase/ui/colors/constants/themes/light.tsindex cc14aa1fc03..e04f00aef0d 100644--- a/frontend/src/metabase/ui/colors/constants/themes/light.ts+++ b/frontend/src/metabase/ui/colors/constants/themes/light.ts@@ -4,13 +4,15 @@ import { getBaseColorsForThemeDefinitionOnly } from "../base-colors";const baseColors = getBaseColorsForThemeDefinitionOnly();+type BrandRamp = typeof baseColors.brand;+// To be removed once the rename in GDGT-2517 is complete. Prefer the keys in// `actualColors` below.-const deprecatedColors = {+const getDeprecatedColors = (brand: BrandRamp) => ({"admin-navbar": baseColors.octopus[60],"admin-navbar-secondary": baseColors.octopus[40],"admin-navbar-inverse": baseColors.octopus[80],- "background-brand": baseColors.brand[10],+ "background-brand": brand[10],"background-filter": baseColors.filter[5],"background-disabled": baseColors.orionAlpha[10],"background-disabled-inverse": baseColors.orionAlphaInverse[10],@@ -32,21 +34,21 @@ const deprecatedColors = {"background-success": baseColors.palm[5],"background-success-secondary": baseColors.palm[20],brand: baseColors.blue[40],- "brand-hover": baseColors.brand[50],+ "brand-hover": brand[50],danger: baseColors.lobster[50],error: baseColors.lobster[50],filter: baseColors.octopus[50],focus: baseColors.blue[20],- "icon-brand": baseColors.brand[50], // Matches text-brand- "icon-brand-inverse": baseColors.brand[20],+ "icon-brand": brand[50], // Matches text-brand+ "icon-brand-inverse": brand[20],"icon-primary": baseColors.orionAlpha[80], // Matches text-primary"icon-primary-inverse": baseColors.orionAlphaInverse[80], // Matches text-primary-inverse"icon-disabled": baseColors.orionAlpha[40], // Matches text-disabled"icon-disabled-inverse": baseColors.orionAlphaInverse[40], // Matches text-disabled-inverse"icon-secondary": baseColors.orionAlpha[60], // Matches text-secondary"icon-secondary-inverse": baseColors.orionAlphaInverse[60], // Matches text-secondary-inverse- "illustration-brand-secondary": baseColors.brand[10],- "illustration-brand-tertiary": baseColors.brand[5],+ "illustration-brand-secondary": brand[10],+ "illustration-brand-tertiary": brand[5],"metabase-brand": baseColors.blue[40],"metabase-brand-hover": baseColors.blue[30],"saturated-blue": baseColors.ocean[60],@@ -62,7 +64,7 @@ const deprecatedColors = {"syntax-parameters": baseColors.mango[60],"text-tertiary": baseColors.orionAlpha[40],"text-tertiary-inverse": baseColors.orionAlphaInverse[40],- "text-hover": baseColors.brand[60],+ "text-hover": brand[60],"text-secondary-opaque": baseColors.orion[60],warning: baseColors.dubloon[30],"background-warning": baseColors.dubloon[5],@@ -78,9 +80,9 @@ const deprecatedColors = {"upsell-primary": baseColors.ocean[70],"upsell-secondary": baseColors.ocean[20],"upsell-gem": baseColors.upsellGem,-};+});-const actualColors = {+const getActualColors = (brand: BrandRamp) => ({"background_page-filter": baseColors.filter[5],"background_page-highlighted":"color-mix(in srgb, var(--mb-color-core-brand) 7%, transparent)",@@ -90,9 +92,9 @@ const actualColors = {"background_page-secondary-inverse": baseColors.orion[100],"background_page-tertiary": baseColors.orion[10],"background_page-tertiary-inverse": baseColors.orion[110],- "background_surface-brand-strong": baseColors.brand[60],- "background_surface-brand-strong-hover": baseColors.brand[70],- "background_surface-brand-strong-pressed": baseColors.brand[80],+ "background_surface-brand-strong": brand[60],+ "background_surface-brand-strong-hover": brand[70],+ "background_surface-brand-strong-pressed": brand[80],"background_surface-brand-subtle":"color-mix(in srgb, var(--mb-color-core-brand) 10%, transparent)","background_surface-brand-subtle-hover":@@ -125,9 +127,9 @@ const actualColors = {"background_surface-success": baseColors.palm[5],"background_surface-warning": baseColors.dubloon[5],"background_surface-warning-strong": baseColors.dubloon[20],- "border-brand": baseColors.brand[10],+ "border-brand": brand[10],"border-filter": baseColors.filter[20],- "border-highlight": baseColors.brand[60],+ "border-highlight": brand[60],"border-neutral": baseColors.orion[20],"border-neutral-inverse-strong": baseColors.orionAlphaInverse[30],"border-neutral-strong": baseColors.orionAlpha[30],@@ -137,9 +139,9 @@ const actualColors = {"button-default-neutral-default": baseColors.white, // Matches background_surface-primary"button-default-neutral-hover": baseColors.orionAlpha[10], // Matches background_surface-primary-hover"button-default-neutral-pressed": baseColors.orionAlpha[20], // Matches background_surface-primary-pressed- "button-filled-brand-default": baseColors.brand[60],- "button-filled-brand-hover": baseColors.brand[70],- "button-filled-brand-pressed": baseColors.brand[80],+ "button-filled-brand-default": brand[60],+ "button-filled-brand-hover": brand[70],+ "button-filled-brand-pressed": brand[80],"button-filled-filter-default": baseColors.filter[60],"button-filled-filter-hover": baseColors.filter[70],"button-filled-filter-pressed": baseColors.filter[80],@@ -200,8 +202,8 @@ const actualColors = {"button_label-filled-negative-default": baseColors.white,"button_label-filled-positive-default": baseColors.white,"button_label-filled-warning-default": baseColors.lobster[80],- "button_label-light-brand-default": baseColors.brand[60],- "button_label-light-brand-hover": baseColors.brand[70],+ "button_label-light-brand-default": brand[60],+ "button_label-light-brand-hover": brand[70],"button_label-light-filter-default": baseColors.filter[70],"button_label-light-filter-hover": baseColors.filter[80],"button_label-light-negative-default": baseColors.lobster[70],@@ -212,15 +214,15 @@ const actualColors = {"button_label-on_dark-disabled": baseColors.orionAlphaInverse[40],"button_label-on_dark-primary": baseColors.orionAlpha[80],"button_label-on_dark-secondary": baseColors.white,- "button_label-subtle-brand-default": baseColors.brand[60],- "button_label-subtle-brand-hover": baseColors.brand[70],+ "button_label-subtle-brand-default": brand[60],+ "button_label-subtle-brand-hover": brand[70],"button_label-subtle-negative-default": baseColors.lobster[70],"button_label-subtle-negative-hover": baseColors.lobster[80],"button_label-subtle-neutral-default": baseColors.orionAlpha[80], // Matches text-primary"button_label-subtle-positive-default": baseColors.palm[70],"button_label-subtle-positive-hover": baseColors.palm[80],"core-blue-saturated": baseColors.ocean[60],- "core-brand-hover": baseColors.brand[50],+ "core-brand-hover": brand[50],"core-filter-strong": baseColors.filter[50],"core-gold": baseColors.gold,"core-green-saturated": baseColors.palm[60],@@ -240,8 +242,8 @@ const actualColors = {"feedback-positive-strong": baseColors.palm[60],"feedback-warning": baseColors.dubloon[30],"feedback-warning-strong": baseColors.mango[60],- "illustration-secondary-brand": baseColors.brand[10],- "illustration-tertiary-brand": baseColors.brand[5],+ "illustration-secondary-brand": brand[10],+ "illustration-tertiary-brand": brand[5],"input-background": baseColors.orionAlpha[5],"input-focus": baseColors.blue[20],"modal-overlay": baseColors.orionAlpha[60],@@ -249,14 +251,14 @@ const actualColors = {"navbar-admin-inverse": baseColors.octopus[80],"navbar-admin-secondary": baseColors.octopus[40],"shadow-default": baseColors.orionAlpha[20],- "switch-checked": baseColors.brand[60],+ "switch-checked": brand[60],"switch-disabled": baseColors.orionAlpha[20],"switch-unchecked": baseColors.orionAlpha[30],"switch_thumb-disabled": baseColors.white,- "text-brand": baseColors.brand[50],- "text-brand-hover": baseColors.brand[60],- "text-brand-strong": baseColors.brand[60],- "text-brand-strong-hover": baseColors.brand[70],+ "text-brand": brand[50],+ "text-brand-hover": brand[60],+ "text-brand-strong": brand[60],+ "text-brand-strong-hover": brand[70],"text-disabled": baseColors.orionAlpha[40],"text-disabled-inverse": baseColors.orionAlphaInverse[40],"text-filter": baseColors.filter[50],@@ -271,16 +273,18 @@ const actualColors = {"tooltip-background-focused": baseColors.orion[90],"tooltip-text": baseColors.white,"tooltip-text-secondary": baseColors.orionAlphaInverse[60],-};+});/*** The default light theme for Metabase.*/-export const METABASE_LIGHT_THEME: MetabaseThemeV2 = {+export const getLightTheme = (+ brand: BrandRamp = baseColors.brand,+): MetabaseThemeV2 => ({version: 2,chartColors: LIGHT_THEME_ACCENT_COLORS,colors: {- ...deprecatedColors,- ...actualColors,+ ...getDeprecatedColors(brand),+ ...getActualColors(brand),},-};+});diff --git a/frontend/src/metabase/ui/colors/constants/themes/themes.unit.spec.ts b/frontend/src/metabase/ui/colors/constants/themes/themes.unit.spec.tsindex 575c6d5f7be..fadcc3f64e9 100644--- a/frontend/src/metabase/ui/colors/constants/themes/themes.unit.spec.ts+++ b/frontend/src/metabase/ui/colors/constants/themes/themes.unit.spec.ts@@ -1,5 +1,5 @@-import { METABASE_DARK_THEME } from "./dark";-import { METABASE_LIGHT_THEME } from "./light";+import { getDarkTheme } from "./dark";+import { getLightTheme } from "./light";// Static viz renders on the server and feeds every theme color straight into// the `color` library, which only parses literals. Anything the browser would@@ -16,8 +16,8 @@ const isWhitelabelDerived = (value: string) =>WHITELABEL_COLOR_KEYS.some((key) => value.includes(`var(--mb-color-${key})`));describe.each([- ["light", METABASE_LIGHT_THEME],- ["dark", METABASE_DARK_THEME],+ ["light", getLightTheme()],+ ["dark", getDarkTheme()],])("%s theme", (_name, theme) => {it("should define every non-whitelabel color as a literal value", () => {const offenders = Object.entries(theme.colors)diff --git a/frontend/src/metabase/ui/colors/derive-theme.ts b/frontend/src/metabase/ui/colors/derive-theme.tsindex 8627c7f872b..ea1f9519090 100644--- a/frontend/src/metabase/ui/colors/derive-theme.ts+++ b/frontend/src/metabase/ui/colors/derive-theme.ts@@ -4,6 +4,7 @@ import type { ResolvedColorScheme } from "metabase/utils/color-scheme";import type { ColorSettings } from "metabase-types/api";import { deriveAllAccentColors, mapChartColorsToAccents } from "./accents";+import { getBaseColorsForThemeDefinitionOnly } from "./constants/base-colors";import { PROTECTED_COLORS } from "./constants/protected-colors";import { getThemeFromColorScheme } from "./theme-from-color-scheme";import type {@@ -25,13 +26,13 @@ export function deriveFullMetabaseTheme({colorScheme,whitelabelColors,embeddingThemeOverride,+ forceDynamicBrandRamp = false,}: {colorScheme: ResolvedColorScheme;whitelabelColors?: ColorSettings | null;embeddingThemeOverride?: MetabaseEmbeddingThemeV2;+ forceDynamicBrandRamp?: boolean;}): 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(@@ -39,6 +40,26 @@ export function deriveFullMetabaseTheme({...PROTECTED_COLORS,);+ const embeddingColors = embeddingThemeOverride?.colors;++ // When instance doesn't have custom brand color configured, we replace brand+ // ramp (which is generated dynamically using color-mix to work with custom colors)+ // with a hand-picked `ocean` ramp+ const shouldKeepBrandRampDynamic =+ forceDynamicBrandRamp ||+ Boolean(+ embeddingColors?.["core-brand"] ??+ embeddingColors?.brand ??+ whitelabelColors?.brand,+ );++ const baseColors = getBaseColorsForThemeDefinitionOnly();++ const baseTheme = getThemeFromColorScheme(+ colorScheme,+ shouldKeepBrandRampDynamic ? baseColors.brand : baseColors.ocean,+ );+// Unjustified type cast. FIXMEconst colors = {...baseTheme.colors,diff --git a/frontend/src/metabase/ui/colors/derive-theme.unit.spec.ts b/frontend/src/metabase/ui/colors/derive-theme.unit.spec.tsindex f487ab761b9..e60987ea7d1 100644--- a/frontend/src/metabase/ui/colors/derive-theme.unit.spec.ts+++ b/frontend/src/metabase/ui/colors/derive-theme.unit.spec.ts@@ -1,8 +1,14 @@import { deriveChartShadeColor, deriveChartTintColor } from "./accents";+import { getBaseColorsForThemeDefinitionOnly } from "./constants/base-colors";import { PROTECTED_COLORS } from "./constants/protected-colors";-import { METABASE_LIGHT_THEME } from "./constants/themes/light";+import { getDarkTheme } from "./constants/themes/dark";+import { getLightTheme } from "./constants/themes/light";import { deriveFullMetabaseTheme } from "./derive-theme";+const baseColors = getBaseColorsForThemeDefinitionOnly();++const lightTheme = getLightTheme();+describe("deriveFullMetabaseTheme", () => {it("applies whitelabel colors over the base theme", () => {const derived = deriveFullMetabaseTheme({@@ -15,7 +21,7 @@ describe("deriveFullMetabaseTheme", () => {// Other colors should remain from base themeexpect(derived.colors["text-primary"]).toBe(- METABASE_LIGHT_THEME.colors["text-primary"],+ lightTheme.colors["text-primary"],);});@@ -104,14 +110,14 @@ describe("deriveFullMetabaseTheme", () => {expect(derived.colors["accent0-dark"]).toBe("#0000ff");//accent 1 should be default- expect(derived.colors["accent1"]).toBe(METABASE_LIGHT_THEME.chartColors[1]);+ expect(derived.colors["accent1"]).toBe(lightTheme.chartColors[1]);expect(derived.colors["accent1-light"]).toBe(// Unjustified type cast. FIXME- deriveChartTintColor(METABASE_LIGHT_THEME.chartColors[1] as string),+ deriveChartTintColor(lightTheme.chartColors[1] as string),);expect(derived.colors["accent1-dark"]).toBe(// Unjustified type cast. FIXME- deriveChartShadeColor(METABASE_LIGHT_THEME.chartColors[1] as string),+ deriveChartShadeColor(lightTheme.chartColors[1] as string),);//accent 2 should calculate light and dark from provided color@@ -129,4 +135,54 @@ describe("deriveFullMetabaseTheme", () => {expect(derived.colors["accent3-light"]).toBe("#4B9CD3");expect(derived.colors["accent3-dark"]).toBe(deriveChartShadeColor(base));});++ describe("brand ramp", () => {+ it.each([+ ["light" as const, getLightTheme],+ ["dark" as const, getDarkTheme],+ ])(+ "replaces the %s brand ramp with Ocean when the brand color is not customized",+ (colorScheme, getTheme) => {+ const derived = deriveFullMetabaseTheme({ colorScheme });++ expect(derived.colors).toMatchObject(getTheme(baseColors.ocean).colors);+ expect(derived.colors).not.toMatchObject(+ getTheme(baseColors.brand).colors,+ );+ },+ );++ it("keeps the dynamic brand ramp when whitelabel sets a brand color", () => {+ const derived = deriveFullMetabaseTheme({+ colorScheme: "light",+ whitelabelColors: { brand: "#ff0000" },+ });++ expect(derived.colors["text-brand"]).toBe(+ lightTheme.colors["text-brand"],+ );+ });++ it("keeps the dynamic brand ramp when an embedding theme sets a brand color", () => {+ const derived = deriveFullMetabaseTheme({+ colorScheme: "light",+ embeddingThemeOverride: { version: 2, colors: { brand: "#00ff00" } },+ });++ expect(derived.colors["text-brand"]).toBe(+ lightTheme.colors["text-brand"],+ );+ });++ it("keeps the dynamic brand ramp when the caller asks for it", () => {+ const derived = deriveFullMetabaseTheme({+ colorScheme: "light",+ forceDynamicBrandRamp: true,+ });++ expect(derived.colors["text-brand"]).toBe(+ lightTheme.colors["text-brand"],+ );+ });+ });});diff --git a/frontend/src/metabase/ui/colors/harmonies.ts b/frontend/src/metabase/ui/colors/harmonies.tsindex f19425939e2..ffbf890d49b 100644--- a/frontend/src/metabase/ui/colors/harmonies.ts+++ b/frontend/src/metabase/ui/colors/harmonies.ts@@ -1,7 +1,7 @@import Color from "color";import { DEFAULT_ACCENT_COLORS } from "./constants/accent-colors";-import { METABASE_LIGHT_THEME } from "./constants/themes/light";+import { getLightTheme } from "./constants/themes/light";type ColorInstance = ReturnType<typeof Color>;@@ -26,11 +26,13 @@ const toHex = (c: ColorInstance) => c.hex().toLowerCase();const normalize = (cssColor: string) => toHex(Color(cssColor));+const lightTheme = getLightTheme();+const FALLBACK: HarmonyColors = {- filter: normalize(METABASE_LIGHT_THEME.colors.filter),- summarize: normalize(METABASE_LIGHT_THEME.colors.summarize),- positive: normalize(METABASE_LIGHT_THEME.colors["feedback-positive"]),- negative: normalize(METABASE_LIGHT_THEME.colors["feedback-negative"]),+ filter: normalize(lightTheme.colors.filter),+ summarize: normalize(lightTheme.colors.summarize),+ positive: normalize(lightTheme.colors["feedback-positive"]),+ negative: normalize(lightTheme.colors["feedback-negative"]),charts: DEFAULT_ACCENT_COLORS.flatMap((c) => {if (c == null) {return [];diff --git a/frontend/src/metabase/ui/colors/index.ts b/frontend/src/metabase/ui/colors/index.tsindex 3a8f007a4a0..0b9dafda817 100644--- a/frontend/src/metabase/ui/colors/index.ts+++ b/frontend/src/metabase/ui/colors/index.ts@@ -2,8 +2,8 @@ export * from "./palette";export * from "./colors";export * from "./formatting-colors";-export { METABASE_DARK_THEME } from "./constants/themes/dark";-export { METABASE_LIGHT_THEME } from "./constants/themes/light";+export { getDarkTheme } from "./constants/themes/dark";+export { getLightTheme } from "./constants/themes/light";export { ALL_COLOR_NAMES } from "./constants/color-names";export type * from "./types";diff --git a/frontend/src/metabase/ui/colors/theme-from-color-scheme.ts b/frontend/src/metabase/ui/colors/theme-from-color-scheme.tsindex 44c6a1a1af5..d1d8ce532d0 100644--- a/frontend/src/metabase/ui/colors/theme-from-color-scheme.ts+++ b/frontend/src/metabase/ui/colors/theme-from-color-scheme.ts@@ -1,11 +1,14 @@import type { ResolvedColorScheme } from "metabase/utils/color-scheme";-import { METABASE_DARK_THEME } from "./constants/themes/dark";-import { METABASE_LIGHT_THEME } from "./constants/themes/light";+import { getBaseColorsForThemeDefinitionOnly } from "./constants/base-colors";+import { getDarkTheme } from "./constants/themes/dark";+import { getLightTheme } from "./constants/themes/light";import type { MetabaseThemeV2 } from "./types";-/** Returns the theme definition for a color scheme. */+const baseColors = getBaseColorsForThemeDefinitionOnly();+export const getThemeFromColorScheme = (colorScheme: ResolvedColorScheme,+ brand: typeof baseColors.brand = baseColors.brand,): MetabaseThemeV2 =>- colorScheme === "dark" ? METABASE_DARK_THEME : METABASE_LIGHT_THEME;+ colorScheme === "dark" ? getDarkTheme(brand) : getLightTheme(brand);diff --git a/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsx b/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsxindex 082f268caa4..73b7678426c 100644--- a/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsx+++ b/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsx@@ -46,6 +46,12 @@ export interface ThemeProviderProps {* CSS selector for Mantine CSS variables injection.*/cssVariablesSelector?: string;++ /**+ * Keeps brand-derived colors as `color-mix()` over `--mb-color-core-brand` instead of+ * replacing them with Ocean stops. Used by SDK.+ */+ forceDynamicBrandRamp?: boolean;}export const ThemeProvider = ({@@ -55,6 +61,7 @@ export const ThemeProvider = ({whitelabelColors,onUpdateWhitelabelColors,cssVariablesSelector,+ forceDynamicBrandRamp,}: ThemeProviderProps) => {const colorSchemeContext = useColorScheme();const resolvedColorScheme =@@ -63,7 +70,11 @@ export const ThemeProvider = ({const theme = useMemo(() => {// Unjustified type cast. FIXMEconst baseTheme = merge(- getThemeOverrides(resolvedColorScheme, whitelabelColors),+ getThemeOverrides({+ colorScheme: resolvedColorScheme,+ whitelabelColors,+ forceDynamicBrandRamp,+ }),themeOverride,) as MantineTheme;@@ -93,6 +104,7 @@ export const ThemeProvider = ({} as MantineTheme;}, [themeOverride,+ forceDynamicBrandRamp,resolvedColorScheme,whitelabelColors,onUpdateWhitelabelColors,diff --git a/frontend/src/metabase/ui/theme.ts b/frontend/src/metabase/ui/theme.tsindex a6bb9aaba91..f950c6e65ce 100644--- a/frontend/src/metabase/ui/theme.ts+++ b/frontend/src/metabase/ui/theme.ts@@ -136,13 +136,22 @@ export const breakpoints = {};export type BreakpointName = keyof typeof breakpoints;-export const getThemeOverrides = (- colorScheme: "light" | "dark" = "light",- whitelabelColors?: ColorSettings | null,-): MantineThemeOverride => ({+export const getThemeOverrides = ({+ colorScheme = "light",+ whitelabelColors,+ forceDynamicBrandRamp,+}: {+ colorScheme?: "light" | "dark";+ whitelabelColors?: ColorSettings | null;+ forceDynamicBrandRamp?: boolean;+} = {}): MantineThemeOverride => ({focusClassName: Styles.focus,breakpoints,- colors: getMantineThemeColors(colorScheme, whitelabelColors),+ colors: getMantineThemeColors({+ colorScheme,+ whitelabelColors,+ forceDynamicBrandRamp,+ }),primaryColor: "core-brand",primaryShade: 0,// Store colorScheme in other property for access laterdiff --git a/frontend/src/metabase/ui/theme.unit.spec.ts b/frontend/src/metabase/ui/theme.unit.spec.tsindex df5f9bd5f78..35dc03259b4 100644--- a/frontend/src/metabase/ui/theme.unit.spec.ts+++ b/frontend/src/metabase/ui/theme.unit.spec.ts@@ -124,12 +124,12 @@ describe("theme scales", () => {["light", LIGHT_SHADOWS],["dark", DARK_SHADOWS],] as const)("maps every elevation in %s mode", (colorScheme, expected) => {- expect(getThemeOverrides(colorScheme).shadows).toEqual(expected);+ expect(getThemeOverrides({ colorScheme }).shadows).toEqual(expected);});it("uses a stronger shadow set in dark mode", () => {- const light = getThemeOverrides("light").shadows ?? {};- const dark = getThemeOverrides("dark").shadows ?? {};+ const light = getThemeOverrides({ colorScheme: "light" }).shadows ?? {};+ const dark = getThemeOverrides({ colorScheme: "dark" }).shadows ?? {};for (const key of SHADOW_SCALE_KEYS) {expect(dark[key]).not.toEqual(light[key]);@@ -150,7 +150,8 @@ describe("theme scales", () => {describe("component defaults", () => {it("resolves every scale-based component default to a defined key", () => {- const components = getThemeOverrides("dark").components ?? {};+ const components =+ getThemeOverrides({ colorScheme: "dark" }).components ?? {};const violations: string[] = [];for (const [componentName, component] of Object.entries(components)) {diff --git a/frontend/src/metabase/ui/utils/colors.ts b/frontend/src/metabase/ui/utils/colors.tsindex 44ee16bf5bf..5835080e887 100644--- a/frontend/src/metabase/ui/utils/colors.ts+++ b/frontend/src/metabase/ui/utils/colors.ts@@ -38,11 +38,20 @@ export function getColorShades(colorName: string): MantineColorsTuple {];}-export function getMantineThemeColors(- colorScheme: ResolvedColorScheme,- whitelabelColors?: ColorSettings | null,-): Record<string, MantineColorsTuple> {- const { colors } = deriveFullMetabaseTheme({ colorScheme, whitelabelColors });+export function getMantineThemeColors({+ colorScheme,+ whitelabelColors,+ forceDynamicBrandRamp,+}: {+ colorScheme: ResolvedColorScheme;+ whitelabelColors?: ColorSettings | null;+ forceDynamicBrandRamp?: boolean;+}): Record<string, MantineColorsTuple> {+ const { colors } = deriveFullMetabaseTheme({+ colorScheme,+ whitelabelColors,+ forceDynamicBrandRamp,+ });return {...Object.fromEntries(