Class: Shadcn::Popover::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/popover/component.rb

Overview

Port of registry/new-york-v4/ui/popover.tsx

Constant Summary

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(open: false, side: :bottom, align: :center, side_offset: 4, align_offset: 0, **attributes) ⇒ Component

Returns a new instance of Component.



15
16
17
18
19
20
21
22
23
# File 'app/components/shadcn/popover/component.rb', line 15

def initialize(open: false, side: :bottom, align: :center, side_offset: 4,
               align_offset: 0, **attributes)
  @open = open
  @side = side&.to_sym || :bottom
  @align = align&.to_sym || :center
  @side_offset = side_offset
  @align_offset = align_offset
  super(**attributes)
end

Instance Attribute Details

#alignObject (readonly)

Returns the value of attribute align.



13
14
15
# File 'app/components/shadcn/popover/component.rb', line 13

def align
  @align
end

#align_offsetObject (readonly)

Returns the value of attribute align_offset.



13
14
15
# File 'app/components/shadcn/popover/component.rb', line 13

def align_offset
  @align_offset
end

#openObject (readonly)

Returns the value of attribute open.



13
14
15
# File 'app/components/shadcn/popover/component.rb', line 13

def open
  @open
end

#sideObject (readonly)

Returns the value of attribute side.



13
14
15
# File 'app/components/shadcn/popover/component.rb', line 13

def side
  @side
end

#side_offsetObject (readonly)

Returns the value of attribute side_offset.



13
14
15
# File 'app/components/shadcn/popover/component.rb', line 13

def side_offset
  @side_offset
end

Instance Method Details

#callObject



37
38
39
# File 'app/components/shadcn/popover/component.rb', line 37

def call
  render_element(body: safe_join([ anchor, trigger, popover_content, content ].compact))
end

#element_attributes(**defaults) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'app/components/shadcn/popover/component.rb', line 25

def element_attributes(**defaults)
  super(**{
    style: merged_style(CONTENTS_STYLE),
    "data-controller" => "shadcn--popover",
    "data-shadcn--popover-open-value" => open,
    "data-shadcn--popover-side-value" => side,
    "data-shadcn--popover-align-value" => align,
    "data-shadcn--popover-side-offset-value" => side_offset,
    "data-shadcn--popover-align-offset-value" => align_offset
  }.merge(defaults))
end