Skip to content

Commit a4943ec

Browse files
committed
misc perf improvements
1 parent 6811061 commit a4943ec

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src-docs/src/views/theme/color/contrast.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useContext } from 'react';
1+
import React, { useState, useContext, useCallback } from 'react';
22
import { ThemeContext } from '../../../components/with_theme';
33

44
import {
@@ -48,23 +48,22 @@ export const contrastSections = [
4848
const background_colors = BACKGROUND_COLORS.filter(
4949
(color) => color !== 'transparent'
5050
);
51+
const backgroundButtons = [
52+
'container',
53+
// 'hover', Commenting out for now since contrast can't be calculated on transparent values
54+
'button',
55+
].map((m) => {
56+
return {
57+
id: m,
58+
label: m,
59+
};
60+
});
5161

5262
export default () => {
5363
const euiTheme = useEuiTheme();
5464
const [showTextVariants, setShowTextVariants] = useState(true);
5565
const [contrastValue, setContrastValue] = useState(4.5);
5666

57-
const backgroundButtons = [
58-
'container',
59-
// 'hover', Commenting out for now since contrast can't be calculated on transparent values
60-
'button',
61-
].map((m) => {
62-
return {
63-
id: m,
64-
label: m,
65-
};
66-
});
67-
6867
const [backgroundColors, setBackgroundColors] =
6968
useState<any>(background_colors);
7069
const [backgroundFunction, setBackgroundFunction] = useState<any>(
@@ -74,7 +73,7 @@ export default () => {
7473
backgroundButtons[0].id
7574
);
7675

77-
const switchBackgroundColors = (id: string) => {
76+
const switchBackgroundColors = useCallback((id: string) => {
7877
switch (id) {
7978
case 'container':
8079
setBackgroundSelected(id);
@@ -92,7 +91,7 @@ export default () => {
9291
setBackgroundFunction('euiButtonColor(color)');
9392
break;
9493
}
95-
};
94+
}, []);
9695

9796
const showSass = useContext(ThemeContext).themeLanguage.includes('sass');
9897

0 commit comments

Comments
 (0)