├── public ├── robots.txt ├── favicon.ico ├── logo192.png ├── logo512.png ├── manifest.json └── index.html ├── src ├── calc-app.png ├── components │ ├── Wrapper.js │ ├── ButtonBox.js │ ├── Screen.js │ └── Button.js ├── index.js ├── context │ └── CalcContext.js ├── App.js └── index.css ├── .gitignore ├── README.md └── package.json /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/calc-app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candraKriswinarto/react-calculator-app/HEAD/src/calc-app.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candraKriswinarto/react-calculator-app/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candraKriswinarto/react-calculator-app/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candraKriswinarto/react-calculator-app/HEAD/public/logo512.png -------------------------------------------------------------------------------- /src/components/Wrapper.js: -------------------------------------------------------------------------------- 1 | 2 | const Wrapper = ({ children }) => { 3 | return ( 4 |
{children}
5 | ) 6 | } 7 | 8 | export default Wrapper -------------------------------------------------------------------------------- /src/components/ButtonBox.js: -------------------------------------------------------------------------------- 1 | 2 | const ButtonBox = ({ children }) => { 3 | return ( 4 |
{children}
5 | ) 6 | } 7 | 8 | export default ButtonBox -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | const root = ReactDOM.createRoot(document.getElementById('root')); 7 | root.render( 8 | 9 | 10 | 11 | ); 12 | -------------------------------------------------------------------------------- /src/components/Screen.js: -------------------------------------------------------------------------------- 1 | import { useContext } from "react" 2 | import { CalcContext } from "../context/CalcContext" 3 | import { Textfit } from 'react-textfit'; 4 | 5 | const Screen = () => { 6 | const { calc } = useContext(CalcContext); 7 | 8 | return ( 9 | {calc.num ? calc.num : calc.res} 10 | ) 11 | } 12 | 13 | export default Screen -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /src/context/CalcContext.js: -------------------------------------------------------------------------------- 1 | import { createContext, useState } from "react" 2 | 3 | export const CalcContext = createContext() 4 | const CalcProvider = ({ children }) => { 5 | const [calc, setCalc] = useState({ 6 | sign: "", 7 | num: 0, 8 | res: 0 9 | }); 10 | 11 | const providerValue = { 12 | calc, setCalc 13 | } 14 | 15 | return ( 16 | 17 | {children} 18 | 19 | ) 20 | } 21 | 22 | export default CalcProvider -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | Basic Calculator 15 | 16 | 17 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ![Project Preview](./src/calc-app.png) 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `yarn install` 10 | 11 | Instal All dependencies in this project 12 | 13 | ### `yarn start` 14 | 15 | Runs the app in the development mode.
16 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 17 | 18 | ### Link 19 | 20 | Reactjs: https://reactjs.org/docs/create-a-new-react-app.html 21 | react-textfit: https://www.npmjs.com/package/react-textfit 22 | box-shadow: https://box-shadow.dev/ 23 | 24 | ### Video Tutorial 25 | 26 | You can see my youtube video for this project in [here](https://youtu.be/o89bhL-S6g8) -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import Wrapper from "./components/Wrapper"; 2 | import Screen from "./components/Screen"; 3 | import ButtonBox from './components/ButtonBox' 4 | import Button from './components/Button' 5 | import CalcProvider from "./context/CalcContext"; 6 | 7 | const btnValues = [ 8 | ["C", "+-", "%", "/"], 9 | [7, 8, 9, "x"], 10 | [4, 5, 6, "-"], 11 | [1, 2, 3, "+"], 12 | [0, ".", "="], 13 | ]; 14 | 15 | function App() { 16 | return ( 17 | 18 | 19 | 20 | 21 | {btnValues.flat().map((btn, i) => ( 22 | 111 | ) 112 | } 113 | 114 | export default Button --------------------------------------------------------------------------------