Skip to content

Commit

Permalink
fix: apply theme bg color to Cell
Browse files Browse the repository at this point in the history
  • Loading branch information
Caele committed Mar 21, 2023
1 parent 26e242a commit f4c2916
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
8 changes: 5 additions & 3 deletions apis/nucleus/src/components/Cell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,11 @@ const Cell = forwardRef(
}, []);

useEffect(() => {
const bgComp = layout?.components ? layout.components.find((comp) => comp.key === 'general') : null;
setBgColor(resolveBgColor(bgComp, halo.public.theme));
setBgImage(resolveBgImage(bgComp, halo.app));
if (layout) {
const bgComp = layout.components ? layout.components.find((comp) => comp.key === 'general') : null;
setBgColor(resolveBgColor(bgComp, halo.public.theme, layout.visualization));
setBgImage(resolveBgImage(bgComp, halo.app));
}
}, [layout, halo.public.theme, halo.app, themeName]);

focusHandler.current.blurCallback = (resetFocus) => {
Expand Down
2 changes: 1 addition & 1 deletion apis/nucleus/src/components/Sheet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function Sheet({ model, halo, initialSnOptions, initialSnPlugins, initialError,

useEffect(() => {
const bgComp = layout?.components ? layout.components.find((comp) => comp.key === 'general') : null;
setBgColor(resolveBgColor(bgComp, halo.public.theme));
setBgColor(resolveBgColor(bgComp, halo.public.theme, 'sheet'));
setBgImage(resolveBgImage(bgComp, halo.app));
}, [layout, halo.public.theme, halo.app, themeName]);

Expand Down
24 changes: 24 additions & 0 deletions apis/nucleus/src/utils/__tests__/background-props.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ describe('Background property resolver', () => {
};
});

test('should resolve background color to empty', () => {
const color = resolveBgColor({});
expect(color).toBeUndefined();
});
test('should resolve background color by expression', () => {
const color = resolveBgColor(bgCompLayout, t);
expect(color).toBe('rgb(255, 0, 0)');
Expand All @@ -55,4 +59,24 @@ describe('Background property resolver', () => {
expect(url).toBe('http://example.com/media/Tulips.jpg');
expect(size).toBe('contain');
});
test('should resolve background color by theme', () => {
const color = resolveBgColor({}, t, 'peoplechart');
expect(color).toBe('transparent');
});

test('should resolve background color by custom theme', () => {
const color = resolveBgColor(
{},
{
getStyle: (obj, path, attr) => {
if (obj === 'object.gantt' && path === '' && attr === 'backgroundColor') {
return '#ff00ff';
}
return undefined;
},
},
'gantt'
);
expect(color).toBe('#ff00ff');
});
});
8 changes: 7 additions & 1 deletion apis/nucleus/src/utils/background-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,19 @@ export const resolveBgImage = (bgComp, app) => {
return undefined;
};

export const resolveBgColor = (bgComp, theme) => {
export const resolveBgColor = (bgComp, theme, objectType) => {
const bgColor = bgComp?.bgColor;
if (bgColor && theme) {
if (bgColor.useExpression) {
return theme.validateColor(bgColor.colorExpression);
}
return bgColor.color && bgColor.color.color !== 'none' ? theme.getColorPickerColor(bgColor.color, true) : undefined;
}
if (theme && objectType) {
return theme.getStyle(`object.${objectType}`, '', 'backgroundColor');
}
if (theme) {
return theme.getStyle('', '', 'backgroundColor');
}
return undefined;
};

0 comments on commit f4c2916

Please sign in to comment.