Sha256: a696b128ea1be1eb154ea89a90b5f4e09705cdb8eab297a6590e22d4cfbd54bf

Contents?: true

Size: 1.12 KB

Versions: 17

Compression:

Stored size: 1.12 KB

Contents

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

Version data entries

17 entries across 17 versions & 1 rubygems

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