Sha256: ee9b99d24ee0c0aee7d5a70f5d02235ae2974091a69699adc93486fc12090ae1

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

module Optics
  module Sidebar
    class Component < ApplicationViewComponent
      VARIANTS = %w[drawer compact rail].freeze

      renders_one :brand, 'Brand'
      renders_many :sidebar_contents, 'SidebarContent'

      accepts :responsive, default: false
      accepts :variant, default: 'drawer'

      def call
        content_tag(
          :nav,
          class: classes
        ) do
          capture do
            concat brand
            sidebar_contents.each do |content|
              concat content
            end
          end
        end
      end

      def classes
        class_names(
          'sidebar',
          variant_class,
          @attributes[:class],
          'sidebar--responsive': responsive
        ).join(' ')
      end

      def variant_class
        "sidebar--#{variant}"
      end

      class Brand < ApplicationViewComponent
        accepts :url
        accepts :img_src
        accepts :name

        def call
          link_to(url, class: 'sidebar__brand') do
            name || image_tag(img_src)
          end
        end
      end

      class SidebarContent < ApplicationViewComponent
        accepts :position, default: 'center'

        def call
          content_tag(:div, class: classes) do
            content
          end
        end

        def classes
          class_names(
            'sidebar__content',
            position_class
          ).join(' ')
        end

        def position_class
          "sidebar__content--#{position}"
        end
      end

      class LinksComponent < ApplicationViewComponent
        accepts :img_src
        accepts :url

        def call
          link_to(url, class: 'sidebar__brand') do
            image_tag(img_src)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
optics_view_components-0.1.8 app/components/optics/sidebar/component.rb