amaannawab923 commented on code in PR #34675: URL: https://github.com/apache/superset/pull/34675#discussion_r2273889743
########## superset-frontend/packages/superset-ui-core/src/components/ThemedAgGridReact/index.tsx: ########## @@ -0,0 +1,183 @@ +/** + * 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 { useRef, useMemo, forwardRef } from 'react'; +import { Global, css } from '@emotion/react'; +import { AgGridReact, type AgGridReactProps } from 'ag-grid-react'; +import { nanoid } from 'nanoid'; +import tinycolor from 'tinycolor2'; +import { + themeQuartz, + colorSchemeDark, + colorSchemeLight, +} from 'ag-grid-community'; +import { useTheme } from '../../theme'; + +// Note: With ag-grid v34's new theming API, CSS files are injected automatically +// Do NOT import 'ag-grid-community/styles/ag-grid.css' or theme CSS files + +/** + * ThemedAgGridReact - A wrapper around AgGridReact that applies Superset theming + * + * This component: + * - Preserves the full AgGridReactProps interface for drop-in replacement + * - Applies Superset theme variables via CSS custom properties + * - Uses unique class-based styling to avoid ID conflicts + * - Supports automatic dark/light mode switching + * + * @example + * ```tsx + * <ThemedAgGridReact + * rowData={data} + * columnDefs={columns} + * // ... any other AgGridReactProps + * /> + * ``` + */ +export const ThemedAgGridReact = forwardRef<AgGridReact, AgGridReactProps>( + function ThemedAgGridReact(props, ref) { + const theme = useTheme(); + + // Generate a unique class name for this instance to avoid conflicts + const instanceClass = useRef(`superset-ag-grid-${nanoid(8)}`).current; + + // Determine if we're in dark mode + const isDarkMode = useMemo(() => { + const bgColor = theme.colorBgBase; + if (!bgColor) { + return false; + } + return tinycolor(bgColor).isDark(); + }, [theme]); + + // Get the appropriate ag-grid theme based on dark/light mode + const agGridTheme = useMemo(() => { + // Use quaternary fill for odd rows + const oddRowBg = theme?.colorFillQuaternary; + + const baseTheme = isDarkMode + ? themeQuartz.withPart(colorSchemeDark) + : themeQuartz.withPart(colorSchemeLight); + Review Comment: ${({ }) => css` --ag-background-color: ${theme.colorBgBase}; --ag-foreground-color: ${theme.colorText}; --ag-header-background-color: ${theme.colorBgBase}; --ag-header-foreground-color: ${theme.colorText}; ` We actually need to do this for Ag Grid table for it to be always be compatible with our theming , this allows the ag grid table to always use the correct theming tokens -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
