Sha256: 8b644e05c00ce5615cd7fe5dd7ed0387b8a40ee48524887d02b9577690aafba3

Contents?: true

Size: 896 Bytes

Versions: 1

Compression:

Stored size: 896 Bytes

Contents

module Lookbook
  class Nav::Item::Component < Lookbook::BaseComponent
    delegate :label, :depth, 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 - 1) * 12) + 24
    end

    def children
      @children ||= node.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

1 entries across 1 versions & 1 rubygems

Version Path
lookbook-1.4.0 app/components/lookbook/nav/item/component.rb