Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup/UI #3

Merged
merged 8 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"predeploy":"npm run build",
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" href="https://img.icons8.com/officel/16/calculator.png" type="image/x-icon">
<title>Mathmagician</title>
</head>
<body>
Expand Down
5 changes: 4 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const App = () => <>Mathmagician</>;
import Calculator from './Components/Calculator';
import './style.css';

const App = () => <main className="container"><Calculator /></main>;

export default App;
15 changes: 15 additions & 0 deletions src/Components/Button.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import PropTypes from 'prop-types';

const Button = ({ value, className }) => <button type="button" className={className}>{value}</button>;

Button.propTypes = {
value: PropTypes.string,
className: PropTypes.string,
};

Button.defaultProps = {
value: '',
className: '',
};

export default Button;
23 changes: 23 additions & 0 deletions src/Components/Calculator.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Button from './Button';
import Result from './Result';

const Calculator = () => {
const btns = ['AC', '+/-', '%', '÷', '7', '8', '9', 'X', '4', '5', '6', '-',
'1', '2', '3', '+', '0', '.', '='];
return (
<section className="calculator">
<Result value="0" />
{btns.map((btn) => {
if (['÷', '-', '=', '+', 'X'].includes(btn)) {
return <Button key={btn} value={btn} className="btn border bg-2" />;
}
if (btn === '0') {
return <Button key={btn} value={btn} className="btn border zero-btn bg-1" />;
}
return <Button key={btn} value={btn} className="btn border bg-1" />;
})}
</section>
);
};

export default Calculator;
10 changes: 10 additions & 0 deletions src/Components/Result.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
const Result = ({ value }) => (
<>
<div className="result">
<span className="result__value">{value}</span>
</div>
</>
);

export default Result;
58 changes: 58 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
:root {
--primary-color: rgba(243, 243, 243, 0.897);
--secondary-dark-color: hsl(0, 0%, 54%);
--secondary-light-color: hsl(36, 90%, 49%);

font-size: 16px;
}

* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}

.container {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}

.calculator {
border: 1px solid var(--primary-color);
display: grid;
grid-template-columns: repeat(4, 1fr);
}

.result {
grid-column: 1 / 5;
display: flex;
justify-content: flex-end;
align-items: center;
padding: 2rem 0.5rem;
background-color: var(--secondary-dark-color);
}

.result__value {
color: white;
font-size: 2.5rem;
}

.btn {
padding: 2.5rem 3rem;
cursor: pointer;
font-size: 1.5rem;
}

.zero-btn {
grid-column: 1 / 3;
}

.border {
border: 1px solid #e0e0e0;
}

.bg-1 {
background-color: var(--primary-color);
}

.bg-2 {
background-color: var(--secondary-light-color);
}