Class: Polaris::IconComponent

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

Constant Summary collapse

COLOR_DEFAULT =
:default
COLOR_MAPPINGS =
{
  COLOR_DEFAULT => "",
  :base => "Polaris-Icon--colorBase",
  :subdued => "Polaris-Icon--colorSubdued",
  :critical => "Polaris-Icon--colorCritical",
  :warning => "Polaris-Icon--colorWarning",
  :highlight => "Polaris-Icon--colorHighlight",
  :success => "Polaris-Icon--colorSuccess",
  :primary => "Polaris-Icon--colorPrimary"
}
COLOR_OPTIONS =
COLOR_MAPPINGS.keys

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(name: nil, backdrop: false, color: COLOR_DEFAULT, **system_arguments) ⇒ IconComponent

Returns a new instance of IconComponent.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/components/polaris/icon_component.rb', line 18

def initialize(
  name: nil,
  backdrop: false,
  color: COLOR_DEFAULT,
  **system_arguments
)
  @source = name ? polaris_icon_source(name) : nil

  @system_arguments = system_arguments
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "Polaris-Icon",
    COLOR_MAPPINGS[fetch_or_fallback(COLOR_OPTIONS, color, COLOR_DEFAULT)],
    "Polaris-Icon--hasBackdrop" => backdrop,
    "Polaris-Icon--applyColor" => color != :default
  )
end