First alpha
This commit is contained in:
39
src/components/modals/YesNoModal.tsx
Executable file
39
src/components/modals/YesNoModal.tsx
Executable file
@ -0,0 +1,39 @@
|
||||
import { h, Component } from 'preact';
|
||||
import "./modal.scss"
|
||||
import { Modal } from './Modal';
|
||||
|
||||
|
||||
export class YesNoModal extends Component<{ title: string, onResult: (result: boolean | undefined) => void }, {}> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.onKeyDown = this.onKeyDown.bind(this);
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
window.addEventListener("keydown", this.onKeyDown);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
window.removeEventListener("keydown", this.onKeyDown);
|
||||
}
|
||||
|
||||
onKeyDown(evt: KeyboardEvent) {
|
||||
if (evt.keyCode === 74 || evt.keyCode === 89) this.props.onResult(true)
|
||||
else if (evt.keyCode === 78) this.props.onResult(false)
|
||||
}
|
||||
|
||||
render() {
|
||||
return <Modal title={this.props.title} onClose={() => this.props.onResult(undefined)}>
|
||||
<fieldset style="border:none;">
|
||||
<div style="text-align: right;">
|
||||
<button class="primary" style="display: inline-block;" onClick={() => {
|
||||
this.props.onResult(false);
|
||||
}}>No</button>
|
||||
<button class="primary" style="display: inline-block;" onClick={() => {
|
||||
this.props.onResult(true);
|
||||
}}>Yes</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</Modal>
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user