1- import React , { useState , useContext } from 'react' ;
1+ import React , { useState , useContext , useCallback } from 'react' ;
22import { ThemeContext } from '../../../components/with_theme' ;
33
44import {
@@ -48,23 +48,22 @@ export const contrastSections = [
4848const 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
5262export 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