Skip to content

Commit 6992787

Browse files
committed
Refactor Calculator to use styled components
1 parent 44d1d3c commit 6992787

5 files changed

Lines changed: 95 additions & 90 deletions

File tree

src/programs/Calculator/Calculator.scss

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/programs/Calculator/Calculator.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { useEffect, useState } from "react";
22

3-
import "./Calculator.scss";
3+
import {
4+
StyledButton,
5+
StyledButtonContent,
6+
StyledButtons,
7+
StyledCalc,
8+
StyledInputOutput,
9+
StyledInputOutputContents,
10+
} from "./styles";
411

512
interface CalculatorProps {}
613

@@ -55,24 +62,22 @@ function Calculator({}: CalculatorProps) {
5562
}
5663

5764
return (
58-
<div className="calculator__button normal" onClick={handleClick}>
59-
<span className="calculator_button-contents">{displayChar}</span>
60-
</div>
65+
<StyledButton onClick={handleClick}>
66+
<StyledButtonContent>{displayChar}</StyledButtonContent>
67+
</StyledButton>
6168
);
6269
}
6370

6471
return (
65-
<div className="calculator">
66-
<div className="calculator__input">
67-
<div className="calculator__input-contents">{input}</div>
68-
</div>
69-
<div className="calculator__output">
70-
<div className="calculator__output-contents">{output}</div>
71-
</div>
72-
<div className="calculator__buttons">
72+
<StyledCalc>
73+
<StyledInputOutput direction="input">
74+
<StyledInputOutputContents>{input}</StyledInputOutputContents>
75+
</StyledInputOutput>
76+
<StyledInputOutput direction="output">
77+
<StyledInputOutputContents>{output}</StyledInputOutputContents>
78+
</StyledInputOutput>
79+
<StyledButtons>
7380
<Button mathematicalChar={"AC"} action="clear" />
74-
{/* <Button mathematicalChar={8} action="append-to-end" />
75-
<Button mathematicalChar={'%'} action="append-to-end" /> */}
7681
<div />
7782
<div />
7883
<Button mathematicalChar="/" displayChar="÷" action="append-to-end" />
@@ -93,8 +98,8 @@ function Calculator({}: CalculatorProps) {
9398
<Button mathematicalChar="." action="append-to-end" />
9499
<Button mathematicalChar="←" action="remove-from-end" />
95100
<Button mathematicalChar="=" action="evaluate" />
96-
</div>
97-
</div>
101+
</StyledButtons>
102+
</StyledCalc>
98103
);
99104
}
100105

src/programs/Calculator/CalculatorLauncher/CalculatorLauncher.scss

Whitespace-only changes.

src/programs/Calculator/CalculatorLauncher/CalculatorLauncher.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Calculator from "..";
22
import Launcher from "../../../components/BottomBar/Launcher";
3-
import "./CalculatorLauncher.scss";
43

54
interface CalculatorLauncherProps {}
65

src/programs/Calculator/styles.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import styled from "@emotion/styled";
2+
3+
export const StyledCalc = styled.div`
4+
width: 100%;
5+
height: 100%;
6+
display: grid;
7+
grid-template-rows: 1fr 1fr 3fr;
8+
grid-template-areas:
9+
"input"
10+
"output"
11+
"buttons";
12+
box-shadow: 0px 0px 4px rgb(0, 0, 0, 0.5) inset;
13+
padding: 10px;
14+
border-radius: 10px;
15+
box-sizing: border-box;
16+
gap: 10px;
17+
`;
18+
19+
export const StyledInputOutput = styled.div<{
20+
direction: "input" | "output";
21+
}>`
22+
box-shadow: 0px 0px 4px rgb(0, 0, 0, 0.5) inset;
23+
width: 100%;
24+
height: 100%;
25+
display: flex;
26+
justify-content: flex-end;
27+
align-items: center;
28+
padding: 20px;
29+
box-sizing: border-box;
30+
grid-area: ${(props) => props.direction};
31+
`;
32+
33+
export const StyledInputOutputContents = styled.div`
34+
text-shadow: 2px 2px 4px rgb(0, 0, 0, 0.5);
35+
`;
36+
37+
export const StyledButtons = styled.div`
38+
min-height: 0;
39+
grid-area: buttons;
40+
width: 100%;
41+
height: 100%;
42+
justify-self: center;
43+
display: grid;
44+
grid-template-columns: 1fr 1fr 1fr 1fr;
45+
grid-template-rows: 1fr 1fr 1fr 1fr 1fr;
46+
box-sizing: border-box;
47+
`;
48+
49+
export const StyledButton = styled.button`
50+
text-align: center;
51+
cursor: default;
52+
border-radius: 20px;
53+
justify-self: center;
54+
width: 80%;
55+
height: 80%;
56+
box-shadow: 2px 2px 4px rgb(0, 0, 0, 0.5);
57+
box-sizing: border-box;
58+
display: flex;
59+
justify-content: center;
60+
align-items: center;
61+
background-color: inherit;
62+
color: inherit;
63+
border-width: 1px;
64+
65+
&:hover {
66+
backdrop-filter: brightness(150%);
67+
transition: ease-in 0.2s;
68+
}
69+
&:active {
70+
box-shadow: 2px 2px 4px rgb(0, 0, 0, 0.5) inset;
71+
}
72+
`;
73+
74+
export const StyledButtonContent = styled.span``;

0 commit comments

Comments
 (0)