Class: Primer::PopoverComponent

Inherits:
Component
  • Object
show all
Includes:
ViewComponent::Slotable
Defined in:
app/components/primer/popover_component.rb

Overview

Use popovers to bring attention to specific user interface elements, typically to suggest an action or to guide users through a new experience.

By default, the popover renders with absolute positioning, meaning it should usually be wrapped in an element with a relative position in order to be positioned properly. To render the popover with relative positioning, use the relative property.

Defined Under Namespace

Classes: Body, Heading

Constant Summary

Constants inherited from Component

Component::STATUSES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

status

Methods included from ViewHelper

#primer

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(**system_arguments) ⇒ PopoverComponent

Returns a new instance of PopoverComponent.

Examples:

Default

<%= render Primer::PopoverComponent.new do |component| %>
  <% component.slot(:heading) do %>
    Activity feed
  <% end %>
  <% component.slot(:body) do %>
    This is the Popover body.
  <% end %>
<% end %>

Large

<%= render Primer::PopoverComponent.new do |component| %>
  <% component.slot(:heading) do %>
    Activity feed
  <% end %>
  <% component.slot(:body, large: true) do %>
    This is the large Popover body.
  <% end %>
<% end %>

Caret position

<%= render Primer::PopoverComponent.new do |component| %>
  <% component.slot(:heading) do %>
    Activity feed
  <% end %>
  <% component.slot(:body, caret: :left) do %>
    This is the large Popover body.
  <% end %>
<% end %>

Parameters:

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



44
45
46
47
48
49
50
51
52
53
54
# File 'app/components/primer/popover_component.rb', line 44

def initialize(**system_arguments)
  @system_arguments = system_arguments
  @system_arguments[:tag] ||= :div
  @system_arguments[:classes] = class_names(
    system_arguments[:classes],
    "Popover"
  )
  @system_arguments[:position] ||= :relative
  @system_arguments[:right] = false unless system_arguments.key?(:right)
  @system_arguments[:left] = false unless system_arguments.key?(:left)
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/components/primer/popover_component.rb', line 56

def render?
  body.present?
end