Class: Polaris::ResourceItemComponent

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

Constant Summary collapse

CURSOR_DEFAULT =
:default
CURSOR_OPTIONS =
%i[default pointer]
ALIGNMENT_DEFAULT =
:default
ALIGNMENT_MAPPINGS =
{
  ALIGNMENT_DEFAULT => "",
  :center => "Polaris-ResourceItem--alignmentCenter"
}
ALIGNMENT_OPTIONS =
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_icon_source, #polaris_inversed_colors

Methods included from OptionHelper

#append_option, #prepend_option

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(url: nil, vertical_alignment: ALIGNMENT_DEFAULT, cursor: CURSOR_DEFAULT, selectable: false, selected: false, persist_actions: false, offset: false, wrapper_arguments: {}, container_arguments: {}, **system_arguments) ⇒ ResourceItemComponent

Returns a new instance of ResourceItemComponent.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/components/polaris/resource_item_component.rb', line 36

def initialize(
  url: nil,
  vertical_alignment: ALIGNMENT_DEFAULT,
  cursor: CURSOR_DEFAULT,
  selectable: false,
  selected: false,
  persist_actions: false,
  offset: false,
  wrapper_arguments: {},
  container_arguments: {},
  **system_arguments
)
  @url = url
  @vertical_alignment = vertical_alignment
  @cursor = fetch_or_fallback(CURSOR_OPTIONS, cursor, CURSOR_DEFAULT)
  @selectable = selectable
  @selected = selected
  @persist_actions = persist_actions
  @offset = offset
  @wrapper_arguments = wrapper_arguments
  @container_arguments = container_arguments
  @system_arguments = system_arguments
end

Instance Method Details

#container_argumentsObject



73
74
75
76
77
78
79
80
81
82
83
# File 'app/components/polaris/resource_item_component.rb', line 73

def container_arguments
  {
    tag: "div"
  }.deep_merge(@container_arguments).tap do |args|
    args[:classes] = class_names(
      args[:classes],
      "Polaris-ResourceItem__Container",
      ALIGNMENT_MAPPINGS[fetch_or_fallback(ALIGNMENT_OPTIONS, @vertical_alignment, ALIGNMENT_DEFAULT)]
    )
  end
end

#owned?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'app/components/polaris/resource_item_component.rb', line 102

def owned?
  checkbox.present? || radio_button.present? || media.present?
end

#owned_argumentsObject



106
107
108
109
110
111
112
113
114
115
# File 'app/components/polaris/resource_item_component.rb', line 106

def owned_arguments
  {
    tag: "div",
    classes: class_names(
      "Polaris-ResourceItem__Owned",
      "Polaris-ResourceItem__OwnedNoMedia": media.blank?,
      "Polaris-ResourceItem__Owned--offset": @offset
    )
  }
end

#system_argumentsObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/components/polaris/resource_item_component.rb', line 85

def system_arguments
  {
    tag: "div",
    data: {}
  }.deep_merge(@system_arguments).tap do |args|
    args[:classes] = class_names(
      args[:classes],
      "Polaris-ResourceItem",
      "Polaris-ResourceItem--selectable": @selectable,
      "Polaris-ResourceItem--selected": @selected,
      "Polaris-ResourceItem--persistActions": @persist_actions
    )
    prepend_option(args, :style, "cursor: #{@cursor};")
    prepend_option(args[:data], :action, "click->polaris-resource-item#open")
  end
end

#wrapper_argumentsObject



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

def wrapper_arguments
  {
    tag: "li",
    data: {}
  }.deep_merge(@wrapper_arguments).tap do |args|
    args[:classes] = class_names(
      args[:classes],
      "Polaris-ResourceItem__ListItem"
    )
    prepend_option(args[:data], :controller, "polaris-resource-item")
  end
end