Created
April 2, 2019 16:30
-
-
Save GraxMonzo/fcc96de90070ff0cb9472ad300f41caf to your computer and use it in GitHub Desktop.
Breaked Calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id='root'></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Component } = React; | |
const { connect, Provider } = ReactRedux; | |
const { createStore, combineReducers } = Redux; | |
const ReduxDevToolsPayload = { | |
"payload": "[{\"type\":\"ADD_ELEM\",\"text\":\"1\"},{\"type\":\"ADD_ELEM\",\"text\":\"+\"},{\"type\":\"ADD_ELEM\",\"text\":\"2\"},{\"type\":\"EQUAL\",\"value\":\"1+2\"},{\"type\":\"ADD_ELEM\",\"text\":\"+\"},{\"type\":\"ADD_ELEM\",\"text\":\"5\"},{\"type\":\"ADD_ELEM\",\"text\":\"*\"},{\"type\":\"ADD_ELEM\",\"text\":\"2\"},{\"type\":\"EQUAL\",\"value\":\"3+5*2\"},{\"type\":\"ADD_ELEM\",\"text\":\"-\"},{\"type\":\"ADD_ELEM\",\"text\":\"4\"},{\"type\":\"ADD_ELEM\",\"text\":\"/\"},{\"type\":\"ADD_ELEM\",\"text\":\"3\"},{\"type\":\"EQUAL\",\"value\":\"13-4/3\"},{\"type\":\"CLEAR\"},{\"type\":\"ADD_ELEM\",\"text\":\"9\"},{\"type\":\"ADD_ELEM\",\"text\":\".\"},{\"type\":\"ADD_ELEM\",\"text\":\"5\"},{\"type\":\"ADD_ELEM\",\"text\":\"*\"},{\"type\":\"ADD_ELEM\",\"text\":\"0\"},{\"type\":\"ADD_ELEM\",\"text\":\".\"},{\"type\":\"ADD_ELEM\",\"text\":\"7\"},{\"type\":\"ADD_ELEM\",\"text\":\"3\"},{\"type\":\"EQUAL\",\"value\":\"9.5*0.73\"}]" | |
} | |
const calcState = { | |
//... | |
} | |
const calcReducer = (state = calcState, action) => { | |
//... | |
} | |
const mapStateToProps = (state) => { | |
//... | |
} | |
const mapDispatchToProps = (dispatch) => { | |
//... | |
} | |
class App extends Component { | |
constructor(props){ | |
super(props) | |
} | |
render() { | |
const { value, btns, addElem, clear, equal } = this.props; | |
return ( | |
<div className="App"> | |
<div className="value-container"> | |
<input type="text" value={value} /> | |
</div> | |
<div className="buttons-container"> | |
{btns.map((item, key) => { | |
if(item == "C"){ | |
return( | |
<button onClick={ clear.bind(this) } key={key}>{item}</button> | |
) | |
} else if(item == "="){ | |
return( | |
<button onClick={ equal.bind(this, value) } key={key}>{item}</button> | |
) | |
} else { | |
return( | |
<button onClick={ addElem.bind(this, item) } key={key}>{item}</button> | |
) | |
} | |
})} | |
</div> | |
</div> | |
); | |
} | |
} | |
const Calc = connect(mapStateToProps, mapDispatchToProps)(App); | |
const store = createStore(calcReducer, | |
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()); | |
ReactDOM.render( | |
<Provider store={store}> | |
<Calc /> | |
</Provider> | |
, document.getElementById('root')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.0/react.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.0/react-dom.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.5.2/redux.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-redux/4.4.5/react-redux.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*{ | |
padding: 0; | |
margin: 0; | |
box-sizing: border-box; | |
} | |
body{ | |
width: 100%; | |
height: 100vh; | |
background: white; | |
} | |
.App{ | |
width: 300px; | |
margin: 0 auto; | |
background: black; | |
box-shadow: 0 0 5px; | |
margin-top: 100px; | |
} | |
.value-container{ | |
padding-top: 1.75%; | |
} | |
.value-container input{ | |
display: block; | |
width: 95%; | |
border: none; | |
height: 30px; | |
text-align: right; | |
padding: 0 10px; | |
margin: 0 auto; | |
font-size: 22px; | |
font-weight: 700; | |
color: lightslategrey; | |
} | |
.buttons-container{ | |
overflow: hidden; | |
width: 100%; | |
margin: 0 auto; | |
display: flex; | |
flex-flow: row wrap; | |
justify-content: space-between; | |
} | |
.buttons-container button{ | |
width: 20%; | |
height: 30px; | |
line-height: 30px; | |
margin: 2%; | |
border: none; | |
outline: none; | |
background: #2f662f; | |
color: white; | |
font-weight: 700; | |
} | |
.buttons-container button:hover{ | |
box-shadow: 0 0 5px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment