2021-11-21 10:40:46 -05:00
|
|
|
import { html, Component } from "../lib/index.js";
|
|
|
|
|
|
|
|
export default class NetworkForm extends Component {
|
|
|
|
state = {
|
|
|
|
username: "",
|
|
|
|
password: "",
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2023-01-10 09:05:57 -05:00
|
|
|
this.handleInput = this.handleInput.bind(this);
|
2021-11-21 10:40:46 -05:00
|
|
|
this.handleSubmit = this.handleSubmit.bind(this);
|
|
|
|
|
|
|
|
if (props.username) {
|
|
|
|
this.state.username = props.username;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-10 09:05:57 -05:00
|
|
|
handleInput(event) {
|
2021-11-21 10:40:46 -05:00
|
|
|
let target = event.target;
|
|
|
|
let value = target.type == "checkbox" ? target.checked : target.value;
|
|
|
|
this.setState({ [target.name]: value });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSubmit(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
this.props.onSubmit(this.state.username, this.state.password);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return html`
|
2023-01-10 09:05:57 -05:00
|
|
|
<form onInput=${this.handleInput} onSubmit=${this.handleSubmit}>
|
2021-11-21 10:40:46 -05:00
|
|
|
<label>
|
|
|
|
Username:<br/>
|
|
|
|
<input type="username" name="username" value=${this.state.username} required/>
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
|
|
|
|
<label>
|
|
|
|
Password:<br/>
|
|
|
|
<input type="password" name="password" value=${this.state.password} required autofocus/>
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
|
|
|
|
<button>Login</button>
|
|
|
|
</form>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|