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]

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(url: nil, vertical_alignment: nil, 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.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/components/polaris/resource_item_component.rb', line 29

def initialize(
  url: nil,
  vertical_alignment: nil,
  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



66
67
68
69
70
71
72
73
74
75
# File 'app/components/polaris/resource_item_component.rb', line 66

def container_arguments
  @container_arguments.tap do |args|
    args[:classes] = class_names(
      args[:classes]
    )
    args[:position] = :relative
    args[:padding] = "3"
    args[:z_index] = "var(--pc-resource-item-content-stacking-order)"
  end
end

#owned?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'app/components/polaris/resource_item_component.rb', line 94

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

#system_argumentsObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/components/polaris/resource_item_component.rb', line 77

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



53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/components/polaris/resource_item_component.rb', line 53

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