Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layout e state v1 #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 72 additions & 24 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,73 @@
import logo from './logo.svg';
import './App.css';

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
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 (
<Container>
<Row>
<h1>Password Generator</h1>
</Row>
<Row>
{ password.length > 0 ? <h2>{ password }</h2> : <h2> CLICK TO GENERATE </h2> }
</Row>
<Form>
<RangeInput handleChange= {this.handleChange} name='length' length={ length }/>

export default App;
<TogleSwith handleChange= {this.handleChange} name='uppercase'/>

<TogleSwith handleChange= {this.handleChange} name='lowercase'/>

<TogleSwith handleChange= {this.handleChange} name='numbers'/>

<TogleSwith handleChange= {this.handleChange} name='symbols'/>

<GenerateButton generatePass= {this.generatePass}/>
</Form>
</Container>
);
}
}
13 changes: 13 additions & 0 deletions src/components/GenerateButton.js
Original file line number Diff line number Diff line change
@@ -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(
<Button variant="primary" type="button" onClick={ generatePass }>
GENERATE PASSWORD
</Button>
)
}
}
14 changes: 14 additions & 0 deletions src/components/RangeInput.js
Original file line number Diff line number Diff line change
@@ -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(
<>
<Form.Label>{ `${name}: ${length}` }</Form.Label>
<Form.Range min="4" max="32" step="1" value={ length } name={ name.toLowerCase() } onChange={ handleChange }/>
</>
)
}
}
17 changes: 17 additions & 0 deletions src/components/TogleSwith.js
Original file line number Diff line number Diff line change
@@ -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(
<Form.Check
type='checkbox'
label={name}
name={name}
value={name}
onChange={handleChange}
/>
)
}
}