calculator/src/Components/KeyPad.js

58 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-07-04 11:15:57 +00:00
import Button from "./Button"
export default function NumPad(props){
2023-07-05 18:48:13 +00:00
const numberMap = {
2023-07-04 15:26:43 +00:00
zero:0,
one:1,
two:2,
three:3,
four:4,
five:5,
six:6,
seven:7,
eight:8,
nine:9,
2023-07-05 18:48:13 +00:00
decimal:"."
}
const operatorMap = {
add:"+",
subtract:"-",
multiply:"x",
divide:"/",
2023-07-05 18:48:13 +00:00
2023-07-04 11:15:57 +00:00
}
2023-07-05 18:48:13 +00:00
const functionMap = {
clear:"C",
equals:"="
}
2023-07-05 18:48:13 +00:00
function buildButtons(map){
return Object.keys(map).map((e,i)=>{
return(
<Button
id={e}
content={map[e]}
key={e+i}
handleInput={()=>props.handleInput(e)}>
{map[e]}
</Button>
)
})
}
2023-07-05 18:48:13 +00:00
2023-07-04 11:15:57 +00:00
return(
<div className="keypad">
<div className="num-pad">
{buildButtons(numberMap)}
</div>
<div className="operator-pad">
{buildButtons(operatorMap)}
</div>
<div className="function-pad">
{buildButtons(functionMap)}
</div>
2023-07-04 15:26:43 +00:00
</div>
2023-07-04 11:15:57 +00:00
)
}