Repository navigation
add dark mode support for chart #93258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
aeb0336
b26a998
68bc0b4
56c0fc0
3a50967
1d50878
b5ddbfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import type {Color} from '@shopify/react-native-skia'; | ||
| import type {ColorValue} from 'react-native'; | ||
| import colors from '@styles/theme/colors'; | ||
| import type {ThemeColors} from '@styles/theme/types'; | ||
|
|
||
| /** | ||
| * Only the chart background colors are remapped. Data-visualization colors (series / | ||
| * slice fills, legend symbols) are intentionally excluded so they remain | ||
| * consistent across themes. | ||
| */ | ||
| type ChartThemeColorKey = 'cardBG' | 'heading' | 'textSupporting' | 'border'; | ||
|
|
||
| const CHART_CHROME_COLOR_MAP = new Map<string, ChartThemeColorKey>( | ||
| ( | ||
| [ | ||
| [colors.productLight200, 'cardBG'], | ||
| [colors.productLight900, 'heading'], | ||
| [colors.productLight800, 'textSupporting'], | ||
|
Comment on lines
+16
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Charts already covered by this renderer still use nearby hex values that are not in this exact-match map: Useful? React with 👍 / 👎. |
||
| [colors.productLight400, 'border'], | ||
| ] as const | ||
| ).map(([hex, key]) => [hex.toLowerCase(), key]), | ||
| ); | ||
|
|
||
| function resolveChartThemeColor(color: string | undefined, theme: ThemeColors): string | undefined; | ||
| function resolveChartThemeColor(color: Color | undefined, theme: ThemeColors): Color | undefined; | ||
| function resolveChartThemeColor(color: Color | undefined, theme: ThemeColors): Color | undefined { | ||
| if (typeof color !== 'string') { | ||
| return color; | ||
| } | ||
| const themeKey = CHART_CHROME_COLOR_MAP.get(color.toLowerCase()); | ||
| return themeKey ? theme[themeKey] : color; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves a `ViewStyle.backgroundColor` (ColorValue) through the chart theme | ||
| * color map. Non-string color values pass through unchanged. | ||
| */ | ||
| function resolveChartContainerBgColor(bgColor: ColorValue | undefined, theme: ThemeColors): ColorValue | undefined { | ||
| return typeof bgColor === 'string' ? (resolveChartThemeColor(bgColor, theme) ?? bgColor) : bgColor; | ||
| } | ||
|
|
||
| export default resolveChartThemeColor; | ||
| export {resolveChartContainerBgColor}; | ||
Uh oh!
There was an error while loading. Please reload this page.