module Coco module App module Blocks class SidebarNavItem < Coco::Component tag_name :a tag_attr :href renders_one :icon renders_one :menu renders_many :menu_items, ->(label, href, **kwargs) do data = {label: label, href: href, **kwargs} if menu_items.size < max_menu_items SidebarNavMenuItem.new(**data) else dropdown_menu_items << data nil end end renders_one :menu_action, ->(*args, **kwargs, &block) do tag.div class: "sidebar-nav-menu-item" do coco_button(*args, theme: :primary, size: :sm, fit: :full, **kwargs, &block) end end before_render do set_tag_attr(:id, item_id) if @icon && !icon? with_icon do tag.span(class: "nav-item-icon") do coco_icon(@icon, size: :full) end end end end attr_reader :label, :tooltip, :dropdown_menu_items, :max_menu_items, :item_id def initialize(label:, id: nil, icon: nil, emphasise: false, active: false, tooltip: nil, menu_select_placeholder: nil, max_menu_items: 6, **) @item_id = id @label = label @icon = icon @emphasise = emphasise @tooltip = tooltip @active = active @max_menu_items = max_menu_items @menu_select_placeholder = menu_select_placeholder @dropdown_menu_items = [] end def tooltip? tooltip.present? end def active? @active == true end def emphasise? @emphasise == true end def menu_select_placeholder @menu_select_placeholder || "More items..." end def menu_id "#{item_id}-menu" if item_id.present? end def menu_template_id "#{menu_id}-template" if menu_id.present? end class SidebarNavMenuItem < Coco::Component attr_reader :icon, :href, :modal def initialize(label:, href:, icon: nil, modal: nil, qualifier: nil, **) @label = label @href = href @icon = icon @modal = modal @qualifier = qualifier end def call coco_link(href, theme: nil, modal: modal, class: "sidebar-nav-menu-item") do label end end def label tag.span(@label, class: "sidebar-nav-menu-item-text") + qualifier end def qualifier if @icon || @qualifier tag.span(class: "sidebar-nav-menu-item-qualifier") do @icon ? coco_icon(icon, size: :sm) : @qualifier end end end end end end end end