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_html_classes, #polaris_html_styles, #polaris_icon_source

Methods included from StylesListHelper

#styles_list

Methods included from OptionHelper

#append_option, #prepend_option

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #fetch_or_fallback_nested

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, scrollable_shadow: true, text_field_activator: false, wrapper_arguments: {}, **system_arguments) ⇒ PopoverComponent

Returns a new instance of PopoverComponent.



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
46
47
48
49
50
51
# File 'app/components/polaris/popover_component.rb', line 19

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,
  scrollable_shadow: true,
  text_field_activator: 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)
  @scrollable_shadow = scrollable_shadow
  @text_field_activator = text_field_activator
  @append_to_body = append_to_body
  @wrapper_arguments = wrapper_arguments
  @system_arguments = system_arguments
  @popover_arguments = {}
  @content_arguments = {}
end

Instance Method Details

#content_argumentsObject



99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/components/polaris/popover_component.rb', line 99

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



87
88
89
90
91
92
93
94
95
96
97
# File 'app/components/polaris/popover_component.rb', line 87

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

#popover_placementObject



112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/components/polaris/popover_component.rb', line 112

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

#system_argumentsObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/components/polaris/popover_component.rb', line 70

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/components/polaris/popover_component.rb', line 53

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] = popover_placement
    opts[:data][:polaris_popover_text_field_activator_value] = @text_field_activator
    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