CountButton.js 1.06 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
const CountButton = ({name, count, setCount}) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
2
3
    function handleCount(event) {
        if (event.target.name === "backbutton") {
Kim, Subin's avatar
Kim, Subin committed
4
            setCount({...count, [name] :count[name] - 1})
Jiwon Yoon's avatar
Jiwon Yoon committed
5
        } else if (event.target.name === "forwardbutton") {
Kim, Subin's avatar
Kim, Subin committed
6
            setCount({...count, [name] :count[name] + 1})
Jiwon Yoon's avatar
Jiwon Yoon committed
7
        } else {
Kim, Subin's avatar
Kim, Subin committed
8
            setCount({...count, [name] :event.target.value})
Jiwon Yoon's avatar
Jiwon Yoon committed
9
10
11

        }
    }
Kim, Subin's avatar
Kim, Subin committed
12
    
Jiwon Yoon's avatar
Jiwon Yoon committed
13
    return (
Kim, Subin's avatar
Kim, Subin committed
14
        <>
Jiwon Yoon's avatar
Jiwon Yoon committed
15
16
17
            <button type="button" name="backbutton" style={{ backgroundColor: "black", border: "0" }} onClick={handleCount}>
                <img src="/images/icons8-back-24.png" name="backbutton" alt="<" />
            </button>
Kim, Subin's avatar
Kim, Subin committed
18
            <input type='number' onChange={handleCount} value={count[name]} style={{ width: '2rem' }} className="text-center" />
Jiwon Yoon's avatar
Jiwon Yoon committed
19
20
21
            <button type="button" name="forwardbutton" min="0" style={{ backgroundColor: "black", border: "0" }} onClick={handleCount}>
                <img src="/images/icons8-forward-24.png" name="forwardbutton" alt=">" />
            </button>
Kim, Subin's avatar
Kim, Subin committed
22
        </>
Jiwon Yoon's avatar
Jiwon Yoon committed
23
24
25
26
    )
}

export default CountButton