Sha256: 6ba0cd02f00bde98938997b790020c022d9a6ccb960a2c960e288e003e72f2f9

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

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

Version data entries

5 entries across 5 versions & 1 rubygems

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