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