Sha256: 139af9683b8c93950948842de84bf4d105b2166b380a25ec1e5329c0e97c1026

Contents?: true

Size: 950 Bytes

Versions: 4

Compression:

Stored size: 950 Bytes

Contents

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

    def nav_icon
      ICONS[collapsed? ? :preview : node.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? ? :scenario : 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

4 entries across 4 versions & 1 rubygems

Version Path
lookbook-2.0.0.beta.3 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.0.beta.2 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.0.beta.1 app/components/lookbook/nav/entity/component.rb
lookbook-2.0.0.beta.0 app/components/lookbook/nav/entity/component.rb