Sha256: dcfe4c3cb169fa27b1025f5e573d9b45f73277e94941794de7b1b3cb69feffa2

Contents?: true

Size: 1.77 KB

Versions: 5

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

module Primer
  # Use the UnderlineNav component to style navigation with a minimal
  # underlined selected state, typically used for navigation placed at the top
  # of the page.
  class UnderlineNavComponent < Primer::Component
    ALIGN_DEFAULT = :left
    ALIGN_OPTIONS = [ALIGN_DEFAULT, :right].freeze

    with_content_areas :body, :actions

    # @example Default
    #   <%= render(Primer::UnderlineNavComponent.new) do |component| %>
    #     <% component.with(:body) do %>
    #       <%= render(Primer::LinkComponent.new(href: "#url")) { "Item 1" } %>
    #     <% end %>
    #     <% component.with(:actions) do %>
    #       <%= render(Primer::ButtonComponent.new) { "Button!" } %>
    #     <% end %>
    #   <% end %>
    #
    # @example Align right
    #   <%= render(Primer::UnderlineNavComponent.new(align: :right)) do |component| %>
    #     <% component.with(:body) do %>
    #       <%= render(Primer::LinkComponent.new(href: "#url")) { "Item 1" } %>
    #     <% end %>
    #     <% component.with(:actions) do %>
    #       <%= render(Primer::ButtonComponent.new) { "Button!" } %>
    #     <% end %>
    #   <% end %>
    #
    # @param align [Symbol] <%= one_of(Primer::UnderlineNavComponent::ALIGN_OPTIONS) %> - Defaults to <%= Primer::UnderlineNavComponent::ALIGN_DEFAULT %>
    # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
    def initialize(align: ALIGN_DEFAULT, **system_arguments)
      @align = fetch_or_fallback(ALIGN_OPTIONS, align, ALIGN_DEFAULT)

      @system_arguments = system_arguments
      @system_arguments[:tag] = :nav
      @system_arguments[:classes] = class_names(
        @system_arguments[:classes],
        "UnderlineNav",
        "UnderlineNav--right" => @align == :right
      )
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
primer_view_components-0.0.26 app/components/primer/underline_nav_component.rb
primer_view_components-0.0.25 app/components/primer/underline_nav_component.rb
primer_view_components-0.0.24 app/components/primer/underline_nav_component.rb
primer_view_components-0.0.23 app/components/primer/underline_nav_component.rb
primer_view_components-0.0.22 app/components/primer/underline_nav_component.rb