Sha256: cc6817c1da1f8fb69ab858a56c10527d96005340040a1cc7b45140c16eae23fb

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

module Coco
  module App
    module SidebarNav
      class Navbar < Coco::Component
        include Coco::AppComponentsHelper

        tag_name :nav
        component_name :app_sidebar_nav

        renders_many :actions, ->(label, href, icon:, **kwargs) do
          actions_data << {label: label, href: href, icon: icon, **kwargs}
        end

        renders_many :items, types: {
          link: ->(label, href, show_on_mobile: true, **kwargs, &block) do
            nav_item(mobile: show_on_mobile) do
              render Coco::App::SidebarNav::Item.new(label: label, href: href, **kwargs), &block
            end
          end,
          menu: ->(label, show_on_mobile: true, **kwargs, &block) do
            nav_item(mobile: show_on_mobile) do
              render Coco::App::SidebarNav::Item.new(label: label, **kwargs) do |item|
                item.with_menu(&block)
              end
            end
          end
        }

        attr_reader :actions_data

        def initialize(**)
          @actions_data = []
          @menus_data = {}
        end

        def nav_item(mobile: true, &block)
          tag.div(class: "nav-item", data: {show_on_mobile: mobile.to_s}, &block)
        end

        def with_link(...)
          with_item_link(...)
        end

        def with_menu(...)
          with_item_menu(...)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
coveragebook_components-0.16.0 app/components/coco/app/sidebar_nav/navbar/navbar.rb
coveragebook_components-0.15.0 app/components/coco/app/sidebar_nav/navbar/navbar.rb
coveragebook_components-0.14.0 app/components/coco/app/sidebar_nav/navbar/navbar.rb
coveragebook_components-0.13.1 app/components/coco/app/sidebar_nav/navbar/navbar.rb
coveragebook_components-0.13.0 app/components/coco/app/sidebar_nav/navbar/navbar.rb