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
Fix EmbeddingTheme violations (#75683)
Frasere8adb6a17e42
diff --git a/frontend/src/embedding-sdk-bundle/types/ui.ts b/frontend/src/embedding-sdk-bundle/types/ui.tsindex 3ceb1673dff..cc3c5ac59c6 100644--- a/frontend/src/embedding-sdk-bundle/types/ui.ts+++ b/frontend/src/embedding-sdk-bundle/types/ui.ts@@ -36,7 +36,7 @@ export type InitializationStatus =| InitializationStatusError;export type { ButtonProps } from "metabase/ui";-export type { MetabaseFontFamily } from "metabase/ui/fonts";+export type { MetabaseFontFamily } from "metabase/utils/fonts";export type {ChartColor,MetabaseTheme,diff --git a/frontend/src/metabase-types/api/embedding-theme.ts b/frontend/src/metabase-types/api/embedding-theme.tsindex ebe4fea15e7..f0da4949151 100644--- a/frontend/src/metabase-types/api/embedding-theme.ts+++ b/frontend/src/metabase-types/api/embedding-theme.ts@@ -1,4 +1,301 @@-import type { MetabaseTheme } from "metabase/embedding-sdk/theme";+import type { CSSProperties } from "react";++import type { MetabaseFontFamily } from "metabase/utils/fonts";+import type { DeepPartial } from "metabase/utils/types";++export type MetabaseThemePreset = "light" | "dark";++/**+ * Theme configuration for embedded Metabase components.+ */+export interface MetabaseTheme {+ /**+ * Predefined theme preset to use as a base.+ */+ preset?: MetabaseThemePreset;++ /**+ * Base font size.+ * Supported units are px, em and rem.+ * Defaults to ~14px (0.875em)+ **/+ fontSize?: string;++ /**+ * Font family that will be used for all text, it defaults to the instance's default font.+ **/+ fontFamily?: MetabaseFontFamily | (string & {});++ /** Base line height */+ lineHeight?: string | number;++ /** Color palette */+ colors?: MetabaseColors;++ /** Component theme options */+ components?: DeepPartial<MetabaseComponentTheme>;+}++export interface MetabaseColors {+ /** Primary brand color used for buttons and links */+ brand?: string;++ /** Lighter variation of the brand color. Used for hover and accented elements. */+ "brand-hover"?: string;++ /** Lightest variation of the brand color. Used for hover and accented elements. */+ "brand-hover-light"?: string;++ /** Text color on dark elements. Should be a lighter color for readability. */+ "text-primary"?: string;++ /** Lighter variation of dark text on light elements. */+ "text-secondary"?: string;++ /** Text color on light elements. Should be a darker color for readability. */+ "text-tertiary"?: string;++ /** Default background color. */+ background?: string;++ /** Slightly muted background color. */+ "background-secondary"?: string;++ /** Slightly darker background color used for hover and accented elements. */+ "background-hover"?: string;++ /** Muted background color used for disabled elements, such as disabled buttons and inputs. */+ "background-disabled"?: string;++ /** Light background color used for some controls like a radiogroup. */+ "background-light"?: string;++ /** Color used for borders */+ border?: string;++ /** Color used for popover shadows */+ shadow?: string;++ /** Color used for filters context */+ filter?: string;++ /** Color used for aggregations and breakouts context */+ summarize?: string;++ /** Chart colors */+ charts?: ChartColor[];++ /** Color used to indicate successful actions and positive values/trends */+ positive?: string;++ /** Color used to indicate dangerous actions and negative values/trends */+ negative?: string;++ /** Color used to outline elements in focus */+ focus?: string;++ /** Color used for white text */+ "text-white"?: string;++ /** Color used for error icons and borders. Defaults to red. */+ error?: string;++ /** Color used for error backgrounds. Defaults to light red. */+ "background-error"?: string;++ /** Color used for some button text on hover */+ "text-hover"?: string;+}++export type MetabaseColor = keyof MetabaseColors;++/**+ * Theme options for customizing specific Metabase+ * components and visualizations.+ *+ * @privateRemarks+ * Every non-optional properties here must have a default value defined+ * in DEFAULT_METABASE_COMPONENT_THEME at [default-component-theme.ts]+ */+export type MetabaseComponentTheme = {+ dashboard: {+ backgroundColor: string;++ /**+ * Border color of the dashboard grid, shown only when editing dashboards.+ * Defaults to `colors.border`+ **/+ gridBorderColor?: string;++ card: {+ backgroundColor: string;++ /**+ * Add custom borders to dashboard cards when set.+ * Value is the same as the border property in CSS, such as "1px solid #ff0000".+ * This will replace the card's drop shadow.+ **/+ border?: string;+ };+ };++ question: {+ /** Background color for all questions */+ backgroundColor: string;++ /** Toolbar of the default interactive question layout */+ toolbar?: {+ backgroundColor?: string;+ };+ };++ /** Data tables **/+ table: {+ /** Background color of the table header that stays fixed while scrolling. Defaults to `white` if no cell background color is set */+ stickyBackgroundColor?: string;++ cell: {+ /** Text color of cells, defaults to `text-primary`. */+ textColor: string;++ /** Default background color of cells, defaults to `background` */+ backgroundColor?: string;++ /** Font size of cell values, defaults to ~12.5px */+ fontSize: string;+ };++ idColumn?: {+ /** Text color of ID column, defaults to `brand`. */+ textColor: string;++ /** Background color of ID column, defaults to `lighten(brand)` */+ backgroundColor?: string;+ };+ };++ /** Pivot table **/+ pivotTable: {+ cell: {+ /** Font size of cell values, defaults to ~12px */+ fontSize: string;+ };++ /** Button to toggle pivot table rows */+ rowToggle: {+ textColor: string;+ backgroundColor: string;+ };+ };++ /** Number chart */+ number?: {+ /**+ * Value displayed on number charts.+ * This also applies to the primary value in trend charts.+ **/+ value?: {+ fontSize?: CSSProperties["fontSize"];+ lineHeight?: string;+ };+ };++ /** Cartesian charts */+ cartesian: {+ /** Padding around the chart. */+ padding?: string;++ label: {+ /** Labels used in cartesian charts, such as axis ticks and series. */+ fontSize: string;+ };++ goalLine: {+ label: {+ /** Font size of goal line labels */+ fontSize: string;+ };+ };++ splitLine: {+ lineStyle: {+ color: string;+ };+ };+ };++ /** Tooltip */+ tooltip?: {+ /** Tooltip text color. */+ textColor?: string;++ /** Secondary text color shown in the tooltip, e.g. for tooltip headers and percentage changes. */+ secondaryTextColor?: string;++ /** Tooltip background color. */+ backgroundColor?: string;++ /** Tooltip background color for focused rows. */+ focusedBackgroundColor?: string;+ };++ /** Popover */+ popover: {+ /** z-index of overlays. Useful for embedding components in a modal.+ * Defaults to 200. */+ zIndex?: number;+ };++ collectionBrowser: {+ breadcrumbs: {+ expandButton: {+ backgroundColor: ColorCssVariableOrString;+ hoverBackgroundColor: ColorCssVariableOrString;+ textColor: ColorCssVariableOrString;+ hoverTextColor: ColorCssVariableOrString;+ };+ };+ emptyContent: {+ icon: {+ width: CSSProperties["width"];+ height: CSSProperties["width"];+ };+ title: {+ fontSize: CSSProperties["fontSize"];+ };+ subtitle: {+ fontSize: CSSProperties["fontSize"];+ };+ };+ };+};++/**+ * A `var(--mb-color-...)` CSS variable reference (see `ColorName` in+ * `metabase/ui/colors/types` for the available keys) or any CSS color string.+ *+ * @inline+ */+export type ColorCssVariableOrString = `var(--mb-color-${string})` | string;++export type ChartColor =+ | string+ | {+ base: string;++ /** Lighter variation of the base color */+ tint?: string;++ /** Darker variation of the base color */+ shade?: string;+ };++/**+ * Embed-setup-wizard-scoped theme: either an inline MetabaseTheme or a+ * reference to a saved EmbeddingTheme via `id`. The preview resolves `id`+ * back to an inline theme before handing it to embed.js.+ */+export type SdkIframeEmbedSetupTheme = MetabaseTheme & { id?: number };export interface EmbeddingTheme {id: number;diff --git a/frontend/src/metabase-types/api/settings.ts b/frontend/src/metabase-types/api/settings.tsindex ed9ab3b3d49..a01d0cce053 100644--- a/frontend/src/metabase-types/api/settings.ts+++ b/frontend/src/metabase-types/api/settings.ts@@ -1,11 +1,11 @@import type { ReactNode } from "react";-import type { SdkIframeEmbedSetupSettings } from "metabase/embedding/embedding-iframe-sdk-setup/types";import type { CurrencyStyle } from "metabase/utils/formatting";import type { InputSettingType } from "./actions";import type { DashboardId } from "./dashboard";import type { DatabaseId } from "./database";+import type { SdkIframeEmbedSetupTheme } from "./embedding-theme";import type { GroupId } from "./group";import type { MetabotLimitPeriod, MetabotLimitType } from "./metabot";import type { NotificationRecipient } from "./notification";@@ -668,10 +668,12 @@ export type UserSettings = {"show-updated-permission-modal": boolean;"show-updated-permission-banner": boolean;"trial-banner-dismissal-timestamp"?: string | null;- "sdk-iframe-embed-setup-settings"?: Pick<- SdkIframeEmbedSetupSettings,- "theme" | "useExistingUserSession"- > | null;+ // The persisted subset of the embed setup wizard's+ // `SdkIframeEmbedSetupSettings` state.+ "sdk-iframe-embed-setup-settings"?: {+ theme?: SdkIframeEmbedSetupTheme;+ useExistingUserSession?: boolean;+ } | null;"color-scheme"?: string;};diff --git a/frontend/src/metabase/admin/embedding/components/ThemeEditor/EditorPanel.tsx b/frontend/src/metabase/admin/embedding/components/ThemeEditor/EditorPanel.tsxindex ef641e80cfc..7d2b94586bc 100644--- a/frontend/src/metabase/admin/embedding/components/ThemeEditor/EditorPanel.tsx+++ b/frontend/src/metabase/admin/embedding/components/ThemeEditor/EditorPanel.tsx@@ -17,7 +17,7 @@ import {Tooltip,UnstyledButton,} from "metabase/ui";-import type { MetabaseFontFamily } from "metabase/ui/fonts";+import type { MetabaseFontFamily } from "metabase/utils/fonts";import { ColorSwatchCard } from "./ColorSwatchCard";import {diff --git a/frontend/src/metabase/admin/embedding/components/ThemeEditor/constants.ts b/frontend/src/metabase/admin/embedding/components/ThemeEditor/constants.tsindex 1a068ef2116..ad5ce23743c 100644--- a/frontend/src/metabase/admin/embedding/components/ThemeEditor/constants.ts+++ b/frontend/src/metabase/admin/embedding/components/ThemeEditor/constants.ts@@ -2,7 +2,7 @@ import { t } from "ttag";import type { MetabaseColor } from "metabase/embedding-sdk/theme";import { ACCENT_COUNT } from "metabase/ui/colors/palette";-import { PREDEFINED_FONT_FAMILIES_FALLBACK_MAP } from "metabase/ui/fonts";+import { PREDEFINED_FONT_FAMILIES_FALLBACK_MAP } from "metabase/utils/fonts";export const FONT_FAMILY_OPTIONS: { value: string; label: string }[] =Object.keys(PREDEFINED_FONT_FAMILIES_FALLBACK_MAP).map((name) => ({diff --git a/frontend/src/metabase/embedding-sdk/theme/MetabaseTheme.ts b/frontend/src/metabase/embedding-sdk/theme/MetabaseTheme.tsindex 643c8e538e9..fbf496cbe78 100644--- a/frontend/src/metabase/embedding-sdk/theme/MetabaseTheme.ts+++ b/frontend/src/metabase/embedding-sdk/theme/MetabaseTheme.ts@@ -1,290 +1,9 @@-import type { CSSProperties } from "react";--import type { ColorName } from "metabase/ui/colors/types";-import type { MetabaseFontFamily } from "metabase/ui/fonts";--import type { DeepPartial } from "../types/utils";--export type MetabaseThemePreset = "light" | "dark";--/**- * Theme configuration for embedded Metabase components.- */-export interface MetabaseTheme {- /**- * Predefined theme preset to use as a base.- */- preset?: MetabaseThemePreset;-- /**- * Base font size.- * Supported units are px, em and rem.- * Defaults to ~14px (0.875em)- **/- fontSize?: string;-- /**- * Font family that will be used for all text, it defaults to the instance's default font.- **/- fontFamily?: MetabaseFontFamily | (string & {});-- /** Base line height */- lineHeight?: string | number;-- /** Color palette */- colors?: MetabaseColors;-- /** Component theme options */- components?: DeepPartial<MetabaseComponentTheme>;-}--export interface MetabaseColors {- /** Primary brand color used for buttons and links */- brand?: string;-- /** Lighter variation of the brand color. Used for hover and accented elements. */- "brand-hover"?: string;-- /** Lightest variation of the brand color. Used for hover and accented elements. */- "brand-hover-light"?: string;-- /** Text color on dark elements. Should be a lighter color for readability. */- "text-primary"?: string;-- /** Lighter variation of dark text on light elements. */- "text-secondary"?: string;-- /** Text color on light elements. Should be a darker color for readability. */- "text-tertiary"?: string;-- /** Default background color. */- background?: string;-- /** Slightly muted background color. */- "background-secondary"?: string;-- /** Slightly darker background color used for hover and accented elements. */- "background-hover"?: string;-- /** Muted background color used for disabled elements, such as disabled buttons and inputs. */- "background-disabled"?: string;-- /** Light background color used for some controls like a radiogroup. */- "background-light"?: string;-- /** Color used for borders */- border?: string;-- /** Color used for popover shadows */- shadow?: string;-- /** Color used for filters context */- filter?: string;-- /** Color used for aggregations and breakouts context */- summarize?: string;-- /** Chart colors */- charts?: ChartColor[];-- /** Color used to indicate successful actions and positive values/trends */- positive?: string;-- /** Color used to indicate dangerous actions and negative values/trends */- negative?: string;-- /** Color used to outline elements in focus */- focus?: string;-- /** Color used for white text */- "text-white"?: string;-- /** Color used for error icons and borders. Defaults to red. */- error?: string;-- /** Color used for error backgrounds. Defaults to light red. */- "background-error"?: string;-- /** Color used for some button text on hover */- "text-hover"?: string;-}--export type MetabaseColor = keyof MetabaseColors;--/**- * Theme options for customizing specific Metabase- * components and visualizations.- *- * @privateRemarks- * Every non-optional properties here must have a default value defined- * in DEFAULT_METABASE_COMPONENT_THEME at [default-component-theme.ts]- */-export type MetabaseComponentTheme = {- dashboard: {- backgroundColor: string;-- /**- * Border color of the dashboard grid, shown only when editing dashboards.- * Defaults to `colors.border`- **/- gridBorderColor?: string;-- card: {- backgroundColor: string;-- /**- * Add custom borders to dashboard cards when set.- * Value is the same as the border property in CSS, such as "1px solid #ff0000".- * This will replace the card's drop shadow.- **/- border?: string;- };- };-- question: {- /** Background color for all questions */- backgroundColor: string;-- /** Toolbar of the default interactive question layout */- toolbar?: {- backgroundColor?: string;- };- };-- /** Data tables **/- table: {- /** Background color of the table header that stays fixed while scrolling. Defaults to `white` if no cell background color is set */- stickyBackgroundColor?: string;-- cell: {- /** Text color of cells, defaults to `text-primary`. */- textColor: string;-- /** Default background color of cells, defaults to `background` */- backgroundColor?: string;-- /** Font size of cell values, defaults to ~12.5px */- fontSize: string;- };-- idColumn?: {- /** Text color of ID column, defaults to `brand`. */- textColor: string;-- /** Background color of ID column, defaults to `lighten(brand)` */- backgroundColor?: string;- };- };-- /** Pivot table **/- pivotTable: {- cell: {- /** Font size of cell values, defaults to ~12px */- fontSize: string;- };-- /** Button to toggle pivot table rows */- rowToggle: {- textColor: string;- backgroundColor: string;- };- };-- /** Number chart */- number?: {- /**- * Value displayed on number charts.- * This also applies to the primary value in trend charts.- **/- value?: {- fontSize?: CSSProperties["fontSize"];- lineHeight?: string;- };- };-- /** Cartesian charts */- cartesian: {- /** Padding around the chart. */- padding?: string;-- label: {- /** Labels used in cartesian charts, such as axis ticks and series. */- fontSize: string;- };-- goalLine: {- label: {- /** Font size of goal line labels */- fontSize: string;- };- };-- splitLine: {- lineStyle: {- color: string;- };- };- };-- /** Tooltip */- tooltip?: {- /** Tooltip text color. */- textColor?: string;-- /** Secondary text color shown in the tooltip, e.g. for tooltip headers and percentage changes. */- secondaryTextColor?: string;-- /** Tooltip background color. */- backgroundColor?: string;-- /** Tooltip background color for focused rows. */- focusedBackgroundColor?: string;- };-- /** Popover */- popover: {- /** z-index of overlays. Useful for embedding components in a modal.- * Defaults to 200. */- zIndex?: number;- };-- collectionBrowser: {- breadcrumbs: {- expandButton: {- backgroundColor: ColorCssVariableOrString;- hoverBackgroundColor: ColorCssVariableOrString;- textColor: ColorCssVariableOrString;- hoverTextColor: ColorCssVariableOrString;- };- };- emptyContent: {- icon: {- width: CSSProperties["width"];- height: CSSProperties["width"];- };- title: {- fontSize: CSSProperties["fontSize"];- };- subtitle: {- fontSize: CSSProperties["fontSize"];- };- };- };-};--/**- * @inline- */-export type ColorCssVariableOrString = `var(--mb-color-${ColorName})` | string;--export type ChartColor =- | string- | {- base: string;-- /** Lighter variation of the base color */- tint?: string;-- /** Darker variation of the base color */- shade?: string;- };+export type {+ ChartColor,+ ColorCssVariableOrString,+ MetabaseColor,+ MetabaseColors,+ MetabaseComponentTheme,+ MetabaseTheme,+ MetabaseThemePreset,+} from "metabase-types/api";diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/types.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/types.tsindex 6defa2d6058..c7c8ddfd5b1 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/types.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/types.ts@@ -7,15 +7,12 @@ import type {SdkIframeEmbedAuthTypeSettings,SdkIframeEmbedBaseSettings,} from "metabase/embedding/embedding-iframe-sdk/types/embed";-import type { MetabaseTheme } from "metabase/embedding-sdk/theme";-import type { BaseRecentItem } from "metabase-types/api";+import type {+ BaseRecentItem,+ SdkIframeEmbedSetupTheme,+} from "metabase-types/api";-/**- * Wizard-scoped theme: either an inline MetabaseTheme or a reference to a- * saved EmbeddingTheme via `id`. The preview resolves `id` back to an inline- * theme before handing it to embed.js.- */-export type SdkIframeEmbedSetupTheme = MetabaseTheme & { id?: number };+export type { SdkIframeEmbedSetupTheme } from "metabase-types/api";export type SdkIframeEmbedSetupExperience =| "dashboard"diff --git a/frontend/src/metabase/styled-components/containers/GlobalStyles/GlobalStyles.tsx b/frontend/src/metabase/styled-components/containers/GlobalStyles/GlobalStyles.tsxindex 5fffb416ea3..90c8f7702fd 100644--- a/frontend/src/metabase/styled-components/containers/GlobalStyles/GlobalStyles.tsx+++ b/frontend/src/metabase/styled-components/containers/GlobalStyles/GlobalStyles.tsx@@ -12,8 +12,8 @@ import {import { useSelector } from "metabase/redux";import { getMetabaseCssVariables } from "metabase/styled-components/theme/css-variables";import { useMantineTheme } from "metabase/ui";-import { getFontFamilyValue } from "metabase/ui/fonts";import { getSitePath } from "metabase/utils/dom";+import { getFontFamilyValue } from "metabase/utils/fonts";import { saveDomImageStyles } from "metabase/visualizations/lib/image-exports";import { getFont, getFontFiles } from "../../selectors";diff --git a/frontend/src/metabase/styled-components/theme/css-variables.ts b/frontend/src/metabase/styled-components/theme/css-variables.tsindex 0ddfb8782f1..fd81677ca42 100644--- a/frontend/src/metabase/styled-components/theme/css-variables.ts+++ b/frontend/src/metabase/styled-components/theme/css-variables.ts@@ -15,8 +15,8 @@ import {import type { MantineTheme } from "metabase/ui";import { deriveFullMetabaseTheme } from "metabase/ui/colors";import type { ColorName } from "metabase/ui/colors/types";-import { getFontFamilyValue } from "metabase/ui/fonts";import type { ResolvedColorScheme } from "metabase/utils/color-scheme";+import { getFontFamilyValue } from "metabase/utils/fonts";import type { ColorSettings } from "metabase-types/api";const createColorVars = (diff --git a/frontend/src/metabase/ui/fonts.ts b/frontend/src/metabase/utils/fonts.tssimilarity index 100%rename from frontend/src/metabase/ui/fonts.tsrename to frontend/src/metabase/utils/fonts.tsdiff --git a/frontend/src/metabase/visualizations/hooks/use-browser-rendering-context.ts b/frontend/src/metabase/visualizations/hooks/use-browser-rendering-context.tsindex 46de37b1fd0..2322b6fb618 100644--- a/frontend/src/metabase/visualizations/hooks/use-browser-rendering-context.ts+++ b/frontend/src/metabase/visualizations/hooks/use-browser-rendering-context.ts@@ -3,7 +3,7 @@ import { useMemo } from "react";import { usePalette } from "metabase/common/hooks/use-palette";import { useMantineTheme } from "metabase/ui";import { color } from "metabase/ui/colors";-import { getFontFamilyValue } from "metabase/ui/fonts";+import { getFontFamilyValue } from "metabase/utils/fonts";import {measureTextHeight,measureTextWidth,diff --git a/frontend/src/metabase/visualizations/visualizations/RowChart/RowChart.tsx b/frontend/src/metabase/visualizations/visualizations/RowChart/RowChart.tsxindex c6e538c519a..c1faeb3cbda 100644--- a/frontend/src/metabase/visualizations/visualizations/RowChart/RowChart.tsx+++ b/frontend/src/metabase/visualizations/visualizations/RowChart/RowChart.tsx@@ -3,7 +3,7 @@ import { t } from "ttag";import { ExplicitSize } from "metabase/common/components/ExplicitSize";import CS from "metabase/css/core/index.css";-import { getFontFamilyValue } from "metabase/ui/fonts";+import { getFontFamilyValue } from "metabase/utils/fonts";import type { FontStyle } from "metabase/utils/measure-text";import { measureTextWidth } from "metabase/utils/measure-text";import { extractRemappedColumns } from "metabase/visualizations";