From 2d30c3e0125e1fc9277e5a3e50c95abaae57f58e Mon Sep 17 00:00:00 2001 From: Pascal Baljet Date: Wed, 2 Oct 2024 23:12:09 +0200 Subject: [PATCH] Introduced `visitModal` method --- demo-app/resources/js/Pages/Visit.vue | 24 +++++++++++++++ demo-app/tests/Browser/VisitTest.php | 35 ++++++++++++++++++++++ docs/basic-usage.md | 42 +++++++++++++++++++++++++++ vue/src/ModalLink.vue | 30 +++++++++---------- vue/src/inertiauiModal.js | 16 +++++++++- vue/src/modalStack.js | 28 +++++++++++------- 6 files changed, 148 insertions(+), 27 deletions(-) create mode 100644 demo-app/resources/js/Pages/Visit.vue create mode 100644 demo-app/tests/Browser/VisitTest.php diff --git a/demo-app/resources/js/Pages/Visit.vue b/demo-app/resources/js/Pages/Visit.vue new file mode 100644 index 0000000..6a6f57e --- /dev/null +++ b/demo-app/resources/js/Pages/Visit.vue @@ -0,0 +1,24 @@ + + + \ No newline at end of file diff --git a/demo-app/tests/Browser/VisitTest.php b/demo-app/tests/Browser/VisitTest.php new file mode 100644 index 0000000..c3c712e --- /dev/null +++ b/demo-app/tests/Browser/VisitTest.php @@ -0,0 +1,35 @@ +browse(function (Browser $browser) { + + $browser->visit('/visit') + ->waitForText('Visit programmatically') + ->press('Open Local Modal') + ->waitFor('.im-dialog') + ->assertSeeIn('.im-modal-content', 'Hi there!'); + }); + } + + #[Test] + public function it_can_programmatically_visit_a_modal() + { + $this->browse(function (Browser $browser) { + + $browser->visit('/visit') + ->waitForText('Visit programmatically') + ->press('Open Route Modal') + ->waitFor('.im-dialog') + ->assertSeeIn('.im-modal-content', 'Hi again!'); + }); + } +} diff --git a/docs/basic-usage.md b/docs/basic-usage.md index 084dcf8..dd730d0 100644 --- a/docs/basic-usage.md +++ b/docs/basic-usage.md @@ -156,3 +156,45 @@ Then there are two more events: `@close` and `@after-leave`. The `@close` event ### Customizing Just like the `Modal` component, you can pass additional props to the `ModalLink` component to customize its behavior and style. Check out the [Configuration](/configuration.html) section for a list of all available props. + +## Programmatic Usage + +Instead of using the `ModalLink` component, you can also open a modal programmatically using the `visitModal` method. + +```vue + + + +``` + +If you want to open a [Local Modal](/local-modals.html), you must prepend the URL with a `#`: + +```js +visitModal('#confirm-action') +``` + +The `visitModal` method accepts a second argument, which is an object with options: + +```js +visitModal('/users/create', { + method: 'post', + data: { default_name: 'John Doe' }, + headers: { 'X-Header': 'Value' }, + config: { + slideover: true, + } + onClose: () => console.log('Modal closed'), + onAfterLeave: () => console.log('Modal removed from DOM'), + queryStringArrayFormat: 'brackets', +}) +``` + +The `config` option allows you to customize the behavior and style of the modal. You should check out the [Configuration](/configuration.html#default-configuration) section for a list of all available options. The `queryStringArrayFormat` can be set to either `brackets` or `indices`. \ No newline at end of file diff --git a/vue/src/ModalLink.vue b/vue/src/ModalLink.vue index b4aa353..04fe7b3 100644 --- a/vue/src/ModalLink.vue +++ b/vue/src/ModalLink.vue @@ -1,6 +1,6 @@