Add PromptDialog to replace window.prompt (#1104)

* Save file prompt dialog

* Don't download if dialog dismissed

* refactor

* style dialog

* nit

* Autofocus
This commit is contained in:
Chenlei Hu
2024-10-04 15:33:27 -04:00
committed by GitHub
parent 39d68bcdc4
commit ebc71b0e46
12 changed files with 148 additions and 76 deletions

View File

@@ -191,8 +191,4 @@ const openNewGithubIssue = async () => {
white-space: pre-wrap;
word-wrap: break-word;
}
.no-results-placeholder {
padding-top: 0;
}
</style>

View File

@@ -0,0 +1,43 @@
<template>
<div class="prompt-dialog-content flex flex-col gap-2 pt-8">
<FloatLabel>
<InputText
ref="inputRef"
v-model="inputValue"
@keyup.enter="onConfirm"
@focus="selectAllText"
autofocus
/>
<label>{{ message }}</label>
</FloatLabel>
<Button @click="onConfirm">{{ $t('confirm') }}</Button>
</div>
</template>
<script setup lang="ts">
import Button from 'primevue/button'
import InputText from 'primevue/inputtext'
import FloatLabel from 'primevue/floatlabel'
import { ref } from 'vue'
import { useDialogStore } from '@/stores/dialogStore'
const props = defineProps<{
message: string
defaultValue: string
onConfirm: (value: string) => void
}>()
const inputValue = ref<string>(props.defaultValue)
const onConfirm = () => {
props.onConfirm(inputValue.value)
useDialogStore().closeDialog()
}
const inputRef = ref(null)
const selectAllText = () => {
if (!inputRef.value) return
const inputElement = inputRef.value.$el
inputElement.setSelectionRange(0, inputElement.value.length)
}
</script>