Class: PhlexKit::AttachmentTrigger

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/attachment/attachment_trigger.rb

Overview

Full-card overlay that activates the attachment (a preview link or dialog trigger). Sits BEHIND AttachmentActions in the stacking order, so actions stay independently clickable. Give it an aria-label; pass as: :a + href: for a link. See attachment.rb.

Constant Summary collapse

AS_TAGS =
%i[button a].freeze

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(as: :button, href: nil, **attrs) ⇒ AttachmentTrigger

Returns a new instance of AttachmentTrigger.



9
10
11
12
13
14
15
16
17
18
19
# File 'app/components/phlex_kit/attachment/attachment_trigger.rb', line 9

def initialize(as: :button, href: nil, **attrs)
  @as = as.to_sym
  unless AS_TAGS.include?(@as)
    raise ArgumentError, "unknown AttachmentTrigger as: #{@as.inspect} (use one of #{AS_TAGS.join(", ")})"
  end
  if @as == :a && href.nil?
    raise ArgumentError, "AttachmentTrigger requires href: when as: :a"
  end
  @href = href
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



21
22
23
24
25
26
27
28
# File 'app/components/phlex_kit/attachment/attachment_trigger.rb', line 21

def view_template(&block)
  base = { class: "pk-attachment-trigger" }
  if @as == :a
    a(**mix(base.merge(href: @href), @attrs), &block)
  else
    button(**mix(base.merge(type: :button), @attrs), &block)
  end
end