@@ -3,71 +3,65 @@ import PropTypes from 'prop-types'
33import TextareaAutosize from 'react-textarea-autosize'
44
55function useInputValue ( defaultValue ) {
6- const [ value , setValue ] = useState ( defaultValue )
7-
8- return {
9- bind : {
10- value,
11- onChange : event => setValue ( event . target . value )
12- } ,
13- clear : ( ) => setValue ( defaultValue ) ,
14- value : ( ) => value
15- }
6+ const [ value , setValue ] = useState ( defaultValue )
7+ return {
8+ bind : {
9+ value,
10+ onChange : event => setValue ( event . target . value )
11+ } ,
12+ clear : ( ) => setValue ( defaultValue ) ,
13+ value : ( ) => value
14+ }
1615}
1716
1817function AddCard ( { onCreate, onDeleteAll } ) {
18+ const input = useInputValue ( '' )
19+ const select = useInputValue ( 0 )
1920
20- const input = useInputValue ( '' )
21- const select = useInputValue ( 0 )
22-
23- function submitHandler ( ) {
24- if ( String ( input . value ( ) ) . trim ( ) && String ( select . value ( ) ) . trim ( ) ) {
25- onCreate ( { name : String ( input . value ( ) ) . trim ( ) , text : "" , sel : Boolean ( Number ( select . value ( ) ) ) } )
26- input . clear ( )
27- }
21+ function submitHandler ( ) {
22+ if ( String ( input . value ( ) ) . trim ( ) && String ( select . value ( ) ) . trim ( ) ) {
23+ onCreate ( { name : String ( input . value ( ) ) . trim ( ) , text : "" , sel : Boolean ( Number ( select . value ( ) ) ) } )
24+ input . clear ( )
2825 }
26+ }
27+
28+ return (
29+ < div className = "container" >
30+ < div className = "row my-2 text-center" >
31+
32+ < div className = "col-lg-12 col-md-12 p-1" >
33+ < TextareaAutosize type = "text" className = "form-control" placeholder = "Card name" id = "Text"
34+ { ...input . bind }
35+ style = { { resize : "none" } }
36+ minRows = { 1 }
37+ maxRows = { 3 }
38+ maxLength = "100"
39+ />
40+ </ div >
2941
30- return (
31-
32- < div className = "container" >
33- < div className = "row my-2 text-center" >
34-
35- < div className = "col-lg-12 col-md-12 p-1" >
36- < TextareaAutosize type = "text" className = "form-control" placeholder = "Card name" id = "Text"
37- { ...input . bind }
38- style = { { resize : "none" } }
39- minRows = { 1 }
40- maxRows = { 3 }
41- maxLength = "100"
42- />
43- </ div >
44-
45- < div className = "col-lg-8 col-md-6 col-sm-4 p-1" >
46- < select className = "custom-select" id = "Status" { ...select . bind } >
47- < option value = "1" > Done</ option >
48- < option value = "0" > Not done</ option >
49- </ select >
50- </ div >
51-
52- < div className = "col-lg-2 col-md-3 col-sm-4 col-6 p-1" >
53- < button disabled = { ! input . value ( ) . trim ( ) } className = "btn btn-success btn-block" onClick = { submitHandler } > < i className = "bi bi-clipboard-plus" > </ i > Add card</ button >
54- </ div >
42+ < div className = "col-lg-8 col-md-6 col-sm-4 p-1" >
43+ < select className = "custom-select" id = "Status" { ...select . bind } >
44+ < option value = "1" > Done</ option >
45+ < option value = "0" > Not done</ option >
46+ </ select >
47+ </ div >
5548
56- < div className = "col-lg-2 col-md-3 col-sm-4 col-6 p-1" >
57- < button className = "btn btn-danger btn-block" onClick = { onDeleteAll } > < i className = "bi bi-x-square " > </ i > Delete All </ button >
58- </ div >
49+ < div className = "col-lg-2 col-md-3 col-sm-4 col-6 p-1" >
50+ < button disabled = { ! input . value ( ) . trim ( ) } className = "btn btn-success btn-block" onClick = { submitHandler } > < i className = "bi bi-clipboard-plus " > </ i > Add card </ button >
51+ </ div >
5952
60- </ div >
53+ < div className = "col-lg-2 col-md-3 col-sm-4 col-6 p-1" >
54+ < button className = "btn btn-danger btn-block" onClick = { onDeleteAll } > < i className = "bi bi-x-square" > </ i > Delete All</ button >
6155 </ div >
6256
63- )
57+ </ div >
58+ </ div >
59+ )
6460}
6561
6662AddCard . propTypes = {
67- onCreate : PropTypes . func . isRequired ,
68- onDeleteAll : PropTypes . func . isRequired
63+ onCreate : PropTypes . func . isRequired ,
64+ onDeleteAll : PropTypes . func . isRequired
6965}
7066
7167export default AddCard
72-
73-
0 commit comments