-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb43631
commit fa04aed
Showing
13 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
demo-app/resources/js/Pages/ComponentThatUsesModalInstance.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useModal } from '@inertiaui/modal-react' | ||
|
||
export default function ComponentThatUsesModalInstance() { | ||
const modal = useModal() | ||
|
||
return ( | ||
modal ? <div> | ||
<button onClick={() => modal.close()}>Close Modal with index {modal.index}</button> | ||
</div> : <div /> | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
demo-app/resources/js/Pages/ComponentThatUsesModalInstance.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup> | ||
import { useModal } from '@inertiaui/modal-vue' | ||
const modal = useModal() | ||
</script> | ||
|
||
<template> | ||
<div v-if="modal"> | ||
<button @click="modal.close()">Close Modal with index {{ modal.index }}</button> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Tests\Browser; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use Tests\DuskTestCase; | ||
|
||
class UseModalTest extends DuskTestCase | ||
{ | ||
#[Test] | ||
public function it_can_inject_the_current_modal_context_from_a_component() | ||
{ | ||
$this->browse(function (Browser $browser) { | ||
$browser->visit('/users/1/edit') | ||
->waitForFirstUser() | ||
->waitFor('.im-dialog') | ||
->within('.im-dialog[data-inertiaui-modal-index="0"]', function (Browser $browser) { | ||
$browser->assertSee('Close Modal with index 0'); | ||
}) | ||
->clickLink('Add Role') | ||
->waitFor('.im-dialog[data-inertiaui-modal-index="1"]') | ||
->within('.im-dialog[data-inertiaui-modal-index="1"]', function (Browser $browser) { | ||
$browser->assertSee('Close Modal with index 1'); | ||
}) | ||
->press('Close Modal with index 1') | ||
->waitUntilMissing('.im-dialog[data-inertiaui-modal-index="1"]'); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useModalIndex } from './ModalRenderer.jsx' | ||
import { useModalStack } from './ModalRoot.jsx' | ||
|
||
export default function useModal() { | ||
return useModalStack().stack[useModalIndex()] ?? null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { inject } from 'vue' | ||
|
||
export default function useModal() { | ||
return inject('modalContext', null) | ||
} |