mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
style(Calculator): Fixed text overflow on input
This commit is contained in:
1 parent
0cace5660a
commit
4a59ed0d46
2 files changed
+51
-46
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
import React from "react";
|
import React from 'react';
|
||||||
import { useCalculator, CalcButton } from "../hooks/useCalculator";
|
import { useCalculator, CalcButton } from '../hooks/useCalculator';
|
||||||
import { Grid, makeStyles, Box, Paper } from "@material-ui/core";
|
import { Grid, makeStyles, Box, Paper } from '@material-ui/core';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
button: {
|
button: {
|
||||||
@@ -9,7 +9,9 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
},
|
},
|
||||||
result: {
|
result: {
|
||||||
fontSize: theme.typography.h2.fontSize,
|
fontSize: theme.typography.h2.fontSize,
|
||||||
textAlign: "right",
|
textAlign: 'right',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -37,12 +39,15 @@ export const Calculator = ({ ...props }) => {
|
|||||||
} = useCalculator();
|
} = useCalculator();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
return (
|
return (
|
||||||
<Box display="flex" flexDirection="column">
|
<Box display='flex' flexDirection='column'>
|
||||||
<Box flexGrow={1} component={Paper} p={4} className={classes.result}>
|
<Box flexGrow={1} component={Paper} p={4} className={classes.result}>
|
||||||
{result()}
|
{result().toLocaleString(undefined, {
|
||||||
|
minimumFractionDigits: 0,
|
||||||
|
maximumFractionDigits: 4,
|
||||||
|
})}
|
||||||
</Box>
|
</Box>
|
||||||
<Box>
|
<Box>
|
||||||
<Grid container justify="space-around">
|
<Grid container justify='space-around'>
|
||||||
<CalcButton button={clear} className={classes.button} />
|
<CalcButton button={clear} className={classes.button} />
|
||||||
<CalcButton button={clearAll} className={classes.button} />
|
<CalcButton button={clearAll} className={classes.button} />
|
||||||
<CalcButton button={divider} className={classes.button} />
|
<CalcButton button={divider} className={classes.button} />
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import React, { useReducer } from "react";
|
import React, { useReducer } from 'react';
|
||||||
import { Grid, Button } from "@material-ui/core";
|
import { Grid, Button } from '@material-ui/core';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
value: 0,
|
value: 0,
|
||||||
op: "",
|
op: '',
|
||||||
num1: 0,
|
num1: 0,
|
||||||
num2: "",
|
num2: '',
|
||||||
num3: "",
|
num3: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
const Reducer = (state, action) => {
|
const Reducer = (state, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case "2":
|
case '2':
|
||||||
if (!state.num1) {
|
if (!state.num1) {
|
||||||
return { ...state, num1: state.num2, op: action.payload, num2: "" };
|
return { ...state, num1: state.num2, op: action.payload, num2: '' };
|
||||||
}
|
}
|
||||||
if (!state.num2) {
|
if (!state.num2) {
|
||||||
return { ...state, op: action.payload };
|
return { ...state, op: action.payload };
|
||||||
@@ -28,30 +28,30 @@ const Reducer = (state, action) => {
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
value: state.op(state.num1, state.num2),
|
value: state.op(state.num1, state.num2),
|
||||||
num2: "",
|
num2: '',
|
||||||
op: action.payload,
|
op: action.payload,
|
||||||
num1: state.op(state.num1, state.num2),
|
num1: state.op(state.num1, state.num2),
|
||||||
};
|
};
|
||||||
|
|
||||||
case "1":
|
case '1':
|
||||||
if (state.num2 === "" && action.payload === ".") {
|
if (state.num2 === '' && action.payload === '.') {
|
||||||
return { ...state, num2: "0" + action.payload };
|
return { ...state, num2: '0' + action.payload };
|
||||||
}
|
}
|
||||||
if (state.num2 === "") {
|
if (state.num2 === '') {
|
||||||
return { ...state, num2: action.payload };
|
return { ...state, num2: action.payload };
|
||||||
}
|
}
|
||||||
if (action.payload === "." && state.num2.includes(".")) {
|
if (action.payload === '.' && state.num2.includes('.')) {
|
||||||
return state;
|
return state;
|
||||||
} else {
|
} else {
|
||||||
return { ...state, num2: state.num2 + action.payload };
|
return { ...state, num2: state.num2 + action.payload };
|
||||||
}
|
}
|
||||||
|
|
||||||
case "3":
|
case '3':
|
||||||
if (state.op && state.num2) {
|
if (state.op && state.num2) {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
value: state.op(state.num1, state.num2),
|
value: state.op(state.num1, state.num2),
|
||||||
num2: "",
|
num2: '',
|
||||||
num1: state.op(state.num1, state.num2),
|
num1: state.op(state.num1, state.num2),
|
||||||
num3: state.num2,
|
num3: state.num2,
|
||||||
};
|
};
|
||||||
@@ -61,22 +61,22 @@ const Reducer = (state, action) => {
|
|||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
case "c":
|
case 'c':
|
||||||
if (state.num2.length === 2 && state.num2.includes("0.")) {
|
if (state.num2.length === 2 && state.num2.includes('0.')) {
|
||||||
return { ...state, num2: "" };
|
return { ...state, num2: '' };
|
||||||
}
|
}
|
||||||
if (state.num2.length > 1) {
|
if (state.num2.length > 1) {
|
||||||
return { ...state, num2: state.num2.slice(0, -1) };
|
return { ...state, num2: state.num2.slice(0, -1) };
|
||||||
}
|
}
|
||||||
return { ...state, num2: "" };
|
return { ...state, num2: '' };
|
||||||
|
|
||||||
case "ac":
|
case 'ac':
|
||||||
return {
|
return {
|
||||||
value: 0,
|
value: 0,
|
||||||
op: "",
|
op: '',
|
||||||
num1: 0,
|
num1: 0,
|
||||||
num2: "",
|
num2: '',
|
||||||
num3: "",
|
num3: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -96,17 +96,17 @@ export const useCalculator = () => {
|
|||||||
const [state, dispatch] = useReducer(Reducer, initialState);
|
const [state, dispatch] = useReducer(Reducer, initialState);
|
||||||
|
|
||||||
const getPayload = (label, type) => {
|
const getPayload = (label, type) => {
|
||||||
if (type !== "2") {
|
if (type !== '2') {
|
||||||
return `${label}`;
|
return `${label}`;
|
||||||
}
|
}
|
||||||
switch (label) {
|
switch (label) {
|
||||||
case "/":
|
case '/':
|
||||||
return (a, b) => Number(a) / Number(b);
|
return (a, b) => Number(a) / Number(b);
|
||||||
case "*":
|
case '*':
|
||||||
return (a, b) => Number(a) * Number(b);
|
return (a, b) => Number(a) * Number(b);
|
||||||
case "+":
|
case '+':
|
||||||
return (a, b) => Number(a) + Number(b);
|
return (a, b) => Number(a) + Number(b);
|
||||||
case "-":
|
case '-':
|
||||||
return (a, b) => Number(a) - Number(b);
|
return (a, b) => Number(a) - Number(b);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -122,17 +122,17 @@ export const useCalculator = () => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const number = (n) => buttonProps(n, "1");
|
const number = (n) => buttonProps(n, '1');
|
||||||
const operator = (sym) => buttonProps(sym, "2");
|
const operator = (sym) => buttonProps(sym, '2');
|
||||||
const clear = buttonProps("C", "c");
|
const clear = buttonProps('C', 'c');
|
||||||
const clearAll = buttonProps("AC", "ac");
|
const clearAll = buttonProps('AC', 'ac');
|
||||||
const equals = buttonProps("=", "3");
|
const equals = buttonProps('=', '3');
|
||||||
const zero = number(0);
|
const zero = number(0);
|
||||||
const dot = number(".");
|
const dot = number('.');
|
||||||
const divider = operator("/");
|
const divider = operator('/');
|
||||||
const multiplier = operator("*");
|
const multiplier = operator('*');
|
||||||
const adder = operator("+");
|
const adder = operator('+');
|
||||||
const substractor = operator("-");
|
const substractor = operator('-');
|
||||||
const one = number(1);
|
const one = number(1);
|
||||||
const two = number(2);
|
const two = number(2);
|
||||||
const three = number(3);
|
const three = number(3);
|
||||||
@@ -142,7 +142,7 @@ export const useCalculator = () => {
|
|||||||
const seven = number(7);
|
const seven = number(7);
|
||||||
const eight = number(8);
|
const eight = number(8);
|
||||||
const nine = number(9);
|
const nine = number(9);
|
||||||
const result = () => (!state.num2 ? state.value : state.num2);
|
const result = (): number => (!state.num2 ? state.value : state.num2);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
result,
|
result,
|
||||||
|
|||||||
Reference in new issue
Block a user