Sha256: 3e2068ccc6d1b501677df7c59dd58dab612dbbe925d28faf97ccc7731effb4d6

Contents?: true

Size: 1.44 KB

Versions: 17

Compression:

Stored size: 1.44 KB

Contents

module Coco
  module App
    module Blocks
      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
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
coveragebook_components-0.12.2 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.12.1 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.12.0 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.11.0 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.10.1.beta.2 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.10.1.beta.1 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.10.1.beta.0 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.10.0 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.9.1 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.9.0 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.8.9 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.8.8 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.8.7 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.8.6 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.8.5 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.8.4 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb
coveragebook_components-0.8.3 app/components/coco/app/blocks/sidebar_nav/menu/menu.rb