Sha256: 426d54762fb2096c7dbd1bfeb4fe43dd523de0c217ca56ad751b701318a50bb4

Contents?: true

Size: 1.75 KB

Versions: 4

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

module Primer
  module Beta
    class BorderBox
      # `BorderBox::Header` is used inside `BorderBox` to render its header slot.
      #
      # @accessibility When using `header.title`, set `tag` to one of `h1`, `h2`, `h3`, etc. based on what is appropriate for the page context. <%= link_to_heading_practices %>
      class Header < Primer::Component
        TITLE_TAG_FALLBACK = :h2
        TITLE_TAG_OPTIONS = [:h1, TITLE_TAG_FALLBACK, :h3, :h4, :h5, :h6].freeze

        # Optional Title.
        #
        # @param tag [Symbol] <%= one_of(Primer::Beta::BorderBox::Header::TITLE_TAG_OPTIONS) %>
        # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
        renders_one :title, lambda { |tag:, **system_arguments|
          system_arguments[:tag] = fetch_or_fallback(TITLE_TAG_OPTIONS, tag, TITLE_TAG_FALLBACK)
          system_arguments[:classes] = class_names(
            "Box-title",
            system_arguments[:classes]
          )

          Primer::BaseComponent.new(**system_arguments)
        }

        # @example Default
        #
        #   <%= render(Primer::Beta::BorderBox::Header.new) do %>
        #     Header
        #   <% end %>
        #
        # @example with title
        #   <%= render(Primer::Beta::BorderBox::Header.new) do |h| %>
        #     <% h.title(tag: :h3) do %>I am a title<% end %>
        #   <% end %>
        #
        # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
        def initialize(**system_arguments)
          @system_arguments = system_arguments
          @system_arguments[:tag] = :div
          @system_arguments[:classes] = class_names(
            "Box-header",
            system_arguments[:classes]
          )
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
primer_view_components-0.0.89 app/components/primer/beta/border_box/header.rb
primer_view_components-0.0.88 app/components/primer/beta/border_box/header.rb
primer_view_components-0.0.87 app/components/primer/beta/border_box/header.rb
primer_view_components-0.0.86 app/components/primer/beta/border_box/header.rb