Spark DSL extension for modal behavior.
Adds modal-specific state and actions to a Lavash Component:
- Open/close state management (modal owns its state)
- Escape key handling
- Backdrop click handling
- Auto-injected :close and :noop actions
Usage
defmodule MyApp.EditModal do
use Lavash.Component, extensions: [Lavash.Overlay.Modal.Dsl]
modal do
open_field :product_id # nil = closed, non-nil = open with this ID
close_on_escape true
close_on_backdrop true
end
# Define an :open action for the parent to invoke
actions do
action :open, [:product_id] do
set :product_id, &(&1.params.product_id)
end
end
render fn assigns ->
~H"..."
end
endParent opens the modal via invoke:
invoke "my-modal", :open,
module: MyApp.EditModal,
params: [product_id: 123]The plugin will:
- Inject the open_field as ephemeral state (if not already defined)
- Inject :close action that sets open_field to nil
- Inject :noop action for backdrop click handling
- Generate render/1 with modal chrome wrapping your content