2018-05-12 15:00:11 -07:00
|
|
|
<ModalDialog
|
|
|
|
{id}
|
|
|
|
{label}
|
|
|
|
{title}
|
2019-04-14 14:09:10 -07:00
|
|
|
shrinkWidthToFit={true}
|
2018-05-12 15:00:11 -07:00
|
|
|
background="var(--main-bg)"
|
2019-05-09 20:34:45 -07:00
|
|
|
on:show="onShow()"
|
2018-05-12 15:00:11 -07:00
|
|
|
>
|
|
|
|
<form class="copy-dialog-form">
|
|
|
|
<input value={text}
|
|
|
|
ref:input
|
|
|
|
>
|
|
|
|
<button type="button" on:click="onClick()">
|
|
|
|
Copy
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
</ModalDialog>
|
|
|
|
<style>
|
|
|
|
.copy-dialog-form {
|
|
|
|
display: grid;
|
|
|
|
grid-template-rows: min-content min-content;
|
|
|
|
grid-template-columns: 1fr;
|
|
|
|
grid-gap: 10px;
|
|
|
|
padding: 10px 20px;
|
|
|
|
width: 400px;
|
2019-04-13 20:02:25 +02:00
|
|
|
max-width: calc(100% - 40px);
|
2018-05-12 15:00:11 -07:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
import ModalDialog from './ModalDialog.html'
|
|
|
|
import { show } from '../helpers/showDialog'
|
|
|
|
import { close } from '../helpers/closeDialog'
|
|
|
|
import { oncreate as onCreateDialog } from '../helpers/onCreateDialog'
|
2018-12-22 15:37:51 -08:00
|
|
|
import { toast } from '../../toast/toast'
|
2018-05-12 15:00:11 -07:00
|
|
|
import { doubleRAF } from '../../../_utils/doubleRAF'
|
|
|
|
|
2019-01-26 12:05:14 -08:00
|
|
|
function copyFromInput (input) {
|
|
|
|
// workarounds for iOS, via https://stackoverflow.com/a/34046084
|
2019-08-03 13:49:37 -07:00
|
|
|
const range = document.createRange()
|
2019-01-26 12:05:14 -08:00
|
|
|
range.selectNodeContents(input)
|
2019-08-03 13:49:37 -07:00
|
|
|
const selection = window.getSelection()
|
2019-01-26 12:05:14 -08:00
|
|
|
selection.removeAllRanges()
|
|
|
|
selection.addRange(range)
|
|
|
|
input.setSelectionRange(0, 9999999)
|
|
|
|
document.execCommand('copy')
|
|
|
|
}
|
|
|
|
|
2018-05-12 15:00:11 -07:00
|
|
|
export default {
|
|
|
|
oncreate () {
|
|
|
|
onCreateDialog.call(this)
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
show,
|
|
|
|
close,
|
|
|
|
onClick () {
|
2019-08-03 13:49:37 -07:00
|
|
|
const { input } = this.refs
|
2019-01-26 12:05:14 -08:00
|
|
|
copyFromInput(input)
|
2018-05-12 15:00:11 -07:00
|
|
|
toast.say('Copied to clipboard')
|
|
|
|
this.close()
|
2019-05-09 20:34:45 -07:00
|
|
|
},
|
|
|
|
onShow () {
|
2019-08-03 13:49:37 -07:00
|
|
|
const { text } = this.get()
|
|
|
|
const { input } = this.refs
|
2019-05-09 20:34:45 -07:00
|
|
|
// double raf is to work around a11y-dialog trying to set the input
|
|
|
|
doubleRAF(() => {
|
|
|
|
input.focus()
|
|
|
|
input.setSelectionRange(0, text.length)
|
|
|
|
})
|
2018-05-12 15:00:11 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data: () => ({
|
|
|
|
text: ''
|
|
|
|
}),
|
|
|
|
components: {
|
|
|
|
ModalDialog
|
|
|
|
}
|
|
|
|
}
|
2018-12-22 15:37:51 -08:00
|
|
|
</script>
|