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

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

export default CountButton