Class: PhlexKit::ToastAction

Inherits:
BaseComponent show all
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

Methods inherited from BaseComponent

#on

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_templateObject



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
  button(**mix({ type: :button, class: "pk-toast-action", data: data }, @attrs)) { @label }
end