gamja/components/join-form.js

50 lines
953 B
JavaScript
Raw Normal View History

2021-03-08 10:23:16 -05:00
import { html, Component } from "../lib/index.js";
export default class JoinForm extends Component {
2021-03-08 10:23:16 -05:00
state = {
channel: "#",
};
constructor(props) {
super(props);
this.handleInput = this.handleInput.bind(this);
2021-03-08 10:23:16 -05:00
this.handleSubmit = this.handleSubmit.bind(this);
if (props.channel) {
this.state.channel = props.channel;
}
2021-03-08 10:23:16 -05:00
}
handleInput(event) {
2021-06-10 12:11:11 -04:00
let target = event.target;
2024-10-13 18:56:18 -04:00
let value = target.type === "checkbox" ? target.checked : target.value;
2021-03-08 10:23:16 -05:00
this.setState({ [target.name]: value });
}
handleSubmit(event) {
event.preventDefault();
2021-06-10 12:11:11 -04:00
let params = {
2021-03-08 10:23:16 -05:00
channel: this.state.channel,
};
this.props.onSubmit(params);
}
render() {
return html`
<form onInput=${this.handleInput} onSubmit=${this.handleSubmit}>
2021-03-08 10:23:16 -05:00
<label>
Channel:<br/>
<input type="text" name="channel" value=${this.state.channel} autofocus required/>
</label>
<br/>
<br/>
<button>Join</button>
</form>
`;
}
}