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

feat/calculator - add calculator functionallity #118

Merged
merged 46 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
5c59e5b
wip
nirtamir2 May 26, 2021
67e3d7a
wip
nirtamir2 May 26, 2021
9127663
wip
nirtamir2 May 28, 2021
9e9b761
add reducer
nirtamir2 Jun 3, 2021
c5f3b52
add tests
nirtamir2 Jun 4, 2021
a4f5efb
tests
nirtamir2 Jun 4, 2021
6200f7a
tests
nirtamir2 Jun 4, 2021
1710395
tests
nirtamir2 Jun 4, 2021
5016587
operator after equal fix
nirtamir2 Jun 4, 2021
af7ddc2
refactor
nirtamir2 Jun 5, 2021
9d3259f
rename
nirtamir2 Jun 5, 2021
ff9f9ff
tests
nirtamir2 Jun 5, 2021
974f31f
simplify tests
nirtamir2 Jun 14, 2021
a16d14e
fix +/-
nirtamir2 Jun 14, 2021
9e0c9e5
fix lock file
nirtamir2 Jun 17, 2021
8d09949
main deps
nirtamir2 Jun 17, 2021
225c846
my deps
nirtamir2 Jun 17, 2021
be99cc4
tdd - show first number
nirtamir2 Jun 17, 2021
5fdd7df
show first number with decimal point
nirtamir2 Jun 18, 2021
f4eb45b
show first number with decimal point
nirtamir2 Jun 18, 2021
8773dc1
refactor
nirtamir2 Jun 18, 2021
1a5e487
refactor - init number to 0
nirtamir2 Jun 18, 2021
010a87a
refactor
nirtamir2 Jun 18, 2021
8c1a91b
operator
nirtamir2 Jun 18, 2021
48793f1
equal
nirtamir2 Jun 18, 2021
5d68e12
equal
nirtamir2 Jun 18, 2021
eab660f
equal
nirtamir2 Jun 18, 2021
3da8ae5
multiple operator fixes
nirtamir2 Jun 18, 2021
31f3cd5
multi-operators
nirtamir2 Jun 18, 2021
86c2283
decimal math
nirtamir2 Jun 18, 2021
1f3abb0
refactor
nirtamir2 Jun 18, 2021
7fa6f3d
refactor
nirtamir2 Jun 18, 2021
536f016
decimal numbers math
nirtamir2 Jun 19, 2021
2f6d689
fix tests
nirtamir2 Jun 19, 2021
b8b2f53
operators
nirtamir2 Jun 19, 2021
e390dbf
enable replace operator
nirtamir2 Jun 19, 2021
5bbf786
reset equation on dot after =
nirtamir2 Jun 25, 2021
774a89e
+- operator
nirtamir2 Jun 26, 2021
6800db6
+- operator
nirtamir2 Jun 26, 2021
c32d55b
% operator
nirtamir2 Jun 26, 2021
91105b3
refactor unary operator
nirtamir2 Jun 26, 2021
3e0defe
better tests for firstNumberInput
nirtamir2 Jun 26, 2021
1387410
treat % as binary operator when second input
nirtamir2 Jun 26, 2021
ca6f9ca
test % with multiple =
nirtamir2 Jun 26, 2021
3e9374c
remove comment
nirtamir2 Jun 26, 2021
267c4ae
remove useless @testing-library
nirtamir2 Jun 26, 2021
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
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
'^@__/(.*)$': '<rootDir>/src/$1',
},
};
20,365 changes: 18,211 additions & 2,154 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"scripts": {
"start": "vite",
"type-check": "tsc --noEmit",
"type-check-watch": "tsc src/**/*.{ts,tsx} --noEmit --watch",
"build": "tsc && vite build",
"test": "jest",
"postbuild": "workbox generateSW workbox-config.js",
"serve": "vite preview"
},
Expand All @@ -20,9 +23,13 @@
},
"devDependencies": {
"@preact/preset-vite": "^2.1.0",
"@types/jest": "^26.0.23",
"@types/react": "^17.0.11",
"autoprefixer": "^10.2.6",
"jest": "^27.0.4",
"prettier": "^2.3.1",
"sass": "^1.34.1",
"ts-jest": "^27.0.3",
"typescript": "^4.3.2",
"typescript-plugin-css-modules": "^3.4.0",
"vite": "^2.2.4",
Expand Down
38 changes: 38 additions & 0 deletions src/components/apps/Calculator/Calculator.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,49 @@
font-family: var(--app-font-family) !important;
}

.buttonsContainer {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(5, 1fr);
gap: 0.9px;

margin: 1.5px;

& > button {
font-size: 1.618rem;
font-weight: 300 !important;
color: white;
fill: white;
}
}

.topRowButton {
background-color: hsla(0, 0%, 35%, 0.6);
}

.numberButton {
background-color: hsla(0, 0%, 45%, 0.6);
}

.operationButton {
background-color: hsla(33, 87%, 59%, 1);
}

.curvedBottomLeftButton {
border-radius: 0 0 0 0.7rem;
}

.curvedBottomRightButton {
border-radius: 0 0 0.7rem 0;
}

.showArea {
font-size: 3rem;
color: white;
text-align: end;
font-weight: 200;

overflow: auto;

padding: 0.5rem 1rem;
}
93 changes: 89 additions & 4 deletions src/components/apps/Calculator/Calculator.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,98 @@
import { useReducer } from 'react';
import { mdiClose, mdiDivision, mdiMinus, mdiPercentOutline, mdiPlusMinusVariant } from '@mdi/js';
import clsx from 'clsx';
import { CalculatorButtonsArea } from './CalculatorButtonsArea/CalculatorButtonsArea';
import { AppIcon } from '__/components/utils/AppIcon';
import {
ActionT,
CalculatorKeyT,
calculatorReducer,
initialState,
IState,
} from './calculatorReducer';
import css from './Calculator.module.scss';

const Calculator = () => {
const [state, dispatch] = useReducer<React.Reducer<IState, ActionT>>(
calculatorReducer,
initialState,
);

const { result } = state;

function handlePress(key: CalculatorKeyT) {
dispatch({ type: 'Press', payload: key });
}

return (
<section class={css.container}>
<header class={clsx('app-window-drag-handle', css.header)}></header>
<section class={css.showArea}>0</section>
<CalculatorButtonsArea />
<header class={clsx('app-window-drag-handle', css.header)} />
<section class={css.showArea}>{result}</section>
<section class={css.buttonsContainer}>
<button class={css.topRowButton} onClick={() => handlePress('AC')}>
AC
</button>
<button class={css.topRowButton} onClick={() => handlePress('+/-')}>
<AppIcon path={mdiPlusMinusVariant} />
</button>
<button class={css.topRowButton} onClick={() => handlePress('%')}>
<AppIcon path={mdiPercentOutline} />
</button>
<button class={css.operationButton} onClick={() => handlePress('/')}>
<AppIcon path={mdiDivision} />
</button>
<button class={css.numberButton} onClick={() => handlePress(7)}>
7
</button>
<button class={css.numberButton} onClick={() => handlePress(8)}>
8
</button>
<button class={css.numberButton} onClick={() => handlePress(9)}>
9
</button>
<button class={css.operationButton} onClick={() => handlePress('*')}>
<AppIcon path={mdiClose} />
</button>
<button class={css.numberButton} onClick={() => handlePress(4)}>
4
</button>
<button class={css.numberButton} onClick={() => handlePress(5)}>
5
</button>
<button class={css.numberButton} onClick={() => handlePress(6)}>
6
</button>
<button class={css.operationButton} onClick={() => handlePress('-')}>
<AppIcon path={mdiMinus} size={24} />
</button>
<button class={css.numberButton} onClick={() => handlePress(1)}>
1
</button>
<button class={css.numberButton} onClick={() => handlePress(2)}>
2
</button>
<button class={css.numberButton} onClick={() => handlePress(3)}>
3
</button>
<button class={css.operationButton} onClick={() => handlePress('+')}>
+
</button>
<button
class={clsx(css.numberButton, css.curvedBottomLeftButton)}
style={{ gridColumn: '1 / span 2' }}
onClick={() => handlePress(0)}
>
0
</button>
<button class={css.numberButton} onClick={() => handlePress('.')}>
.
</button>
<button
class={clsx(css.operationButton, css.curvedBottomRightButton)}
onClick={() => handlePress('=')}
>
=
</button>
</section>
</section>
);
};
Expand Down

This file was deleted.

This file was deleted.

Loading