1- import React , { JSX , useCallback , useRef , useState } from 'react'
1+ import React , { JSX , useRef , useState } from 'react'
22import ReactColorA11y from 'react-color-a11y'
33import {
44 Box ,
77 Switch ,
88 Grid
99} from '@mui/material'
10- import { HexColorPicker , HexColorInput } from 'react-colorful'
10+ import { HexAlphaColorPicker , HexColorInput } from 'react-colorful'
1111import SettingsBox from './SettingsBox'
1212
1313const TextContent = ( ) : JSX . Element => (
@@ -38,22 +38,6 @@ function App(): JSX.Element {
3838 const [ preserveContrastDirectionIfPossible , setPreserveContrastDirectionIfPossible ] = useState ( true )
3939 const [ backgroundColorOverride , setBackgroundColorOverride ] = useState < string | undefined > ( )
4040
41- const requiredContrastRatioChangeHandler = useCallback ( ( _event : unknown , value : number | number [ ] ) => {
42- setRequiredContrastRatio ( Number ( value ) )
43- } , [ ] )
44-
45- const flipBlackAndWhiteChangeHandler = useCallback ( ( event : React . ChangeEvent < HTMLInputElement > ) => {
46- setFlipBlackAndWhite ( event . target . checked )
47- } , [ ] )
48-
49- const preserveContrastDirectionIfPossibleChangeHandler = useCallback ( ( event : React . ChangeEvent < HTMLInputElement > ) => {
50- setPreserveContrastDirectionIfPossible ( event . target . checked )
51- } , [ ] )
52-
53- const backgroundColorOverrideChangeHandler = useCallback ( ( event : React . ChangeEvent < HTMLInputElement > ) => {
54- setBackgroundColorOverride ( event . target . checked ? '#000000' : undefined )
55- } , [ ] )
56-
5741 return (
5842 < >
5943 < Box sx = { { background : backgroundColor , flexGrow : 1 , padding : 2 } } >
@@ -107,27 +91,27 @@ function App(): JSX.Element {
10791 < Grid size = { { xs : 12 , xl : 2 , md : 3 } } >
10892 < SettingsBox >
10993 < Typography gutterBottom > Background Color</ Typography >
110- < HexColorPicker style = { { margin : '15px auto' } } color = { backgroundColor } onChange = { setBackgroundColor } />
94+ < HexAlphaColorPicker style = { { margin : '15px auto' } } color = { backgroundColor } onChange = { setBackgroundColor } />
11195 < HexColorInput alpha color = { backgroundColor } onChange = { setBackgroundColor } />
11296 </ SettingsBox >
11397 </ Grid >
11498 < Grid size = { { xs : 12 , xl : 2 , md : 3 } } >
11599 < SettingsBox >
116100 < Typography gutterBottom > Foreground Color</ Typography >
117- < HexColorPicker style = { { margin : '15px auto' } } color = { foregroundColor } onChange = { setForegroundColor } />
101+ < HexAlphaColorPicker style = { { margin : '15px auto' } } color = { foregroundColor } onChange = { setForegroundColor } />
118102 < HexColorInput alpha color = { foregroundColor } onChange = { setForegroundColor } />
119103 </ SettingsBox >
120104 </ Grid >
121105 < Grid size = { { xs : 12 , lg : 2 } } >
122106 < SettingsBox >
123107 < Typography gutterBottom > Required Contrast Ratio</ Typography >
124108 < Slider
125- defaultValue = { 4.5 }
109+ value = { requiredContrastRatio }
126110 valueLabelDisplay = "auto"
127111 step = { 0.5 }
128112 min = { 1 }
129113 max = { 21 }
130- onChangeCommitted = { requiredContrastRatioChangeHandler }
114+ onChange = { ( _event , value ) => setRequiredContrastRatio ( value ) }
131115 />
132116 </ SettingsBox >
133117 </ Grid >
@@ -137,8 +121,7 @@ function App(): JSX.Element {
137121 < Typography gutterBottom > (only impacts #000 and #fff)</ Typography >
138122 < Switch
139123 checked = { flipBlackAndWhite }
140- onChange = { flipBlackAndWhiteChangeHandler }
141- inputProps = { { 'aria-label' : 'controlled' } }
124+ onChange = { ( _event , checked ) => setFlipBlackAndWhite ( checked ) }
142125 />
143126 </ SettingsBox >
144127 </ Grid >
@@ -147,8 +130,7 @@ function App(): JSX.Element {
147130 < Typography gutterBottom > Preserve Contrast Direction If Possible</ Typography >
148131 < Switch
149132 checked = { preserveContrastDirectionIfPossible }
150- onChange = { preserveContrastDirectionIfPossibleChangeHandler }
151- inputProps = { { 'aria-label' : 'controlled' } }
133+ onChange = { ( _event , checked ) => setPreserveContrastDirectionIfPossible ( checked ) }
152134 />
153135 </ SettingsBox >
154136 </ Grid >
@@ -157,12 +139,11 @@ function App(): JSX.Element {
157139 < Typography gutterBottom > Background Color Override</ Typography >
158140 < Switch
159141 checked = { ! ! backgroundColorOverride }
160- onChange = { backgroundColorOverrideChangeHandler }
161- inputProps = { { 'aria-label' : 'controlled' } }
142+ onChange = { ( _event , checked ) => setBackgroundColorOverride ( checked ? '#000000' : undefined ) }
162143 />
163144 { backgroundColorOverride && (
164145 < >
165- < HexColorPicker style = { { margin : '15px auto' } } color = { backgroundColorOverride } onChange = { setBackgroundColorOverride } />
146+ < HexAlphaColorPicker style = { { margin : '15px auto' } } color = { backgroundColorOverride } onChange = { setBackgroundColorOverride } />
166147 < HexColorInput alpha color = { backgroundColorOverride } onChange = { setBackgroundColorOverride } />
167148 </ >
168149 ) }
0 commit comments