calculator/src/Components/KeyPad.js

64 lines
1.2 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-07 17:28:27 +00:00
2023-07-04 15:26:43 +00:00
seven:7,
eight:8,
nine:9,
2023-07-07 17:28:27 +00:00
four:4,
five:5,
six:6,
one:1,
two:2,
three:3,
zero:0,
decimal:".",
equals:"="
2023-07-05 18:48:13 +00:00
}
const operatorMap = {
2023-07-07 17:28:27 +00:00
subtract:"-",
multiply:"x",
divide:"/",
2023-07-07 17:28:27 +00:00
add:"+",
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 = {
2023-07-07 17:28:27 +00:00
on:"on",
off:"off",
clear:"C",
2023-07-07 17:28:27 +00:00
}
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(
2023-07-07 17:28:27 +00:00
<>
<div className="num-pad">
{buildButtons(numberMap)}
</div>
<div className="operator-pad">
{buildButtons(operatorMap)}
</div>
<div className="function-pad">
{buildButtons(functionMap)}
</div>
2023-07-07 17:28:27 +00:00
</>
2023-07-04 11:15:57 +00:00
)
}