Skip to content

Commit

Permalink
docs[Op#56496]: touch up documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
akabiru committed Sep 30, 2024
1 parent 69e91cb commit cab737f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lookbook/docs/patterns/09-flash-modal.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ This pattern defines use cases where a modal view component is rendered on the n
## Overview

To flash a modal, set a `flash[:op_modal]` hash in your controller action. The hash should contain the following keys:
* `type:` - the modal component to render
* `component:` - the modal component to render
* `parameters:` - the parameters to pass to the modal component

You can use the helper method `flash_op_modal` to set the flash modal properties.

Ex.

```ruby
Expand All @@ -18,6 +20,23 @@ flash_op_modal component: ::Storages::ProjectStorages::OAuthAccessGrantedModalCo

Internally, the `FlashMessagesHelper#render_flash_messages` will select flash messages with the key `:op_modal` and render the modal component with the given parameters.

P.S. When the `component` is a `Primer::Alpha::Dialog` the `auto-show-dialog` stimulus controller should be declared in order to automatically show the dialog when the page is loaded.

Ex.

```ruby
render(
Primer::Alpha::Dialog.new(
id: dialog_id,
title:,
data: {
controller: "auto-show-dialog",
}
) do
# ....
end
```

### Flash a modal on callback from external service

When you want to display a modal after a callback request from an external service, store the op modal component directly in the `session` in the controller action that performs by calling `OpModalFlashable#store_callback_op_modal_flash` bofore the open redirect and then extract them in the controller action that handles the callback via `OpTurbo::Flashable#retrieve_callback_op_modal_flash`.
Expand Down

0 comments on commit cab737f

Please sign in to comment.