Class: Polaris::PopoverComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/popover_component.rb

Constant Summary collapse

ALIGNMENT_DEFAULT =
:center
ALIGNMENT_OPTIONS =
[:left, :right, :center]
POSITION_DEFAULT =
:auto
POSITION_OPTIONS =
[:auto, :above, :below]

Constants included from ViewHelper

ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from ViewHelper

#polaris_body_styles, #polaris_icon_source, #polaris_inversed_colors

Methods included from OptionHelper

#append_option, #prepend_option

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(active: false, inline: true, fixed: false, fluid_content: false, full_height: false, full_width: false, sectioned: false, alignment: ALIGNMENT_DEFAULT, position: POSITION_DEFAULT, append_to_body: false, wrapper_arguments: {}, **system_arguments) ⇒ PopoverComponent



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/components/polaris/popover_component.rb', line 17

def initialize(
  active: false,
  inline: true,
  fixed: false,
  fluid_content: false,
  full_height: false,
  full_width: false,
  sectioned: false,
  alignment: ALIGNMENT_DEFAULT,
  position: POSITION_DEFAULT,
  append_to_body: false,
  wrapper_arguments: {},
  **system_arguments
)
  @active = active
  @inline = inline
  @fixed = fixed
  @fluid_content = fluid_content
  @full_height = full_height
  @full_width = full_width
  @sectioned = sectioned
  @alignment = fetch_or_fallback(ALIGNMENT_OPTIONS, alignment, ALIGNMENT_DEFAULT)
  @position = fetch_or_fallback(POSITION_OPTIONS, position, POSITION_DEFAULT)
  @append_to_body = append_to_body
  @wrapper_arguments = wrapper_arguments
  @system_arguments = system_arguments
  @popover_arguments = {}
  @content_arguments = {}
end

Instance Method Details

#content_argumentsObject



92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/components/polaris/popover_component.rb', line 92

def content_arguments
  @content_arguments.tap do |opts|
    opts[:tag] = "div"
    opts[:tabindex] ||= "-1"
    opts[:classes] = class_names(
      @content_arguments[:classes],
      "Polaris-Popover__Content",
      "Polaris-Popover__Content--fluidContent": @fluid_content,
      "Polaris-Popover__Content--fullHeight": @full_height
    )
  end
end

#popover_argumentsObject



80
81
82
83
84
85
86
87
88
89
90
# File 'app/components/polaris/popover_component.rb', line 80

def popover_arguments
  @popover_arguments.tap do |opts|
    opts[:tag] = "div"
    opts[:classes] = class_names(
      @content_arguments[:classes],
      "Polaris-Popover",
      "Polaris-Popover--fullWidth": @full_width,
      "Polaris-Popover--positionedAbove": @position == :above
    )
  end
end

#popperjs_placementObject



105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/components/polaris/popover_component.rb', line 105

def popperjs_placement
  placement =
    case @position
    when :above then "top"
    when :below then "bottom"
    else
      "auto"
    end
  placement += "-start" if @alignment == :left
  placement += "-end" if @alignment == :right
  placement
end

#system_argumentsObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/components/polaris/popover_component.rb', line 63

def system_arguments
  @system_arguments.tap do |opts|
    opts[:tag] = "div"
    opts[:data] ||= {}
    unless @append_to_body
      opts[:data]["polaris_popover_target"] = "popover"
    end
    opts[:classes] = class_names(
      @system_arguments[:classes],
      "Polaris-PositionedOverlay",
      "Polaris-Popover__PopoverOverlay",
      "Polaris-Popover__PopoverOverlay--closed",
      "Polaris-Popover__PopoverOverlay--fixed": @fixed
    )
  end
end

#wrapper_argumentsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/components/polaris/popover_component.rb', line 47

def wrapper_arguments
  @wrapper_arguments.tap do |opts|
    opts[:tag] = "div"
    opts[:data] ||= {}
    prepend_option(opts[:data], :controller, "polaris-popover")
    opts[:data][:polaris_popover_append_to_body_value] = @append_to_body
    opts[:data][:polaris_popover_active_value] = @active
    opts[:data][:polaris_popover_placement_value] = popperjs_placement
    opts[:data][:polaris_popover_open_class] = "Polaris-Popover__PopoverOverlay--open"
    opts[:data][:polaris_popover_closed_class] = "Polaris-Popover__PopoverOverlay--closed"
    if @inline
      prepend_option(opts, :style, "display: inline-block;")
    end
  end
end