1
0
mirror of https://github.com/flarum/core.git synced 2025-08-11 10:55:47 +02:00

update: Modal

This commit is contained in:
Alexander Skvortsov
2020-08-07 15:59:00 -04:00
committed by Franz Liedke
parent 5606eae0f1
commit 99d79e7571

View File

@@ -14,7 +14,7 @@ export default class Modal extends Component {
*/ */
static isDismissible = true; static isDismissible = true;
init() { oninit() {
/** /**
* Attributes for an alert component to show below the header. * Attributes for an alert component to show below the header.
* *
@@ -23,17 +23,11 @@ export default class Modal extends Component {
this.alertAttrs = null; this.alertAttrs = null;
} }
config(isInitialized, context) { oncreate(vnode) {
if (isInitialized) return; vnode.attrs.onshow(() => this.onready(vnode.attrs));
this.props.onshow(() => this.onready());
context.onunload = () => {
this.props.onhide();
};
} }
view() { view(vnode) {
if (this.alertAttrs) { if (this.alertAttrs) {
this.alertAttrs.dismissible = false; this.alertAttrs.dismissible = false;
} }
@@ -45,7 +39,7 @@ export default class Modal extends Component {
<div className="Modal-close App-backControl"> <div className="Modal-close App-backControl">
{Button.component({ {Button.component({
icon: 'fas fa-times', icon: 'fas fa-times',
onclick: this.hide.bind(this), onclick: this.hide.bind(this, vnode.attrs),
className: 'Button Button--icon Button--link', className: 'Button Button--icon Button--link',
})} })}
</div> </div>
@@ -60,7 +54,7 @@ export default class Modal extends Component {
{this.alertAttrs ? <div className="Modal-alert">{Alert.component(this.alertAttrs)}</div> : ''} {this.alertAttrs ? <div className="Modal-alert">{Alert.component(this.alertAttrs)}</div> : ''}
{this.content()} {this.content(vnode.attrs)}
</form> </form>
</div> </div>
</div> </div>
@@ -89,7 +83,7 @@ export default class Modal extends Component {
* @return {VirtualElement} * @return {VirtualElement}
* @abstract * @abstract
*/ */
content() {} content(attrs) {}
/** /**
* Handle the modal form's submit event. * Handle the modal form's submit event.
@@ -101,15 +95,15 @@ export default class Modal extends Component {
/** /**
* Focus on the first input when the modal is ready to be used. * Focus on the first input when the modal is ready to be used.
*/ */
onready() { onready(attrs) {
this.$('form').find('input, select, textarea').first().focus().select(); this.$('form').find('input, select, textarea').first().focus().select();
} }
/** /**
* Hide the modal. * Hide the modal.
*/ */
hide() { hide(attrs) {
this.props.onhide(); attrs.onhide();
} }
/** /**