11import { useState } from 'react'
22
3- import { Dialog , Switch } from '@headlessui/react'
3+ import { Dialog } from '@headlessui/react'
44
55import ImageUpload from "./ImageUpload" ;
66import GridSelect from "./GridSelect" ;
77import ImageDisplay from "./ImageDisplay" ;
88
9- export default function ImageEditorModal ( { isOpen, setIsOpen, tile, changeImage} ) {
10- const [ img , setImg ] = useState ( ) ;
9+ type ImageEditorModalProps = {
10+ isOpen : boolean ;
11+ setIsOpen : ( isOpen : boolean ) => void ;
12+ tile : { id ?: number } ;
13+ changeImage : ( code : string ) => void ;
14+ } ;
15+
16+ export default function ImageEditorModal ( { isOpen, setIsOpen, tile, changeImage} : ImageEditorModalProps ) {
17+ const [ img , setImg ] = useState < string > ( "" ) ;
1118
1219 const [ { col, row} , setGrid ] = useState ( {
1320 col : 1 ,
@@ -20,7 +27,7 @@ export default function ImageEditorModal({isOpen, setIsOpen, tile, changeImage})
2027 pixelSize : 16
2128 } ) ;
2229
23- const handleImageChange = ( src : any ) => {
30+ const handleImageChange = ( src : string ) => {
2431 setImg ( src ) ;
2532 }
2633
@@ -44,26 +51,27 @@ export default function ImageEditorModal({isOpen, setIsOpen, tile, changeImage})
4451 setIsOpen ( true )
4552 }
4653
47- function updateMaxColors ( newMaxColors ) {
48- if ( ! newMaxColors || isNaN ( newMaxColors ) ) newMaxColors = null ;
49- else if ( newMaxColors > 256 ) newMaxColors = 256 ;
50- else if ( newMaxColors < 1 ) newMaxColors = 1 ;
54+ function updateMaxColors ( newMaxColors : number | string ) {
55+ let numValue = typeof newMaxColors === 'string' ? parseInt ( newMaxColors ) : newMaxColors ;
56+ if ( ! numValue || isNaN ( numValue ) ) numValue = 256 ;
57+ else if ( numValue > 256 ) numValue = 256 ;
58+ else if ( numValue < 1 ) numValue = 1 ;
5159 setCompression ( {
52- maxColors : newMaxColors ,
60+ maxColors : numValue ,
5361 colorDepth : colorDepth ,
5462 pixelSize : pixelSize
5563 } ) ;
5664 }
5765
58- function updateColorDepth ( newColorDepth ) {
66+ function updateColorDepth ( newColorDepth : number ) {
5967 setCompression ( {
6068 maxColors : maxColors ,
6169 colorDepth : newColorDepth ,
6270 pixelSize : pixelSize
6371 } ) ;
6472 }
6573
66- function updatePixelSize ( newPixelSize ) {
74+ function updatePixelSize ( newPixelSize : number ) {
6775 setCompression ( {
6876 maxColors : maxColors ,
6977 colorDepth : colorDepth ,
@@ -128,7 +136,14 @@ export default function ImageEditorModal({isOpen, setIsOpen, tile, changeImage})
128136 < div className = "mx-4 lg:inline-block" > </ div >
129137
130138 < div className = "comp-inp" >
131- < input type = "number" min = "1" max = "256" className = "comp-inp-num" value = { maxColors } onChange = { ( ) => { updateMaxColors ( ( event . target as HTMLInputElement ) . value ) ; } } > </ input >
139+ < input
140+ type = "number"
141+ min = "1"
142+ max = "256"
143+ className = "comp-inp-num"
144+ value = { maxColors }
145+ onChange = { ( e ) => { updateMaxColors ( e . target . value ) ; } }
146+ />
132147 < label className = "comp-inp-num-label" > Colors</ label >
133148 </ div >
134149 </ div >
0 commit comments