2018-03-27 19:54:05 +05:30
|
|
|
<script>
|
2018-11-18 11:00:15 +05:30
|
|
|
import $ from 'jquery';
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
const buttonVariants = ['danger', 'primary', 'success', 'warning'];
|
2018-11-08 19:23:39 +05:30
|
|
|
const sizeVariants = ['sm', 'md', 'lg', 'xl'];
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
export default {
|
|
|
|
name: 'GlModal',
|
|
|
|
props: {
|
|
|
|
id: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
2018-03-27 19:54:05 +05:30
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
modalSize: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: 'md',
|
|
|
|
validator: value => sizeVariants.includes(value),
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
headerTitleText: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
footerPrimaryButtonVariant: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: 'primary',
|
|
|
|
validator: value => buttonVariants.includes(value),
|
|
|
|
},
|
|
|
|
footerPrimaryButtonText: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
computed: {
|
|
|
|
modalSizeClass() {
|
|
|
|
return this.modalSize === 'md' ? '' : `modal-${this.modalSize}`;
|
|
|
|
},
|
|
|
|
},
|
2018-11-18 11:00:15 +05:30
|
|
|
mounted() {
|
2018-12-13 13:39:08 +05:30
|
|
|
$(this.$el)
|
|
|
|
.on('shown.bs.modal', this.opened)
|
|
|
|
.on('hidden.bs.modal', this.closed);
|
2018-11-18 11:00:15 +05:30
|
|
|
},
|
|
|
|
beforeDestroy() {
|
2018-12-13 13:39:08 +05:30
|
|
|
$(this.$el)
|
|
|
|
.off('shown.bs.modal', this.opened)
|
|
|
|
.off('hidden.bs.modal', this.closed);
|
2018-11-18 11:00:15 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
methods: {
|
|
|
|
emitCancel(event) {
|
|
|
|
this.$emit('cancel', event);
|
|
|
|
},
|
|
|
|
emitSubmit(event) {
|
|
|
|
this.$emit('submit', event);
|
2018-03-27 19:54:05 +05:30
|
|
|
},
|
2018-11-18 11:00:15 +05:30
|
|
|
opened() {
|
|
|
|
this.$emit('open');
|
|
|
|
},
|
|
|
|
closed() {
|
|
|
|
this.$emit('closed');
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
};
|
2018-03-27 19:54:05 +05:30
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2019-02-15 15:39:39 +05:30
|
|
|
<div :id="id" class="modal fade" tabindex="-1" role="dialog">
|
|
|
|
<div :class="modalSizeClass" class="modal-dialog" role="document">
|
2018-03-27 19:54:05 +05:30
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<slot name="header">
|
2018-11-08 19:23:39 +05:30
|
|
|
<h4 class="modal-title">
|
2019-02-15 15:39:39 +05:30
|
|
|
<slot name="title"> {{ headerTitleText }} </slot>
|
2018-11-08 19:23:39 +05:30
|
|
|
</h4>
|
2018-03-27 19:54:05 +05:30
|
|
|
<button
|
2018-11-08 19:23:39 +05:30
|
|
|
:aria-label="s__('Modal|Close')"
|
2018-03-27 19:54:05 +05:30
|
|
|
type="button"
|
2018-05-09 12:01:36 +05:30
|
|
|
class="close js-modal-close-action"
|
2018-03-27 19:54:05 +05:30
|
|
|
data-dismiss="modal"
|
2019-02-15 15:39:39 +05:30
|
|
|
@click="emitCancel($event);"
|
2018-03-27 19:54:05 +05:30
|
|
|
>
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
|
|
|
</slot>
|
|
|
|
</div>
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
<div class="modal-body"><slot></slot></div>
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
<div class="modal-footer">
|
|
|
|
<slot name="footer">
|
|
|
|
<button
|
|
|
|
type="button"
|
2018-12-13 13:39:08 +05:30
|
|
|
class="btn js-modal-cancel-action qa-modal-cancel-button"
|
2018-03-27 19:54:05 +05:30
|
|
|
data-dismiss="modal"
|
2019-02-15 15:39:39 +05:30
|
|
|
@click="emitCancel($event);"
|
2018-03-27 19:54:05 +05:30
|
|
|
>
|
|
|
|
{{ s__('Modal|Cancel') }}
|
|
|
|
</button>
|
|
|
|
<button
|
2018-11-08 19:23:39 +05:30
|
|
|
:class="`btn-${footerPrimaryButtonVariant}`"
|
2018-03-27 19:54:05 +05:30
|
|
|
type="button"
|
2018-12-13 13:39:08 +05:30
|
|
|
class="btn js-modal-primary-action qa-modal-primary-button"
|
2018-03-27 19:54:05 +05:30
|
|
|
data-dismiss="modal"
|
2019-02-15 15:39:39 +05:30
|
|
|
@click="emitSubmit($event);"
|
2018-03-27 19:54:05 +05:30
|
|
|
>
|
|
|
|
{{ footerPrimaryButtonText }}
|
|
|
|
</button>
|
|
|
|
</slot>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|