module Coco module App module Blocks module SidebarNav class Item < Coco::Component include Concerns::Extendable include Concerns::AcceptsOptions tag_attr :href component_name :app_sidebar_nav_item accepts_option :active, from: [true, false] accepts_option :emphasise, from: [true, false] renders_one :icon renders_one :menu before_render do if @icon && !icon? with_icon { coco_icon(@icon, size: :full) } end if link? && get_option_value(:active).nil? set_option_value(:active, helpers.current_page?(tag_attr(:href))) end end attr_reader :label def initialize(label:, icon: nil, **) @label = label @icon = icon end def link? tag_attr?(:href) && !menu? end def item_tag link? ? :a : :button end def menu_id "#{tag_attr(:id)}-menu" if tag_attr?(:id) end end end end end end