api-client/packages/hoppscotch-common/src/components/collections/EditFolder.vue

93 lines
1.8 KiB
Vue
Raw Normal View History

<template>
<SmartModal
v-if="show"
dialog
:title="t('folder.edit')"
@close="emit('hide-modal')"
>
<template #body>
<div class="flex flex-col">
2021-07-09 17:19:45 +00:00
<input
id="selectLabelEditFolder"
v-model="name"
v-focus
2021-08-07 09:21:13 +00:00
class="input floating-input"
placeholder=" "
2021-07-09 17:19:45 +00:00
type="text"
autocomplete="off"
2021-07-09 17:19:45 +00:00
@keyup.enter="editFolder"
/>
2021-08-07 09:21:13 +00:00
<label for="selectLabelEditFolder">
{{ t("action.label") }}
2021-08-07 09:21:13 +00:00
</label>
2021-07-09 17:19:45 +00:00
</div>
</template>
<template #footer>
2022-09-30 04:17:12 +00:00
<span class="flex space-x-2">
<ButtonPrimary
:label="t('action.save')"
:loading="loadingState"
2022-09-30 04:17:12 +00:00
outline
@click="editFolder"
/>
2022-09-30 04:17:12 +00:00
<ButtonSecondary
:label="t('action.cancel')"
outline
filled
@click="hideModal"
/>
</span>
</template>
</SmartModal>
</template>
<script setup lang="ts">
import { ref, watch } from "vue"
import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast"
2021-08-24 03:44:46 +00:00
const t = useI18n()
const toast = useToast()
const props = withDefaults(
defineProps<{
show: boolean
loadingState: boolean
editingFolderName: string
}>(),
{
show: false,
loadingState: false,
editingFolderName: "",
}
)
const emit = defineEmits<{
(e: "submit", name: string): void
(e: "hide-modal"): void
}>()
const name = ref("")
watch(
() => props.editingFolderName,
(newName) => {
name.value = newName
}
)
const editFolder = () => {
if (name.value.trim() === "") {
toast.error(t("folder.invalid_name"))
return
}
emit("submit", name.value)
}
const hideModal = () => {
name.value = ""
emit("hide-modal")
}
</script>