Skip to content
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

feat: Deephaven UI table databar support (#2190) #2340

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/components/src/theme/ThemeUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,10 @@ describe.each([undefined, document.createElement('div')])(
bbb: 'bbb',
};

jest.spyOn(window.CSS, 'supports').mockReturnValue(false);

const actual = resolveCssVariablesInRecord(given, targetElement);

expect(computedStyle.getPropertyValue).not.toHaveBeenCalled();
expect(ColorUtils.normalizeCssColor).not.toHaveBeenCalled();
expect(actual).toEqual(given);
});
Expand Down
19 changes: 9 additions & 10 deletions packages/components/src/theme/ThemeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,19 @@ export function resolveCssVariablesInRecord<T extends Record<string, string>>(

const result = {} as T;
recordArray.forEach(([key, value], i) => {
// only resolve if it contains a css var expression
if (!value.includes(CSS_VAR_EXPRESSION_PREFIX)) {
(result as Record<string, string>)[key] = value;
return;
}
// resolves any variables in the expression
let resolved = tempPropElComputedStyle.getPropertyValue(
`--${TMP_CSS_PROP_PREFIX}-${i}`
);

const containsCssVar = value.includes(CSS_VAR_EXPRESSION_PREFIX);
const isColor = CSS.supports('color', resolved);

if (
// skip if resolved is already hex
!/^#[0-9A-F]{6}[0-9a-f]{0,2}$/i.test(resolved) &&
// only try to normalize things that are valid colors
// only try to normalize non-hex strings that are valid colors
// otherwise non-colors will be made #00000000
CSS.supports('color', resolved)
isColor &&
!/^#[0-9A-F]{6}[0-9a-f]{0,2}$/i.test(resolved)
) {
// getting the computed background color is necessary
// because resolved can still contain a color-mix() function
Expand All @@ -344,7 +342,8 @@ export function resolveCssVariablesInRecord<T extends Record<string, string>>(
// convert color to hex, which is what monaco and plotly require
resolved = ColorUtils.normalizeCssColor(color, isAlphaOptional);
}
(result as Record<string, string>)[key] = resolved;
(result as Record<string, string>)[key] =
containsCssVar || isColor ? resolved : value;
});

// Remove the temporary div
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/theme/colorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ export function isDHColorValue(value: string): value is DHColorValue {
* ex. colorValueStyle('red') => 'red'
* ex. colorValueStyle('#F00') => '#F00'
*/
export function colorValueStyle(value: string): string;
export function colorValueStyle(value: string | undefined): string | undefined;
export function colorValueStyle(value: string | undefined): string | undefined {
if (value != null && isDHColorValue(value)) {
return `var(--dh-color-${value})`;
Expand Down
Loading
Loading