mistercrunch commented on code in PR #31590: URL: https://github.com/apache/superset/pull/31590#discussion_r1968727920
########## superset-frontend/packages/superset-ui-core/src/theme/Theme.tsx: ########## @@ -0,0 +1,352 @@ +/** + * 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. + */ +/* eslint-disable react-prefer-function-component/react-prefer-function-component */ +// eslint-disable-next-line no-restricted-syntax +import React from 'react'; +import { + theme as antdThemeImport, + ThemeConfig as AntdThemeConfig, + ConfigProvider, +} from 'antd-v5'; +import tinycolor from 'tinycolor2'; + +import { + ThemeProvider as EmotionThemeProvider, + CacheProvider as EmotionCacheProvider, +} from '@emotion/react'; +import createCache from '@emotion/cache'; +// import { merge } from 'lodash'; + +import { + AntdTokens, + SupersetTheme, + allowedAntdTokens, + SharedAntdTokens, + SystemColors, + ColorVariants, + DeprecatedColorVariations, + DeprecatedThemeColors, + LegacySupersetTheme, + FontSizeKey, +} from './types'; + +/* eslint-disable theme-colors/no-literal-colors */ + +export class Theme { + theme: SupersetTheme; + + private static readonly defaultTokens = { + // Default colors + colorPrimary: '#20a7c9', + colorError: '#e04355', + colorWarning: '#fcc700', + colorSuccess: '#5ac189', + colorInfo: '#66bcfe', + + // Forcing some default tokens + fontFamily: `'Inter', Helvetica, Arial`, + fontFamilyCode: `'Fira Code', 'Courier New', monospace`, + + // Extra tokens + transitionTiming: 0.3, + brandIconMaxWidth: 37, + fontSizeXS: '8', + fontSizeXXL: '28', + fontWeightNormal: '400', + fontWeightLight: '300', + fontWeightMedium: '500', + }; + + private antdConfig: AntdThemeConfig; + + private static readonly sizeMap: Record<FontSizeKey, string> = { + xs: 'fontSizeXS', + s: 'fontSizeSM', + m: 'fontSize', + l: 'fontSizeLG', + xl: 'fontSizeXL', + xxl: 'fontSizeXXL', + }; + + private constructor({ + seed, + antdConfig, + isDark = false, Review Comment: Dark is a pretty funky construct where based on this we pass in an AntD `darkAlgorithm` object in `ThemeConfig`. Similarly they offer a `compact` algorithm that can be composed with `darkAlgorithm`, so you can do ``` const themeConfig = { seed, algorithm: [darkAlgorithm, compactAlgorithm] } ``` Meaning some of these things are not exclusive, which is a bit funky. The constructor here allows for different combos through static methods, like `Theme.fromSeed(seed, isDark)` and another `Theme.fromAntdConfig(config)`. We still need `isDark` to support legacy logic around `theme.colors.primary.dark3`. Could simplify/cleanup later, and until the public API settles. Working with all this, I think standardizing with an extended AntD config makes most sense. If you want a dark theme, give me a dark antdconfig.... -- 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]
