EnxDev commented on code in PR #34182:
URL: https://github.com/apache/superset/pull/34182#discussion_r2228131763


##########
superset-frontend/packages/superset-ui-core/src/theme/utils/themeUtils.ts:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import tinycolor from 'tinycolor2';
+import type { SupersetTheme, FontSizeKey, ColorVariants } from '../types';
+
+const fontSizeMap: Record<FontSizeKey, keyof SupersetTheme> = {
+  xs: 'fontSizeXS',
+  s: 'fontSizeSM',
+  m: 'fontSize',
+  l: 'fontSizeLG',
+  xl: 'fontSizeXL',
+  xxl: 'fontSizeXXL',
+};
+
+/**
+ * Get font size from theme tokens based on size key
+ * @param theme - Theme tokens from useTheme()
+ * @param size - Font size key
+ * @returns Font size as string
+ */
+export function getFontSize(theme: SupersetTheme, size?: FontSizeKey): string {
+  const key = fontSizeMap[size || 'm'];
+  return String(theme[key] || theme.fontSize);
+}
+
+/**
+ * Get color variants for a given color type from theme tokens
+ * @param theme - Theme tokens from useTheme()
+ * @param color - Color type (e.g., 'primary', 'error', 'success')
+ * @returns ColorVariants object with bg, border, text colors etc.
+ */
+export function getColorVariants(
+  theme: SupersetTheme,
+  color: string,
+): ColorVariants {
+  const firstLetterCapped = color.charAt(0).toUpperCase() + color.slice(1);
+
+  if (color === 'default' || color === 'grayscale') {
+    const isDark = isThemeDark(theme);
+
+    const flipBrightness = (baseColor: string): string => {
+      if (!isDark) return baseColor;
+      const { r, g, b } = tinycolor(baseColor).toRgb();
+      const invertedColor = tinycolor({ r: 255 - r, g: 255 - g, b: 255 - b });
+      return invertedColor.toHexString();
+    };
+
+    return {
+      active: flipBrightness('#222'),
+      textActive: flipBrightness('#444'),
+      text: flipBrightness('#555'),
+      textHover: flipBrightness('#666'),
+      hover: flipBrightness('#888'),
+      borderHover: flipBrightness('#AAA'),
+      border: flipBrightness('#CCC'),
+      bgHover: flipBrightness('#DDD'),
+      bg: flipBrightness('#F4F4F4'),
+    };
+  }
+
+  return {
+    active: (theme as any)[`color${firstLetterCapped}Active`],
+    textActive: (theme as any)[`color${firstLetterCapped}TextActive`],
+    text: (theme as any)[`color${firstLetterCapped}Text`],
+    textHover: (theme as any)[`color${firstLetterCapped}TextHover`],
+    hover: (theme as any)[`color${firstLetterCapped}Hover`],
+    borderHover: (theme as any)[`color${firstLetterCapped}BorderHover`],
+    border: (theme as any)[`color${firstLetterCapped}Border`],
+    bgHover: (theme as any)[`color${firstLetterCapped}BgHover`],
+    bg: (theme as any)[`color${firstLetterCapped}Bg`],
+  };
+}
+
+/**
+ * Check if the current theme is dark mode based on background color
+ * @param theme - Theme tokens from useTheme()
+ * @returns true if theme is dark, false if light
+ */
+export function isThemeDark(theme: SupersetTheme): boolean {
+  return tinycolor(theme.colorBgContainer).isDark();

Review Comment:
   I think it could be a good idea to also consider `colorBgElevated` in 
addition to `colorBgContainer`
   
   **Note:** There's already a `useIsDark` hook defined in 
`superset-frontend/plugins/plugin-chart-ag-grid-table/src/utils/useTableTheme.ts`
 that does the same thing.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to