diff --git a/public/index.html b/public/index.html index eb020eb..1b78027 100644 --- a/public/index.html +++ b/public/index.html @@ -40,6 +40,8 @@ To create a production bundle, use `npm run build` or `yarn build`. --> - + + + diff --git a/src/App.css b/src/App.css index 83cfb0c..77596ac 100644 --- a/src/App.css +++ b/src/App.css @@ -1,11 +1,144 @@ -button{ - width:100px; - height:100px; - background-color: gray; - margin: 10px; - font-size: 30px; + + +*, +*::before, +*::after { + box-sizing: border-box; +} + +@font-face { + font-family: calculator; + src: url("DS-DIGIB.TTF"); +} + +html{ + font-size: 16px; +} + +#calculator{ + width:550px; + margin:auto; + background: rgb(68,64,64); +background: linear-gradient(351deg, rgba(68,64,64,1) 0%, rgba(156,150,150,1) 100%); + padding: 1rem; + border-radius: 2rem; +} + +#calculator-content{ + display: grid; + grid-template-columns: repeat(4,1fr); + grid-template-rows: 1fr 1.6fr repeat(5,1fr); + grid-template-areas: + "header header header header" + "display display display display" + "functions functions functions operators" + "numbers numbers numbers operators" + "numbers numbers numbers operators" + "numbers numbers numbers operators" + "numbers numbers numbers operators" + ; + gap:1rem; +} + + +#calculator-content > header{ + grid-area: header; + font-family: 'Roboto', sans-serif; + +} + +#calculator-content > header > h1{ + font-size: 3rem; + margin:0.5rem auto; + color: aliceblue; + + opacity: 0.8; +} + +#display-container{ + grid-area: display; + justify-self: end; + align-self: end; + height:100%; + width:100%; + display: grid; + grid-template-rows: 1fr 6fr 1fr; + grid-template-areas: + "memory" + "main" + "operator" + ; + + + background: linear-gradient(351deg, rgba(15,93,53,1) 0%, rgba(194,228,185,1) 100%); + font-family: 'VT323', monospace; + font-size: 1rem; + border-radius: 0.5rem; + padding:0.5rem; + box-shadow: 0.5rem 0.5rem 2rem inset; +} + +#display-container > p { + margin:auto 0; + text-align: right; + line-height:1em; + opacity: 0.8; } #display{ - font-size: 26px;; + font-family: calculator; + font-size: 6rem; + grid-area: main; + align-self: center; + +} + +#memory{ + grid-area: memory; + align-self: center; + +} + +#operator{ + grid-area: operator; + align-self: center; + +} + + + + + +.num-pad{ + grid-area: numbers; + display: grid; + grid-template-columns: repeat(3,1fr); + grid-template-rows: repeat(4,1fr); + gap: 0.2rem; +} + +.operator-pad{ + grid-area: operators; + display: grid; + grid-template-rows: repeat(3,1fr) 2fr; + gap: 0.2rem; +} + +.function-pad{ + grid-area: functions; + display: grid; + grid-template-columns: repeat(3,1fr); + gap: 0.2rem; +} + + + +button{ + + background: rgb(92,92,92); +background: linear-gradient(351deg, rgba(92,92,92,1) 0%, rgba(224,224,224,1) 100%); + font-size: 30px; + place-self: stretch; + border-radius: 1.5rem; + } \ No newline at end of file diff --git a/src/Components/Calculator.js b/src/Components/Calculator.js index ef5cafb..d5d7c5d 100644 --- a/src/Components/Calculator.js +++ b/src/Components/Calculator.js @@ -1,107 +1,109 @@ import { useState } from "react"; import KeyPad from "./KeyPad"; -export default function Calculator(props){ - const [main,setMain] = useState("0") - const [memory,setMemory] = useState("") - const [operation,setOperation] = useState("") +export default function Calculator(props) { + const [main, setMain] = useState("0") + const [memory, setMemory] = useState("") + const [operation, setOperation] = useState("") const map = { - conc:(numberString)=>{ - if(main[0]==="0"){ - setMain(prev=>prev.slice(1)+numberString) - }else{ - setMain(prev=>prev+numberString) + conc: (numberString) => { + if (main[0] === "0") { + setMain(prev => prev.slice(1) + numberString) + } else { + setMain(prev => prev + numberString) } - + }, - zero:function(){this.conc("0")}, - one:function(){this.conc("1")}, - two:function(){this.conc("2")}, - three:function(){this.conc("3")}, - four:function(){this.conc("4")}, - five:function(){this.conc("5")}, - six:function(){this.conc("6")}, - seven:function(){this.conc("7")}, - eight:function(){this.conc("8")}, - nine:function(){this.conc("9")}, - decimal:function(){ - if(!/\./g.test(main)){ + zero: function () { this.conc("0") }, + one: function () { this.conc("1") }, + two: function () { this.conc("2") }, + three: function () { this.conc("3") }, + four: function () { this.conc("4") }, + five: function () { this.conc("5") }, + six: function () { this.conc("6") }, + seven: function () { this.conc("7") }, + eight: function () { this.conc("8") }, + nine: function () { this.conc("9") }, + decimal: function () { + if (!/\./g.test(main)) { this.conc(".") - } + } }, - add:function(){this.rcvOperator("add")}, - subtract:function(){this.rcvOperator("subtract")}, - multiply:function(){this.rcvOperator("multiply")}, - divide:function(){this.rcvOperator("divide")}, + add: function () { this.rcvOperator("add") }, + subtract: function () { this.rcvOperator("subtract") }, + multiply: function () { this.rcvOperator("multiply") }, + divide: function () { this.rcvOperator("divide") }, - rcvOperator:function(operator){ - if(main==="-"){ + rcvOperator: function (operator) { + if (main === "-") { setMain("") - }else if(main!==""){ - if(memory===""){ + } else if (main !== "") { + if (memory === "") { setMemory(main) - }else{ - setMemory(prev=>{return this.calculate(main,prev)}) + } else { + setMemory(prev => { return this.calculate(main, prev) }) } setMain("") } - if(main==="" && operator==="subtract"){ - setMain(prev=>{ - if(prev[0]!=="-"){ - return "-"+prev - } - }) - }else{ + if (main === "" && operator === "subtract") { + setMain(prev => { + if (prev[0] !== "-") { + return "-" + prev + } + }) + } else { setOperation(operator) } - + }, - operations:{ - add:(a,b)=>{return a+b}, - subtract:(a,b)=>{return b-a}, - multiply:(a,b)=>{return a*b}, - divide:(a,b)=>{return b/a}, - }, - - clear:()=>{ + operations: { + add: (a, b) => { return a + b }, + subtract: (a, b) => { return b - a }, + multiply: (a, b) => { return a * b }, + divide: (a, b) => { return b / a }, + }, + + clear: () => { setMain("0") setMemory("") setOperation("") }, - equals:function(){ - if(operation!=="" && main !==""){ - setMain(prev=>{ - return this.calculate(prev,memory) + equals: function () { + if (operation !== "" && main !== "") { + setMain(prev => { + return this.calculate(prev, memory) }) setMemory("") setOperation("") } - - }, - calculate:function(a,b){ - return this.operations[operation](parseFloat(a),parseFloat(b)).toString() - } - } - function handleInput(content){ + }, + calculate: function (a, b) { + return this.operations[operation](parseFloat(a), parseFloat(b)).toString() + } + } + + function handleInput(content) { map[content]() } - return( - <> -
-

{"memory: "+memory}

-

{main}

-

{"operation: "+operation}

+ return ( +
+
+

CALCULATOR

+
+

{memory}

+

{main}

+

{operation}

+
+ +
- - - ) } \ No newline at end of file diff --git a/src/Components/KeyPad.js b/src/Components/KeyPad.js index ebd24b2..ec1aae7 100644 --- a/src/Components/KeyPad.js +++ b/src/Components/KeyPad.js @@ -1,30 +1,36 @@ import Button from "./Button" export default function NumPad(props){ const numberMap = { - zero:0, - one:1, - two:2, - three:3, - four:4, - five:5, - six:6, + seven:7, eight:8, nine:9, - decimal:"." + four:4, + five:5, + six:6, + one:1, + two:2, + three:3, + zero:0, + decimal:".", + equals:"=" + } const operatorMap = { - add:"+", + subtract:"-", multiply:"x", divide:"/", + add:"+", } const functionMap = { + on:"on", + off:"off", clear:"C", - equals:"=" + } function buildButtons(map){ @@ -43,7 +49,7 @@ export default function NumPad(props){ return( -
+ <>
{buildButtons(numberMap)}
@@ -53,6 +59,6 @@ export default function NumPad(props){
{buildButtons(functionMap)}
-
+ ) } \ No newline at end of file diff --git a/src/DS-DIGIB.TTF b/src/DS-DIGIB.TTF new file mode 100644 index 0000000..064ad47 Binary files /dev/null and b/src/DS-DIGIB.TTF differ diff --git a/src/digital-7 (mono).ttf b/src/digital-7 (mono).ttf new file mode 100644 index 0000000..a481b97 Binary files /dev/null and b/src/digital-7 (mono).ttf differ