Class: Yattho::Beta::Popover

Inherits:
Component
  • Object
show all
Defined in:
app/components/yattho/beta/popover.rb

Overview

Use ‘Popover` 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.

Direct Known Subclasses

PopoverComponent

Constant Summary collapse

CARET_DEFAULT =
:top
CARET_MAPPINGS =
{
  CARET_DEFAULT => "",
  :bottom => "Popover-message--bottom",
  :bottom_right => "Popover-message--bottom-right",
  :bottom_left => "Popover-message--bottom-left",
  :left => "Popover-message--left",
  :left_bottom => "Popover-message--left-bottom",
  :left_top => "Popover-message--left-top",
  :right => "Popover-message--right",
  :right_bottom => "Popover-message--right-bottom",
  :right_top => "Popover-message--right-top",
  :top_left => "Popover-message--top-left",
  :top_right => "Popover-message--top-right"
}.freeze
DEFAULT_HEADING_TAG =
:h4

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(**system_arguments) ⇒ Popover

Returns a new instance of Popover.

Examples:

Default

<%= render Yattho::Beta::Popover.new do |component| %>
  <% component.with_heading do %>
    Activity feed
  <% end %>
  <% component.with_body do %>
    This is the Popover body.
  <% end %>
<% end %>

Large

<%= render Yattho::Beta::Popover.new do |component| %>
  <% component.with_heading do %>
    Activity feed
  <% end %>
  <% component.with_body(large: true) do %>
    This is the large Popover body.
  <% end %>
<% end %>

Caret position

<%= render Yattho::Beta::Popover.new do |component| %>
  <% component.with_heading do %>
    Activity feed
  <% end %>
  <% component.with_body(caret: :left) do %>
    This is the Popover body.
  <% end %>
<% end %>

With multiple elements in the body

<%= render Yattho::Beta::Popover.new do |component| %>
  <% component.with_heading do %>
    Activity feed
  <% end %>
  <% component.with_body(caret: :left) do %>
    <p>This is the Popover body.</p>
    <%= render Yattho::ButtonComponent.new(type: :submit) do %>
      Got it!
    <% end %>
  <% end %>
<% end %>

Parameters:

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



106
107
108
109
110
111
112
113
114
115
116
# File 'app/components/yattho/beta/popover.rb', line 106

def initialize(**system_arguments)
  @system_arguments = deny_tag_argument(**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.delete(:right)
  @system_arguments[:left] = false unless @system_arguments.delete(:left)
end

Instance Method Details

#body_componentObject



122
123
124
# File 'app/components/yattho/beta/popover.rb', line 122

def body_component
  Yattho::Box.new(**@body_arguments)
end

#render?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'app/components/yattho/beta/popover.rb', line 118

def render?
  body.present?
end