Class: Polaris::Navigation::ItemComponent

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

Defined Under Namespace

Classes: SecondaryActionComponent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, label:, icon: nil, badge: nil, selected: false, disabled: false, external: false, action_type: :link, link_arguments: {}, **system_arguments) ⇒ ItemComponent

Returns a new instance of ItemComponent.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/components/polaris/navigation/item_component.rb', line 7

def initialize(
  url:,
  label:,
  icon: nil,
  badge: nil,
  selected: false,
  disabled: false,
  external: false,
  action_type: :link,
  link_arguments: {},
  **system_arguments
)
  @url = url
  @label = label
  @icon = icon
  @badge = badge
  @selected = selected
  @disabled = disabled
  @external = external
  @system_arguments = system_arguments
  @action_type = action_type
  @link_arguments = link_arguments
  @item_inner_wrapper_classes = item_inner_wrapper_classes
end

Instance Attribute Details

#selectedObject (readonly)

Returns the value of attribute selected.



5
6
7
# File 'app/components/polaris/navigation/item_component.rb', line 5

def selected
  @selected
end

Instance Method Details

#item_inner_wrapper_classesObject



53
54
55
56
57
58
59
# File 'app/components/polaris/navigation/item_component.rb', line 53

def item_inner_wrapper_classes
  class_names(
    "Polaris-Navigation__ItemInnerWrapper",
    "Polaris-Navigation__ItemInnerWrapper--selected": @selected,
    "Polaris-Navigation__ItemInnerDisabled": @disabled
  )
end


42
43
44
45
46
47
48
49
50
51
# File 'app/components/polaris/navigation/item_component.rb', line 42

def link_arguments
  @link_arguments.tap do |opts|
    opts[:class] = class_names(
      @link_arguments[:classes],
      link_classes
    )
    opts[:tabindex] = "0"
    opts[:target] = "_blank" if @external
  end
end


61
62
63
64
65
66
67
68
# File 'app/components/polaris/navigation/item_component.rb', line 61

def link_classes
  class_names(
    "Polaris-Navigation__Item",
    "Polaris-Navigation__Item--selected": @selected,
    "Polaris-Navigation--subNavigationActive": @selected || selected_sub_items?,
    "Polaris-Navigation__Item--disabled": @disabled
  )
end

#selected_sub_items?Boolean

Returns:

  • (Boolean)


70
71
72
73
74
# File 'app/components/polaris/navigation/item_component.rb', line 70

def selected_sub_items?
  return unless sub_items.present?

  sub_items.any?(&:selected)
end

#system_argumentsObject



32
33
34
35
36
37
38
39
40
# File 'app/components/polaris/navigation/item_component.rb', line 32

def system_arguments
  @system_arguments.tap do |opts|
    opts[:tag] = "li"
    opts[:classes] = class_names(
      @system_arguments[:classes],
      "Polaris-Navigation__ListItem"
    )
  end
end