Files
Jonathan Adeline 38ccc54c2e chore: update Iconoir to 7.12.2 (#7012)
* chore(deps): update Iconoir to 7.12.2

* test: update grid visibility selector for Iconoir 7

* fix: restore open and slashed eye icons

* docs: document Iconoir 7 plugin changes
2026-12-04 15:36:56 +04:00

165 lines
3.9 KiB
Vue

<template>
<Modal
ref="modal"
class="user-template-modal-wrapper user-template-modal-wrapper--small"
:box-padding="false"
:close-button="false"
@hidden="hidden"
>
<form
ref="form"
class="user-template-modal"
@submit.prevent="confirm"
@keydown.tab="keepFocusInside"
>
<div class="user-template-modal__head">
<h2 class="user-template-modal__title">{{ title }}</h2>
<button
type="button"
class="user-template-modal__head-action user-template-modal__close"
:title="$t('action.close')"
@click="hide()"
>
<i class="iconoir-xmark"></i>
</button>
</div>
<div class="user-template-modal__body">
<slot></slot>
</div>
<div class="user-template-modal__footer">
<div class="user-template-modal__footer-actions">
<Button
ref="cancelButton"
type="secondary"
button-type="button"
@click="hide()"
>
{{ $t('action.cancel') }}
</Button>
<Button
:type="danger ? 'danger' : 'primary'"
button-type="submit"
:loading="loading"
:disabled="loading || confirmDisabled"
>
{{ confirmLabel }}
</Button>
</div>
</div>
</form>
</Modal>
</template>
<script setup>
import { computed, nextTick, reactive, ref } from 'vue'
import { notifyIf } from '@baserow/modules/core/utils/error'
import { useReturnFocus } from '@baserow/modules/core/composables/useReturnFocus'
const props = defineProps({
template: {
type: Object,
required: true,
},
title: {
type: String,
required: true,
},
confirmLabel: {
type: String,
required: true,
},
danger: {
type: Boolean,
required: false,
default: false,
},
confirmDisabled: {
type: Boolean,
required: false,
default: false,
},
// Sends the request for the template, and resolves with what `done` is emitted
// with.
request: {
type: Function,
required: true,
},
})
// `done` is emitted with the id of the template, what the request resolved with
// and the `performance.now()` at which it was sent, also when the modal was closed
// or opened for another template while the request ran.
const emit = defineEmits(['done', 'hidden'])
const modal = ref(null)
const form = ref(null)
const cancelButton = ref(null)
const { remember: rememberFocus, restore: restoreFocus } = useReturnFocus()
// The ids of the templates whose request runs.
const pending = reactive(new Set())
const loading = computed(() => pending.has(props.template.id))
async function show(...args) {
rememberFocus()
modal.value.show(...args)
await nextTick()
const field = form.value?.querySelector('input, textarea')
if (field) {
field.focus()
} else {
cancelButton.value?.focus()
}
}
function hidden() {
restoreFocus()
emit('hidden')
}
function keepFocusInside(event) {
const focusable = [
...form.value.querySelectorAll('button:not([disabled]), input, textarea'),
]
const first = focusable[0]
const last = focusable[focusable.length - 1]
if (event.shiftKey && document.activeElement === first) {
event.preventDefault()
last.focus()
} else if (!event.shiftKey && document.activeElement === last) {
event.preventDefault()
first.focus()
}
}
function hide(...args) {
modal.value?.hide(...args)
}
async function confirm() {
const template = props.template
const { id } = template
if (pending.has(id) || props.confirmDisabled) {
return
}
pending.add(id)
const requestedAt = performance.now()
try {
const result = await props.request(template)
emit('done', id, result, requestedAt)
if (props.template.id === id) {
hide()
}
} catch (error) {
notifyIf(error, 'templates')
} finally {
pending.delete(id)
}
}
defineExpose({ show, hide })
</script>