Guest User

Untitled

a guest
Feb 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. export const Button = ({ children, handleClick})=> (
  2. <div
  3. className={`button-container ${children}`}
  4. onClick={() => handleClick(children)}>
  5. {children}
  6. </div>
  7. )
  8.  
  9. export const Screen = props => (
  10. <div className="input">
  11. {props.screen}
  12. </div>
  13. )
  14.  
  15. class App extends Component {
  16. //extend component class
  17. constructor(props) {
  18. super(props);
  19.  
  20. this.state = {
  21. screen: [],
  22. sucess: 'SUCESS',
  23. error: 'ERRO',
  24. tries: 3,
  25. password: ''
  26. }
  27. }
  28.  
  29. //I tried using an input on the screen component
  30. //but this worked
  31. //not sure if "the react way"
  32. addPassword = val => {
  33. return this.state.screen.length > 3 ? '' : this.setState({screen: this.state.screen + val});
  34. }
  35.  
  36. /*
  37. pin = '1234';
  38. validadePassword = (addPassword, pin) => {
  39. //return addPassword === pin ? this.state.screen.type === 'password' : this.state.screen.type === 'number';
  40. console.log(pin);
  41. }*/
  42.  
  43. render() {
  44. return (
  45. <div className="App">
  46. <h1>Pin pad</h1>
  47. <h2>Addcode!</h2>
  48. <div className="container">
  49. <Screen
  50. screen={this.state.screen}
  51.  
  52. length = {5}>
  53. </Screen>
  54. <div className="row justify-content-md-center">
  55. <Button handleClick={this.addPassword}>7</Button>
  56. <Button handleClick={this.addPassword}>8</Button>
  57. <Button handleClick={this.addPassword}>9</Button>
  58. </div>
  59. <div className="row justify-content-md-center">
  60. <Button handleClick={this.addPassword}>4</Button>
  61. <Button handleClick={this.addPassword}>5</Button>
  62. <Button handleClick={this.addPassword}>6</Button>
  63. </div>
  64. <div className="row justify-content-md-center">
  65. <Button handleClick={this.addPassword}>1</Button>
  66. <Button handleClick={this.addPassword}>2</Button>
  67. <Button handleClick={this.addPassword}>3</Button>
  68. </div>
  69. <div className="row justify-content-md-center">
  70. <Button handleClick={this.addPassword} class="col align-self-center">0</Button>
  71. </div>
  72. </div>
  73. </div>
  74. );
  75. }
  76. }
  77.  
  78. export default App;
Add Comment
Please, Sign In to add comment