Skip to content

Commit

Permalink
[bonus perf] memoize useEuiBackgroundColorCSS as well
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Jan 29, 2024
1 parent b4f452b commit 5fcb18d
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions src/global_styling/mixins/_color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,32 +79,37 @@ export const useEuiBackgroundColor = (
};

export const useEuiBackgroundColorCSS = () => {
return {
transparent: css`
background-color: ${useEuiBackgroundColor('transparent')};
`,
plain: css`
background-color: ${useEuiBackgroundColor('plain')};
`,
subdued: css`
background-color: ${useEuiBackgroundColor('subdued')};
`,
accent: css`
background-color: ${useEuiBackgroundColor('accent')};
`,
primary: css`
background-color: ${useEuiBackgroundColor('primary')};
`,
success: css`
background-color: ${useEuiBackgroundColor('success')};
`,
warning: css`
background-color: ${useEuiBackgroundColor('warning')};
`,
danger: css`
background-color: ${useEuiBackgroundColor('danger')};
`,
};
const euiThemeContext = useEuiTheme();

return useMemo(
() => ({
transparent: css`
background-color: ${euiBackgroundColor(euiThemeContext, 'transparent')};
`,
plain: css`
background-color: ${euiBackgroundColor(euiThemeContext, 'plain')};
`,
subdued: css`
background-color: ${euiBackgroundColor(euiThemeContext, 'subdued')};
`,
accent: css`
background-color: ${euiBackgroundColor(euiThemeContext, 'accent')};
`,
primary: css`
background-color: ${euiBackgroundColor(euiThemeContext, 'primary')};
`,
success: css`
background-color: ${euiBackgroundColor(euiThemeContext, 'success')};
`,
warning: css`
background-color: ${euiBackgroundColor(euiThemeContext, 'warning')};
`,
danger: css`
background-color: ${euiBackgroundColor(euiThemeContext, 'danger')};
`,
}),
[euiThemeContext]
);
};

export const euiBorderColor = (
Expand Down

0 comments on commit 5fcb18d

Please sign in to comment.