1- import React , { Component } from 'react' ;
2- import { InputHandler } from '../InputHandler/InputHandler.js' ;
3-
4-
1+ import React , { Component } from 'react'
2+ import { InputHandler } from '../InputHandler/InputHandler.js'
3+ import { Options } from './options/Options.js' ;
54
65class InputField extends Component {
76
@@ -16,38 +15,28 @@ class InputField extends Component {
1615 const { inputArrayLength} = this . props . InputHandler . state ;
1716
1817 return (
19- < div className = { this . name [ 0 ] + ' ' } >
20- < p className = { this . name [ 1 ] + ' ' } > Array size should not
21- exceed { InputHandler . getAllowedMaxInputSize ( ) } .</ p >
22- < div className = "flex" >
23- < input placeholder = "Enter array size"
24- value = { inputArrayLength }
25- onChange = { ( e ) => {
26- ( Number ( e . target . value ) || ! e . target . value )
27- &&
28- ( e . target . value <= InputHandler . getAllowedMaxInputSize ( ) )
29- ?
30- this . props . InputHandler . setState (
31- { inputArrayLength : e . target . value . replace ( / \D / g, '' ) } )
32- :
33- this . props . InputHandler . setState (
34- { inputArrayLength : InputHandler . getAllowedMaxInputSize ( ) } ) ;
35- } }
36- className = " bg-gray-200 rounded-md text-center p-2 font-medium"
37- maximum = { InputHandler . getAllowedMaxInputSize ( ) }
18+ < div className = { `flex items-center justify-around border-b p-3 w-sreen flex-wrap ${ this . name [ 0 ] + ' ' } ` } >
19+ < div >
20+ < div className = "flex" >
21+ < input placeholder = "Enter array size" value = { inputArrayLength } onChange = { ( e ) => {
22+ // SG 07/07/2022 21:03 Input validation, only accepts a number that is less than the allowed array size
23+ ( Number ( e . target . value ) || ! e . target . value )
24+ && ( e . target . value <= InputHandler . getAllowedMaxInputSize ( ) )
25+ ? this . props . InputHandler . setState ( { inputArrayLength : e . target . value . replace ( / \D / g, '' ) } )
26+ : this . props . InputHandler . setState ( { inputArrayLength : InputHandler . getAllowedMaxInputSize ( ) } )
27+ } }
28+ className = " bg-gray-200 rounded-md text-center p-[.5em] font-medium"
29+ maximum = { InputHandler . getAllowedMaxInputSize ( ) }
3830 />
39- < button onClick = { ( ) => {
40- this . props . InputHandler . setState ( {
41- generatedArray : InputHandler . handleInputRequest (
42- inputArrayLength ) ,
43- } ) ;
44- } }
45- className = "bg-blue-300 p-2 ml-3 rounded-md text-white font-medium hover:scale-[1.02] hover:bg-blue-400 transition duration-200 ease-in-out" > Generate
46- Array
47- </ button >
31+ < button onClick = { ( ) => {
32+ this . props . InputHandler . setState ( { generatedArray : InputHandler . handleInputRequest ( inputArrayLength ) } ) ;
33+ } } className = "bg-blue-300 p-2 ml-3 rounded-md text-white font-medium hover:scale-[1.02] hover:bg-blue-400 transition duration-200 ease-in-out" > Generate Array</ button >
4834 </ div >
35+ < p className = { `text-gray-700 mt-1 ${ this . name [ 1 ] + ' ' } ` } > Array size should not exceed { InputHandler . getAllowedMaxInputSize ( ) } .</ p >
4936 </ div >
50- ) ;
37+ < Options options = { this . props . InputHandler } />
38+ </ div >
39+ )
5140 }
5241}
5342
0 commit comments