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

JNG-5409 support row font color highlighting #294

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function RowHighlightLegend(props: { rowStylings: RowStylerConfigured<any
<div key={s.name}>
<Box sx={ { mt: 1, display: 'flex', flexDirection: 'row', alignItems: 'center' } }>
<MdiIcon path="record" sx={ { mr: 1, ml: idx > 0 ? 3 : 0, color: s.backgroundColor } } />
<Typography variant="body1">
<Typography variant="body1" sx={ s.fontColor ? { color: s.fontColor } : {} }>
{t(`table-custom-row-style-${s.name}`, { defaultValue: s.label }) as string}
</Typography>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export type TableRowHighlightingHook<T extends GridValidRowModel> = () => () =>

export interface CustomRowThemeData {
name: string;
backgroundColor: string;
backgroundColor?: string;
fontColor?: string;
}

export interface RowStyler<T extends GridValidRowModel> {
Expand All @@ -17,28 +18,34 @@ export interface RowStyler<T extends GridValidRowModel> {

export interface RowStylerConfigured<T extends GridValidRowModel> extends RowStyler<T>, CustomRowThemeData {
label: string;
backgroundColor: string;
backgroundColor?: string;
fontColor?: string;
}

const getBackgroundColor = (color: string, mode: string) => mode === 'dark' ? darken(color, 0.6) : lighten(color, 0.6);
const getHoverBackgroundColor = (color: string, mode: string) => mode === 'dark' ? darken(color, 0.4) : lighten(color, 0.4);
const getSelectedBackgroundColor = (color: string, mode: string) => mode === 'dark' ? darken(color, 0.5) : lighten(color, 0.5);
const getSelectedHoverBackgroundColor = (color: string, mode: string) => mode === 'dark' ? darken(color, 0.3) : lighten(color, 0.3);

const createRowThemes = ({ name, backgroundColor }: CustomRowThemeData): any => {
const createRowThemes = ({ name, backgroundColor, fontColor }: CustomRowThemeData): any => {
return {
[`& .${name}`]: {
backgroundColor: getBackgroundColor(backgroundColor, 'light'),
'&:hover': {
backgroundColor: getHoverBackgroundColor(backgroundColor, 'light'),
},
'&.Mui-selected': {
backgroundColor: getSelectedBackgroundColor(backgroundColor, 'light'),
...(fontColor ? {
color: fontColor,
} : {}),
...(backgroundColor ? {
backgroundColor: getBackgroundColor(backgroundColor, 'light'),
'&:hover': {
backgroundColor: getSelectedHoverBackgroundColor(backgroundColor, 'light'),
backgroundColor: getHoverBackgroundColor(backgroundColor, 'light'),
},
},
},
'&.Mui-selected': {
backgroundColor: getSelectedBackgroundColor(backgroundColor, 'light'),
'&:hover': {
backgroundColor: getSelectedHoverBackgroundColor(backgroundColor, 'light'),
},
},
} : {}),
}
};
};

Expand All @@ -50,4 +57,4 @@ export const transformRowStylings = <T extends GridValidRowModel>(rowStylings: R
}

return res;
}
};
Loading