props drilled
This commit is contained in:
parent
6f61edc8ce
commit
b6918fd7cc
|
@ -22,7 +22,7 @@ export default function Calculator(props){
|
|||
|
||||
if(typeof content === "number" ){
|
||||
setMain(prev=>{return prev.toString()+content.toString()})
|
||||
}else if(content == "."){
|
||||
}else if(content === "."){
|
||||
//HANDLE DECIMAL WITH REGEX
|
||||
}else if(operations[content]){
|
||||
setMemory(prev=>{operations[content](prev,main)})
|
||||
|
|
|
@ -1,28 +1,32 @@
|
|||
import Button from "./Button"
|
||||
export default function NumPad(props){
|
||||
const map = {
|
||||
zero:{number:0,callback:""},
|
||||
one:{number:1,callback:""},
|
||||
two:{number:2,callback:""},
|
||||
three:{number:3,callback:""},
|
||||
four:{number:4,callback:""},
|
||||
five:{number:5,callback:""},
|
||||
six:{number:6,callback:""},
|
||||
seven:{number:7,callback:""},
|
||||
eight:{number:8,callback:""},
|
||||
nine:{number:9,callback:""}
|
||||
zero:0,
|
||||
one:1,
|
||||
two:2,
|
||||
three:3,
|
||||
four:4,
|
||||
five:5,
|
||||
six:6,
|
||||
seven:7,
|
||||
eight:8,
|
||||
nine:9
|
||||
}
|
||||
const numPad = Object.keys(map).map((e,i)=>{
|
||||
return(
|
||||
<Button id={e} number={map[e].number} key={"numPad"+e} callback={map[e]}>
|
||||
<Button
|
||||
id={e}
|
||||
content={map[e]}
|
||||
key={"numPad"+e}
|
||||
handleInput={props.handleInput}>
|
||||
{i}
|
||||
</Button>
|
||||
)
|
||||
})
|
||||
|
||||
return(
|
||||
<>
|
||||
<div className="numPad">
|
||||
{numPad}
|
||||
</>
|
||||
</div>
|
||||
)
|
||||
}
|
|
@ -1,19 +1,23 @@
|
|||
import Button from "./Button";
|
||||
export default function Operators(props){
|
||||
const map = {
|
||||
add:{symbol:"+",callback:""},
|
||||
subtract:{symbol:"-",callback:""},
|
||||
multiply:{symbol:"x",callback:""},
|
||||
divide:{symbol:"/",callback:""},
|
||||
decimal:{symbol:".",callback:""}
|
||||
add:"+",
|
||||
subtract:"-",
|
||||
multiply:"x",
|
||||
divide:"/",
|
||||
decimal:"."
|
||||
}
|
||||
|
||||
const operators = Object.keys(map).map(e=>{
|
||||
return <Button id={e} callback={map[e].callback} key={e}>
|
||||
{map[e].symbol}
|
||||
return <Button
|
||||
id={e}
|
||||
content={map[e]}
|
||||
handleInput={props.handleInput}
|
||||
key={e}>
|
||||
{map[e]}
|
||||
</Button>
|
||||
})
|
||||
|
||||
return ( <>{operators}</>)
|
||||
return ( <div className="operations-pad">{operators}</div>)
|
||||
|
||||
}
|
Loading…
Reference in New Issue