Skip to content

Commit b98732f

Browse files
committed
Refactor calculator buttons
1 parent 2fc5b40 commit b98732f

File tree

2 files changed

+21
-33
lines changed

2 files changed

+21
-33
lines changed

src/programs/Calculator/Calculator.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import {
77
} from "react";
88

99
import {
10-
StyledButton,
11-
StyledButtonContent,
1210
StyledButtons,
1311
StyledCalc,
1412
StyledInputOutput,
1513
StyledInputOutputContents,
1614
} from "./styles";
1715
import { BorderedAppContentHandles } from "../../components/BorderedApp/BorderedApp";
1816
import useSystemSettings from "../../stores/systemSettingsStore";
17+
import CommonButton from "../../components/Button";
1918

2019
export type CalculatorHandles = BorderedAppContentHandles<HTMLDivElement>;
2120

@@ -29,7 +28,13 @@ const Calculator = forwardRef<CalculatorHandles, CalculatorProps>(
2928
const elementRef = useRef<HTMLDivElement>(null);
3029
const [input, setInput] = useState<string>("");
3130
const [output, setOutput] = useState<string>("");
32-
const [scrollbarColor] = useSystemSettings((s) => [s.iconColor]);
31+
const [scrollbarColor, buttonColor, fontColor, primaryButtonColor] =
32+
useSystemSettings((s) => [
33+
s.iconColor,
34+
s.secondaryColor,
35+
s.fontColor,
36+
s.primaryColor,
37+
]);
3338
const appendToInput = (value: string) =>
3439
setInput((current) => current + value);
3540
const removeFromEnd = (count: number = 1) =>
@@ -117,9 +122,18 @@ const Calculator = forwardRef<CalculatorHandles, CalculatorProps>(
117122
}
118123

119124
return (
120-
<StyledButton onClick={handleClick}>
121-
<StyledButtonContent>{displayChar}</StyledButtonContent>
122-
</StyledButton>
125+
<CommonButton
126+
onClick={handleClick}
127+
width={"100%"}
128+
height={"100%"}
129+
borderRadius={12}
130+
backgroundColor={
131+
displayChar === "=" ? primaryButtonColor : buttonColor
132+
}
133+
color={fontColor}
134+
>
135+
{displayChar}
136+
</CommonButton>
123137
);
124138
}
125139

src/programs/Calculator/styles.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,8 @@ export const StyledButtons = styled.div`
5050
height: 100%;
5151
justify-self: center;
5252
display: grid;
53+
gap: 4px;
5354
grid-template-columns: 1fr 1fr 1fr 1fr;
5455
grid-template-rows: 1fr 1fr 1fr 1fr 1fr;
5556
box-sizing: border-box;
5657
`;
57-
58-
export const StyledButton = styled.button`
59-
text-align: center;
60-
cursor: default;
61-
border-radius: 20px;
62-
justify-self: center;
63-
width: 80%;
64-
height: 80%;
65-
box-shadow: 2px 2px 4px rgb(0, 0, 0, 0.5);
66-
box-sizing: border-box;
67-
display: flex;
68-
justify-content: center;
69-
align-items: center;
70-
background-color: inherit;
71-
color: inherit;
72-
border: none;
73-
74-
&:hover {
75-
backdrop-filter: brightness(150%);
76-
transition: ease-in 0.2s;
77-
}
78-
&:active {
79-
box-shadow: 2px 2px 4px rgb(0, 0, 0, 0.5) inset;
80-
}
81-
`;
82-
83-
export const StyledButtonContent = styled.span``;

0 commit comments

Comments
 (0)