diff --git a/src/App.js b/src/App.js index 3784575..c8618a4 100644 --- a/src/App.js +++ b/src/App.js @@ -1,25 +1,73 @@ -import logo from './logo.svg'; -import './App.css'; - -function App() { - return ( -
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
-
- ); -} +import React from 'react'; +import 'bootstrap/dist/css/bootstrap.min.css'; +import GenerateButton from './components/GenerateButton'; +import RangeInput from './components/RangeInput'; +import TogleSwith from './components/TogleSwith'; +import { Container, Form, Row } from 'react-bootstrap'; + +export default class App extends React.Component { + constructor(){ + super(); + this.state = { + length: 4, + uppercase: false, + lowercase: false, + numbers: false, + symbols: false, + password: '', + } + } + + handleChange = ({ target }) => { + const { name } = target; + const value = target.type === 'checkbox' ? target.checked : target.value; + + this.setState({ + [name]: value, + }); + } + + // Codigo adaptado de webtutorial.com.br + generatePass = () => { + const { uppercase, lowercase, numbers, symbols, length} = this.state; + let stringAleatoria = ''; + let caracteres = '' + lowercase ? caracteres += 'abcdefghijklmnopqrstuvwxyz' : '' + uppercase ? caracteres += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' : '' + numbers ? caracteres += '0123456789' : '' + symbols ? caracteres += '!@#$%ยจ&*()_+': '' + for (var i = 0; i < length; i++) { + stringAleatoria += caracteres.charAt(Math.floor(Math.random() * caracteres.length)); + } + this.setState({ + password: stringAleatoria, + }) + } + + render(){ + const { length, password } = this.state; + return ( + + +

Password Generator

+
+ + { password.length > 0 ?

{ password }

:

CLICK TO GENERATE

} +
+
+ -export default App; + + + + + + + + + + +
+ ); + } +} diff --git a/src/components/GenerateButton.js b/src/components/GenerateButton.js new file mode 100644 index 0000000..3819f39 --- /dev/null +++ b/src/components/GenerateButton.js @@ -0,0 +1,13 @@ +import React from "react"; +import { Button } from "react-bootstrap"; + +export default class GenerateButton extends React.Component { + render() { + const { generatePass } = this.props + return( + + ) + } +} \ No newline at end of file diff --git a/src/components/RangeInput.js b/src/components/RangeInput.js new file mode 100644 index 0000000..ce3a49a --- /dev/null +++ b/src/components/RangeInput.js @@ -0,0 +1,14 @@ +import React from "react"; +import { Form } from "react-bootstrap"; + +export default class RangeInput extends React.Component { + render() { + const { handleChange, name, length } = this.props; + return( + <> + { `${name}: ${length}` } + + + ) + } +} \ No newline at end of file diff --git a/src/components/TogleSwith.js b/src/components/TogleSwith.js new file mode 100644 index 0000000..8b3a7a9 --- /dev/null +++ b/src/components/TogleSwith.js @@ -0,0 +1,17 @@ +import React from "react"; +import { Form } from "react-bootstrap"; + +export default class TogleSwith extends React.Component { + render() { + const { name, handleChange } = this.props; + return( + + ) + } +} \ No newline at end of file