Sha256: 1dc61f326b2793af1a0255f02941b64d21ac4d22ef851538ebcff3e6a7e4f071
Contents?: true
Size: 1.69 KB
Versions: 11
Compression:
Stored size: 1.69 KB
Contents
module Lookbook class Nav::Item::Component < Lookbook::BaseComponent ICONS = { page: :file, page_collection: :folder, preview_collection: :folder, preview: :layers, example: :eye, group: :eye, collection: :folder }.freeze delegate :label, to: :@item def initialize( item, nav_id:, depth: 1, collapse_singles: false, **html_attrs ) @nav_id = nav_id @item = item @depth = depth @collapse_singles = collapse_singles super(**html_attrs) end def id "#{@nav_id}-#{@item.id}" end def left_pad ((@depth - 1) * 12) + 24 end def href if collapsed? item.url_path elsif !collection? item.url_path end end def children @children ||= if collection? && !collapsed? item.non_empty_items.map do |item| render Lookbook::Nav::Item::Component.new item, nav_id: @nav_id, depth: (@depth + 1), collapse_singles: @collapse_singles end else [] end end def item collapsed? ? @item.first : @item end def nav_icon ICONS[@item.type] || :file end def collection? @item.is_a? Lookbook::Collection end def children? children.any? if collection? && !collapsed? end def collapsed? @collapse_singles == true && collection? && @item.collapsible? && @item.one? end protected def alpine_data { id: @item.id, matchers: item.is_a?(Lookbook::Collection) ? nil : item.matchers }.to_json end def alpine_component "navItemComponent" end end end
Version data entries
11 entries across 11 versions & 1 rubygems