Class: MenuItemComponent

Inherits:
Component show all
Includes:
Positionable
Defined in:
app/components/menu_item_component.rb

Overview

MenuItem — individual item within a Menu or Sidebar.

Usage:

Menu {
  MenuItem(href: "/") { text "Home" }
  MenuItem(active: true) { text "Current" }
  MenuItem(header: true) { text "Section Header" }
  MenuItem(icon: "settings") { text "Settings" }
}

Constant Summary

Constants inherited from Component

Component::HTML_OPTIONS

Instance Method Summary collapse

Methods inherited from Component

default, #initialize, #render_in, slot

Constructor Details

This class inherits a constructor from Component

Instance Method Details

#to_sObject



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

def to_s
  classes = class_names(
    { "ui simple" => dropdown },
    color,
    fitted && (fitted == "true" ? "fitted" : "#{fitted} fitted"),
    position,
    { "active" => active,
      "disabled" => disabled,
      "header" => header,
      "link" => link,
      "dropdown" => dropdown },
    "item"
  )

  icon_el = icon ? tag.i(class: "#{icon} icon") : nil
  inner = icon_el ? safe_join([ icon_el, @content ]) : @content

  opts = merge_html_options(class: classes)
  opts["data-value"] = value if value
  opts[:target] = target if target
  opts[:rel] = rel if rel

  if href
    tag.a(**opts, href: href) { inner }
  else
    tag.div(**opts) { inner }
  end
end