module Coco module App module SidebarNav class Menu < Coco::Component component_name :app_sidebar_nav_menu renders_many :items, types: { link: ->(label, href, qualifier: nil, **kwargs, &block) do if items.size < max_links coco_link(href, **kwargs, theme: nil, underline: false) do tag.span(label, class: "menu-item-label") + tag.span(qualifier, class: "menu-item-qualifier") end else overflow_items << ["#{label}#{qualifier.present? ? " (#{qualifier})" : ""}", href] nil end end, block_link: ->(href, **kwargs, &block) do coco_link(href, **kwargs, theme: nil, underline: false, &block) end } renders_one :action, ->(*args, **kwargs, &block) do coco_button(*args, theme: :primary, **kwargs, size: :sm, fit: :full, &block) end attr_reader :max_links, :overflow_items, :prompt def initialize(max_links: 6, prompt: "More links...", **kwargs) @max_links = max_links @prompt = prompt @overflow_items = [] end def with_link(...) with_item_link(...) end def with_block_link(...) with_item_block_link(...) end end end end end