* fix css focuses * #90 - wip * #90 - fix to generate PDF * #90 - wip * #90 - wip * #90 - wip * #90 - wip * #90 - fix to calendar * #90 - wip * #90 - fix * #90 - fix lint * #90 - fix * Apply suggestions from code review Co-authored-by: Krzysztof Rewak <krzysztof.rewak@gmail.com> Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * #90 - cr fixes * #90 - fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl> Co-authored-by: Krzysztof Rewak <krzysztof.rewak@gmail.com> Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
This commit is contained in:
65
resources/js/Shared/InertiaLink.js
Normal file
65
resources/js/Shared/InertiaLink.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import { h, ref } from 'vue'
|
||||
import { Inertia, mergeDataIntoQueryString, shouldIntercept } from '@inertiajs/inertia'
|
||||
|
||||
export default {
|
||||
name: 'InertiaLink',
|
||||
props: {
|
||||
as: {
|
||||
type: String,
|
||||
default: 'a',
|
||||
},
|
||||
data: {
|
||||
type: Object,
|
||||
default: () => ({}),
|
||||
},
|
||||
href: {
|
||||
type: String,
|
||||
},
|
||||
method: {
|
||||
type: String,
|
||||
default: 'get',
|
||||
},
|
||||
replace: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
preserveScroll: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
preserveState: {
|
||||
type: Boolean,
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
setup(props, { slots, attrs }) {
|
||||
const processing = ref(false)
|
||||
|
||||
return props => {
|
||||
const as = props.as.toLowerCase()
|
||||
const method = props.method.toLowerCase()
|
||||
const [href, data] = mergeDataIntoQueryString(method, props.href || '', props.data, 'brackets')
|
||||
|
||||
return h(props.as, {
|
||||
...attrs,
|
||||
...as === 'a' ? { href } : {},
|
||||
onClick: (event) => {
|
||||
if (shouldIntercept(event)) {
|
||||
event.preventDefault()
|
||||
|
||||
Inertia.visit(href, {
|
||||
data: data,
|
||||
method: method,
|
||||
replace: props.replace,
|
||||
preserveScroll: props.preserveScroll,
|
||||
preserveState: props.preserveState ?? (method !== 'get'),
|
||||
onBefore: () => !processing.value,
|
||||
onStart: () => processing.value = true,
|
||||
onFinish: () => processing.value = false,
|
||||
})
|
||||
}
|
||||
},
|
||||
}, slots)
|
||||
}
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user