Class: PhlexKit::ToastAction
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::ToastAction
- Defined in:
- app/components/phlex_kit/toast/toast_action.rb
Overview
Filled action button in a toast (e.g. "Undo"). Pass on: a Stimulus action
string for server-rendered toasts; client-spawned toasts get their onClick
wired by the toaster when it clones the action slot template.
See toast_region.rb.
Instance Method Summary collapse
-
#initialize(label:, on: nil, **attrs) ⇒ ToastAction
constructor
A new instance of ToastAction.
- #view_template ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(label:, on: nil, **attrs) ⇒ ToastAction
Returns a new instance of ToastAction.
7 8 9 10 11 |
# File 'app/components/phlex_kit/toast/toast_action.rb', line 7 def initialize(label:, on: nil, **attrs) @label = label @on = on @attrs = attrs end |
Instance Method Details
#view_template ⇒ Object
13 14 15 16 17 |
# File 'app/components/phlex_kit/toast/toast_action.rb', line 13 def view_template data = { slot: "action" } data[:action] = @on if @on (**mix({ type: :button, class: "pk-toast-action", data: data }, @attrs)) { @label } end |