Skip to content

Commit

Permalink
Merge branch 'base-route-url-radix' of github.com:inertiaui/modal int…
Browse files Browse the repository at this point in the history
…o base-route-url-radix
  • Loading branch information
pascalbaljet committed Oct 22, 2024
2 parents ad26b79 + 93e5f3d commit 162964a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
24 changes: 12 additions & 12 deletions react/src/HeadlessModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ const HeadlessModal = forwardRef(({ name, children, ...props }, ref) => {
<>
{typeof children === 'function'
? children({
afterLeave: modalContext.afterLeave,
close: modalContext.close,
emit: modalContext.emit,
getChildModal: modalContext.getChildModal,
getParentModal: modalContext.getParentModal,
index: modalContext.index,
isOpen: modalContext.open,
modalContext,
modalProps,
reload: modalContext.reload,
setOpen: modalContext.setOpen,
})
afterLeave: modalContext.afterLeave,
close: modalContext.close,
emit: modalContext.emit,
getChildModal: modalContext.getChildModal,
getParentModal: modalContext.getParentModal,
index: modalContext.index,
isOpen: modalContext.open,
modalContext,
modalProps,
reload: modalContext.reload,
setOpen: modalContext.setOpen,
})
: children}

{/* Next modal in the stack */}
Expand Down
14 changes: 8 additions & 6 deletions react/src/ModalRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ const ModalRenderer = ({ index }) => {
}, [stack, index])

return (
modalContext?.component && <ModalIndexContext.Provider value={index}>
<modalContext.component
{...modalContext.componentProps}
onModalEvent={(...args) => modalContext.emit(...args)}
/>
</ModalIndexContext.Provider>
modalContext?.component && (
<ModalIndexContext.Provider value={index}>
<modalContext.component
{...modalContext.componentProps}
onModalEvent={(...args) => modalContext.emit(...args)}
/>
</ModalIndexContext.Provider>
)
)
}

Expand Down
32 changes: 17 additions & 15 deletions react/src/ModalRoot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ export const ModalStackProvider = ({ children }) => {
return true
}

return newStack.map((modal) => ({ id: modal.id, shouldRender: modal.shouldRender }))
.reverse()
.find((modal) => modal.shouldRender)?.id === modalId
return (
newStack
.map((modal) => ({ id: modal.id, shouldRender: modal.shouldRender }))
.reverse()
.find((modal) => modal.shouldRender)?.id === modalId
)
}

newStack.forEach((modal, index) => {
Expand All @@ -57,7 +60,6 @@ export const ModalStackProvider = ({ children }) => {
// Find the first open modal after this one
return newStack.slice(index + 1).find((modal) => modal.open)
}

})

return newStack
Expand Down Expand Up @@ -259,16 +261,17 @@ export const ModalStackProvider = ({ children }) => {
return modal
}

const visitModal = (url, options = {}) => visit(
url,
options.method ?? 'get',
options.data ?? {},
options.headers ?? {},
options.config ?? {},
options.onClose,
options.onAfterLeave,
options.queryStringArrayFormat ?? 'brackets',
)
const visitModal = (url, options = {}) =>
visit(
url,
options.method ?? 'get',
options.data ?? {},
options.headers ?? {},
options.config ?? {},
options.onClose,
options.onAfterLeave,
options.queryStringArrayFormat ?? 'brackets',
)

const visit = (
href,
Expand Down Expand Up @@ -305,7 +308,6 @@ export const ModalStackProvider = ({ children }) => {
'X-InertiaUI-Modal-Use-Router': useInertiaRouter ? 1 : 0,
}


if (useInertiaRouter) {
// Pushing the modal to the stack will be handled by the ModalRoot...
return router.visit(url, {
Expand Down

0 comments on commit 162964a

Please sign in to comment.