Sha256: 02e4c6665f45713aafda1baf32dc6d93c24dd828b999e69b3afc4ee93fbe9b50

Contents?: true

Size: 899 Bytes

Versions: 28

Compression:

Stored size: 899 Bytes

Contents

module Lookbook
  class Nav::Item::Component < Lookbook::BaseComponent
    delegate :label, :depth, :priority, to: :node

    attr_reader :node, :nav_id

    def initialize(node, nav_id:, **html_attrs)
      @node = node
      @nav_id = nav_id
      super(**html_attrs)
    end

    def id
      "#{nav_id}-#{node.id}"
    end

    def left_pad
      depth * 12
    end

    def children
      @children ||= node.sort.map { |node| render_item(node) }
    end

    def nav_icon
      :folder
    end

    def children?
      children.any?
    end

    def render_item(node)
      item_class = (node.type == :directory) ? Nav::Directory::Component : Nav::Entity::Component
      lookbook_render item_class.new node, nav_id: nav_id
    end

    protected

    def alpine_data
      alpine_encode({id: node.id, matchers: []})
    end

    def alpine_component
      "navItemComponent"
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
lookbook-2.3.4 app/components/lookbook/nav/item/component.rb
lookbook-2.3.3 app/components/lookbook/nav/item/component.rb
lookbook-2.3.2 app/components/lookbook/nav/item/component.rb
lookbook-2.3.0 app/components/lookbook/nav/item/component.rb
lookbook-2.2.2 app/components/lookbook/nav/item/component.rb
lookbook-2.2.1 app/components/lookbook/nav/item/component.rb
lookbook-2.2.0 app/components/lookbook/nav/item/component.rb
lookbook-2.1.1 app/components/lookbook/nav/item/component.rb
lookbook-2.1.0 app/components/lookbook/nav/item/component.rb
lookbook-2.0.5 app/components/lookbook/nav/item/component.rb
lookbook-2.0.4 app/components/lookbook/nav/item/component.rb
lookbook-2.0.3 app/components/lookbook/nav/item/component.rb
lookbook-2.0.2 app/components/lookbook/nav/item/component.rb
lookbook-2.0.1 app/components/lookbook/nav/item/component.rb
lookbook-2.0.0 app/components/lookbook/nav/item/component.rb
lookbook-2.0.0.rc.3 app/components/lookbook/nav/item/component.rb
lookbook-2.0.0.rc.2 app/components/lookbook/nav/item/component.rb
lookbook-2.0.0.rc.1 app/components/lookbook/nav/item/component.rb
lookbook-2.0.0.beta.9 app/components/lookbook/nav/item/component.rb
lookbook-2.0.0.beta.8 app/components/lookbook/nav/item/component.rb