11import React , { useState } from 'react'
22import PropTypes from 'prop-types'
33import TextareaAutosize from 'react-textarea-autosize'
4+ import Palette , { colors } from './palette/palette'
45
56function useInputValue ( defaultValue ) {
67 const [ value , setValue ] = useState ( defaultValue )
@@ -16,20 +17,36 @@ function useInputValue(defaultValue) {
1617
1718function AddCard ( { onCreate, onDeleteAll } ) {
1819 const input = useInputValue ( '' )
19- const select = useInputValue ( 0 )
20+
21+ const defColor = colors [ 0 ]
22+ const [ color , setColor ] = React . useState ( defColor )
23+ const blackOnHover = ( ) => {
24+ switch ( color ) {
25+ case colors [ 0 ] :
26+ case colors [ 2 ] :
27+ case colors [ 3 ] :
28+ case colors [ 4 ] :
29+ case colors [ 6 ] :
30+ case colors [ 8 ] :
31+ return true
32+ default :
33+ return false
34+ }
35+ }
2036
2137 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 ( ) ) ) } )
38+ if ( String ( input . value ( ) ) . trim ( ) && String ( color ) . trim ( ) ) {
39+ onCreate ( { name : String ( input . value ( ) ) . trim ( ) , text : "" , color : String ( color ) } )
2440 input . clear ( )
41+ setColor ( defColor )
2542 }
2643 }
2744
2845 return (
2946 < div className = "container" >
3047 < div className = "row my-2 text-center" >
3148
32- < div className = "col-lg-12 col-md-12 p-1" >
49+ < div className = "col-lg-9 col-md-10 col -12 p-1" >
3350 < TextareaAutosize type = "text" className = "form-control" placeholder = "Card name" id = "Text"
3451 { ...input . bind }
3552 style = { { resize : "none" } }
@@ -39,19 +56,15 @@ function AddCard({ onCreate, onDeleteAll }) {
3956 />
4057 </ div >
4158
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 >
48-
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 >
59+ < div className = "col-lg-1 col-md-1 col-sm-3 col-4 p-1" >
60+ < Palette setColor = { setColor } className = { `btn btn-outline-secondary palitra-btn ${ blackOnHover ( ) ? "palitra-blackOnHover" : "palitra-lightOnHover" } ` } style = { { width : "100%" , background : color } } > </ Palette >
5161 </ div >
5262
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 >
63+ < div className = "col-lg-2 col-md-1 col p-1" >
64+ < button disabled = { ! input . value ( ) . trim ( ) } className = "btn btn-success btn-block" onClick = { submitHandler } >
65+ < i className = "bi bi-clipboard-plus" > </ i >
66+ < span className = 'd-lg-inline d-none' > Add card</ span >
67+ </ button >
5568 </ div >
5669
5770 </ div >
0 commit comments