Class: Polaris::CardComponent

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

Constant Summary collapse

:right
{
  FOOTER_ACTION_ALIGNMENT_DEFAULT => "",
  :left => "Polaris-LegacyCard__LeftJustified"
}
FOOTER_ACTION_ALIGNMENT_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(title: "", actions: [], sectioned: true, subdued: false, borders: true, footer_action_alignment: FOOTER_ACTION_ALIGNMENT_DEFAULT, **system_arguments) ⇒ CardComponent

Returns a new instance of CardComponent.



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

def initialize(
  title: "",
  actions: [],
  sectioned: true,
  subdued: false,
  borders: true,
  footer_action_alignment: FOOTER_ACTION_ALIGNMENT_DEFAULT,
  **system_arguments
)
  @title = title
  @actions = actions
  @sectioned = sectioned
  @subdued = subdued
  @borders = borders
  @footer_action_alignment = footer_action_alignment
  @system_arguments = system_arguments
end

Instance Method Details



55
56
57
58
59
60
# File 'app/components/polaris/card_component.rb', line 55

def footer_classes
  class_names(
    "Polaris-LegacyCard__Footer",
    FOOTER_ACTION_ALIGNMENT_MAPPINGS[fetch_or_fallback(FOOTER_ACTION_ALIGNMENT_OPTIONS, @footer_action_alignment, FOOTER_ACTION_ALIGNMENT_DEFAULT)]
  )
end

#render_footer?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/components/polaris/card_component.rb', line 51

def render_footer?
  primary_footer_action.present? || secondary_footer_actions.any?
end

#system_argumentsObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/components/polaris/card_component.rb', line 38

def system_arguments
  @system_arguments.tap do |opts|
    opts[:tag] = :div
    opts[:classes] = class_names(
      opts[:classes],
      "Polaris-LegacyCard",
      "Polaris-LegacyCard--subdued": @subdued,
      "Polaris-LegacyCard--withoutTitle": @title.blank?,
      "Polaris-LegacyCard--borderless": !@borders
    )
  end
end