Class: ShadcnPhlexcomponents::PopoverTrigger

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/popover.rb

Constant Summary

Constants inherited from Base

Base::SANITIZER_ALLOWED_ATTRIBUTES, Base::SANITIZER_ALLOWED_TAGS, Base::TAILWIND_MERGER

Instance Method Summary collapse

Methods inherited from Base

#before_template, #convert_collection_hash_to_struct, #find_as_child, #icon, #item_disabled?, #merge_default_attributes, #merged_as_child_attributes, #nokogiri_attributes_to_hash, #overlay, #sanitize_as_child

Constructor Details

#initialize(as_child: false, aria_id: nil, **attributes) ⇒ PopoverTrigger

Returns a new instance of PopoverTrigger.



43
44
45
46
47
# File 'lib/shadcn_phlexcomponents/components/popover.rb', line 43

def initialize(as_child: false, aria_id: nil, **attributes)
  @as_child = as_child
  @aria_id = aria_id
  super(**attributes)
end

Instance Method Details

#default_attributesObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/shadcn_phlexcomponents/components/popover.rb', line 64

def default_attributes
  {
    role: "button",
    aria: {
      haspopup: "dialog",
      expanded: false,
      controls: "#{@aria_id}-content",
    },
    data: {
      as_child: @as_child.to_s,
      action: "click->popover#toggle",
      popover_target: "trigger",
    },
  }
end

#view_templateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/shadcn_phlexcomponents/components/popover.rb', line 49

def view_template(&)
  if @as_child
    content = capture(&)
    element = find_as_child(content.to_s)
    vanish(&)
    merged_attributes = merged_as_child_attributes(element, @attributes)

    send(element.name, **merged_attributes) do
      sanitize_as_child(element.children.to_s)
    end
  else
    div(**@attributes, &)
  end
end