Class: Polaris::BannerComponent

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

Constant Summary collapse

STATUS_DEFAULT =
:default
STATUS_MAPPINGS =
{
  STATUS_DEFAULT => "Polaris-Banner--statusInfo",
  :success => "Polaris-Banner--statusSuccess",
  :info => "Polaris-Banner--statusInfo",
  :warning => "Polaris-Banner--statusWarning",
  :critical => "Polaris-Banner--statusCritical"
}
STATUS_OPTIONS =
STATUS_MAPPINGS.keys
WITHIN_DEFAULT =
:page
WITHIN_MAPPINGS =
{
  page: "Polaris-Banner--withinPage",
  container: "Polaris-Banner--withinContentContainer"
}
WITHIN_OPTIONS =
WITHIN_MAPPINGS.keys
ICON_COLOR_MAPPINGS =
{
  default: :base,
  success: :success,
  info: :highlight,
  warning: :warning,
  critical: :critical
}

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(status: STATUS_DEFAULT, within: WITHIN_DEFAULT, icon: nil, hide_icon: false, title: nil, **system_arguments) ⇒ BannerComponent

Returns a new instance of BannerComponent.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/components/polaris/banner_component.rb', line 42

def initialize(
  status: STATUS_DEFAULT,
  within: WITHIN_DEFAULT,
  icon: nil,
  hide_icon: false,
  title: nil,
  **system_arguments
)
  @status = status
  @within = within
  @icon = icon || default_icon(status)
  @hide_icon = hide_icon
  @title = title
  @system_arguments = system_arguments
end

Instance Method Details

#default_icon(status) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'app/components/polaris/banner_component.rb', line 77

def default_icon(status)
  case status
  when :success then "CheckIcon"
  when :critical then "AlertDiamondIcon"
  when :warning then "AlertTriangleIcon"
  else
    "InfoIcon"
  end
end

#has_content?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/components/polaris/banner_component.rb', line 95

def has_content?
  content.present? || action || secondary_action
end

#has_title?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'app/components/polaris/banner_component.rb', line 91

def has_title?
  @title.present?
end

#render_iconObject



73
74
75
# File 'app/components/polaris/banner_component.rb', line 73

def render_icon
  polaris_icon(name: @icon, color: ICON_COLOR_MAPPINGS[@status])
end

#system_argumentsObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/components/polaris/banner_component.rb', line 58

def system_arguments
  @system_arguments.tap do |opts|
    opts[:tabindex] = 0
    opts[:role] = "status"
    opts[:tag] = "div"
    opts[:classes] = class_names(
      opts[:classes],
      "Polaris-Banner",
      STATUS_MAPPINGS[fetch_or_fallback(STATUS_OPTIONS, @status, STATUS_DEFAULT)],
      WITHIN_MAPPINGS[fetch_or_fallback(WITHIN_OPTIONS, @within, WITHIN_DEFAULT)],
      "Polaris-Banner--onlyTitle": has_title? && !has_content?
    )
  end
end

#within_container?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/components/polaris/banner_component.rb', line 87

def within_container?
  @within == :container
end