2018-05-02 00:05:36 +00:00
|
|
|
<div class={backdropClass}
|
2018-03-04 00:31:00 +00:00
|
|
|
tabindex="-1"
|
|
|
|
data-a11y-dialog-hide
|
|
|
|
></div>
|
2018-05-02 00:05:36 +00:00
|
|
|
<div class={contentsClass}
|
2018-03-04 00:31:00 +00:00
|
|
|
role="dialog"
|
2018-05-02 00:05:36 +00:00
|
|
|
aria-label={label || ''}
|
2018-03-04 00:31:00 +00:00
|
|
|
ref:node
|
|
|
|
>
|
2018-05-02 00:05:36 +00:00
|
|
|
<div class="modal-dialog-document" role="document" style="background: {background || '#000'};">
|
2018-02-28 07:18:07 +00:00
|
|
|
<div class="modal-dialog-header">
|
2018-05-02 00:05:36 +00:00
|
|
|
{#if title}
|
|
|
|
<h1 class="modal-dialog-title">{title}</h1>
|
|
|
|
{/if}
|
2018-02-28 07:18:07 +00:00
|
|
|
<div class="close-dialog-button-wrapper">
|
2018-03-21 04:26:53 +00:00
|
|
|
<button class="close-dialog-button"
|
|
|
|
data-a11y-dialog-hide aria-label="Close dialog">
|
2018-03-28 15:56:35 +00:00
|
|
|
<svg class="close-dialog-button-svg">
|
2018-12-09 04:04:32 +00:00
|
|
|
<use xlink:href="/icons.svg#fa-times" />
|
2018-03-28 15:56:35 +00:00
|
|
|
</svg>
|
2018-02-28 07:18:07 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
2018-02-05 03:15:35 +00:00
|
|
|
</div>
|
2018-02-23 04:04:19 +00:00
|
|
|
<slot></slot>
|
2018-02-04 21:49:43 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<style>
|
2018-04-01 01:46:44 +00:00
|
|
|
:global(.modal-dialog[aria-hidden='true']) {
|
2018-02-05 03:15:35 +00:00
|
|
|
display: none;
|
|
|
|
}
|
2018-04-13 16:46:47 +00:00
|
|
|
:global(.modal-dialog) {
|
2018-02-05 03:15:35 +00:00
|
|
|
position: fixed;
|
|
|
|
z-index: 10000;
|
2018-04-13 16:46:47 +00:00
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.modal-dialog-backdrop {
|
|
|
|
position: fixed;
|
|
|
|
z-index: 10010;
|
2018-02-05 03:15:35 +00:00
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
bottom: 0;
|
|
|
|
top: 0;
|
|
|
|
background: rgba(51, 51, 51, 0.9);
|
2018-04-01 01:46:44 +00:00
|
|
|
}
|
|
|
|
.modal-dialog-backdrop.should-animate {
|
2018-03-04 00:31:00 +00:00
|
|
|
transition: opacity 0.2s linear;
|
2018-02-05 03:15:35 +00:00
|
|
|
}
|
|
|
|
.modal-dialog-contents {
|
2018-04-13 16:46:47 +00:00
|
|
|
z-index: 10020;
|
2018-02-04 21:49:43 +00:00
|
|
|
padding: 0;
|
2018-02-06 17:09:47 +00:00
|
|
|
border: 1px solid var(--main-border);
|
|
|
|
border-radius: 2px;
|
2018-02-23 04:04:19 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
max-height: calc(100% - 20px);
|
2018-04-01 01:46:44 +00:00
|
|
|
}
|
|
|
|
.modal-dialog-contents.should-animate {
|
2018-03-04 00:31:00 +00:00
|
|
|
transition: opacity 0.2s linear;
|
2018-02-04 21:49:43 +00:00
|
|
|
}
|
2018-02-23 04:04:19 +00:00
|
|
|
|
2018-02-05 03:15:35 +00:00
|
|
|
.modal-dialog-document {
|
2018-02-04 21:49:43 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2018-02-06 17:09:47 +00:00
|
|
|
max-width: calc(100vw - 20px);
|
2018-02-23 04:04:19 +00:00
|
|
|
flex: 1;
|
2018-02-04 21:49:43 +00:00
|
|
|
}
|
2018-02-28 07:18:07 +00:00
|
|
|
.modal-dialog-header {
|
|
|
|
width: 100%;
|
|
|
|
background: var(--nav-bg);
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
.modal-dialog-title {
|
|
|
|
color: var(--nav-text-color);
|
|
|
|
padding: 2px 0 2px 10px;
|
|
|
|
margin: 0;
|
|
|
|
font-size: 1.5em;
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
}
|
2018-02-04 21:49:43 +00:00
|
|
|
.close-dialog-button-wrapper {
|
2018-02-28 07:18:07 +00:00
|
|
|
flex: 1;
|
2018-03-28 00:31:17 +00:00
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
2018-02-04 21:49:43 +00:00
|
|
|
}
|
|
|
|
.close-dialog-button {
|
2018-03-28 00:31:17 +00:00
|
|
|
padding: 0;
|
2018-02-04 21:49:43 +00:00
|
|
|
background: none;
|
|
|
|
border: none;
|
2018-03-28 00:31:17 +00:00
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2018-02-04 21:49:43 +00:00
|
|
|
}
|
2018-03-28 15:56:35 +00:00
|
|
|
.close-dialog-button-svg {
|
|
|
|
padding: 10px;
|
|
|
|
fill: var(--button-primary-text);
|
|
|
|
width: 24px;
|
|
|
|
height: 24px;
|
2018-03-28 00:31:17 +00:00
|
|
|
flex: 1;
|
2018-02-04 21:49:43 +00:00
|
|
|
}
|
2018-03-21 04:26:53 +00:00
|
|
|
.muted-style .modal-dialog-header {
|
|
|
|
background: var(--muted-modal-bg);
|
|
|
|
}
|
|
|
|
.muted-style .close-dialog-button:focus {
|
|
|
|
outline: 2px solid var(--muted-modal-focus);
|
|
|
|
}
|
|
|
|
.muted-style .close-dialog-button:hover {
|
|
|
|
background: var(--muted-modal-hover);
|
|
|
|
}
|
|
|
|
.muted-style.modal-dialog-contents {
|
|
|
|
border: none;
|
|
|
|
}
|
2018-11-24 05:33:03 +00:00
|
|
|
:global(body.modal-open) {
|
|
|
|
overflow-y: hidden;
|
|
|
|
}
|
2018-02-04 21:49:43 +00:00
|
|
|
</style>
|
|
|
|
<script>
|
2018-11-21 08:33:46 +00:00
|
|
|
import { A11yDialog } from '../../../_thirdparty/a11y-dialog/a11y-dialog'
|
2018-04-08 23:56:20 +00:00
|
|
|
import { classname } from '../../../_utils/classname'
|
|
|
|
import { on, emit } from '../../../_utils/eventBus'
|
2018-04-01 01:46:44 +00:00
|
|
|
|
2018-02-04 21:49:43 +00:00
|
|
|
export default {
|
2018-04-20 04:38:01 +00:00
|
|
|
oncreate () {
|
2018-04-08 23:56:20 +00:00
|
|
|
let dialogElement = this.refs.node.parentElement
|
|
|
|
this._a11yDialog = new A11yDialog(dialogElement)
|
|
|
|
this._a11yDialog.on('hide', () => {
|
2018-04-19 16:37:05 +00:00
|
|
|
let { id } = this.get()
|
2018-11-24 05:33:03 +00:00
|
|
|
document.body.classList.toggle('modal-open', false)
|
2018-11-13 00:20:59 +00:00
|
|
|
this.fire('close')
|
|
|
|
this._a11yDialog.destroy()
|
2018-04-19 16:37:05 +00:00
|
|
|
emit('destroyDialog', id)
|
2018-04-08 23:56:20 +00:00
|
|
|
requestAnimationFrame(() => document.body.removeChild(dialogElement))
|
|
|
|
})
|
|
|
|
on('showDialog', this, this.showDialog)
|
|
|
|
on('closeDialog', this, this.closeDialog)
|
|
|
|
},
|
2018-04-01 01:46:44 +00:00
|
|
|
data: () => ({
|
|
|
|
// don't animate if we're showing a modal dialog on top of another modal dialog. it looks ugly
|
2018-04-30 16:57:49 +00:00
|
|
|
shouldAnimate: !process.browser || document.getElementsByClassName('modal-dialog').length < 2,
|
|
|
|
fadedIn: false,
|
|
|
|
muted: false,
|
2018-05-01 02:06:08 +00:00
|
|
|
className: void 0,
|
|
|
|
title: void 0
|
2018-04-01 01:46:44 +00:00
|
|
|
}),
|
|
|
|
computed: {
|
2018-05-02 00:05:36 +00:00
|
|
|
backdropClass: ({ fadedIn, shouldAnimate }) => {
|
2018-04-01 01:46:44 +00:00
|
|
|
return classname(
|
|
|
|
'modal-dialog-backdrop',
|
|
|
|
!fadedIn && 'hidden',
|
|
|
|
shouldAnimate && 'should-animate'
|
|
|
|
)
|
|
|
|
},
|
2018-05-02 00:05:36 +00:00
|
|
|
contentsClass: ({ fadedIn, muted, shouldAnimate, className }) => {
|
2018-04-01 01:46:44 +00:00
|
|
|
return classname(
|
|
|
|
'modal-dialog-contents',
|
|
|
|
!fadedIn && 'hidden',
|
|
|
|
muted && 'muted-style',
|
|
|
|
shouldAnimate && 'should-animate',
|
|
|
|
className
|
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
2018-04-08 23:56:20 +00:00
|
|
|
methods: {
|
2018-04-20 04:38:01 +00:00
|
|
|
showDialog (thisId) {
|
2018-04-19 16:37:05 +00:00
|
|
|
let { id } = this.get()
|
|
|
|
if (id !== thisId) {
|
2018-04-08 23:56:20 +00:00
|
|
|
return
|
2018-02-05 17:43:45 +00:00
|
|
|
}
|
2018-11-24 05:33:03 +00:00
|
|
|
document.body.classList.toggle('modal-open', true)
|
2018-04-08 23:56:20 +00:00
|
|
|
this._a11yDialog.show()
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
this.set({ fadedIn: true })
|
|
|
|
})
|
|
|
|
},
|
2018-04-20 04:38:01 +00:00
|
|
|
closeDialog (thisId) {
|
2018-04-19 16:37:05 +00:00
|
|
|
let { id } = this.get()
|
|
|
|
if (id !== thisId) {
|
2018-04-08 23:56:20 +00:00
|
|
|
return
|
2018-02-04 21:49:43 +00:00
|
|
|
}
|
2018-04-08 23:56:20 +00:00
|
|
|
setTimeout(() => { // use setTimeout to workaround svelte timing issue
|
|
|
|
this._a11yDialog.hide()
|
|
|
|
}, 0)
|
|
|
|
}
|
2018-02-04 21:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 20:46:16 +00:00
|
|
|
</script>
|