Sha256: 8fbe5f4760a41a4d23bb4789bf543696316c0bd0349490a03034681719fb6384

Contents?: true

Size: 919 Bytes

Versions: 1

Compression:

Stored size: 919 Bytes

Contents

module Lookbook
  class Nav::Entity::Component < Nav::Item::Component
    ICONS = {
      page: :file,
      preview: :layers,
      example: :eye,
      group: :eye
    }.freeze

    def nav_icon
      ICONS[type] || :file
    end

    def href
      if collapsed?
        node.first.url_path
      elsif type != :preview
        node.url_path
      end
    end

    def children
      collapsed? ? [] : super
    end

    def type
      collapsed? ? :example : node.type
    end

    def collapsed?
      node.type == :preview && node.children.one?
    end

    def search_terms
      matchers = if collapsed?
        node.first.search_terms
      else
        node.respond_to?(:search_terms) ? Array(node.search_terms) : []
      end
      matchers.flatten.map { |m| m.gsub(/\s/, "").downcase }
    end

    protected

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

Version data entries

1 entries across 1 versions & 1 rubygems

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