Sha256: 659801cb60f6c8608de5fda80fda65548ec7b8770341f63eefc6115bec83efd8

Contents?: true

Size: 1.42 KB

Versions: 25

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Primer
  # Use `BaseButton` to render an unstyled `<button>` tag that can be customized.
  class BaseButton < Primer::Component
    status :beta

    DEFAULT_TAG = :button
    TAG_OPTIONS = [DEFAULT_TAG, :a, :summary].freeze

    DEFAULT_TYPE = :button
    TYPE_OPTIONS = [DEFAULT_TYPE, :reset, :submit].freeze

    # @example Block
    #   <%= render(Primer::BaseButton.new(block: :true)) { "Block" } %>
    #   <%= render(Primer::BaseButton.new(block: :true, scheme: :primary)) { "Primary block" } %>
    #
    # @param tag [Symbol] <%= one_of(Primer::BaseButton::TAG_OPTIONS) %>
    # @param type [Symbol] <%= one_of(Primer::BaseButton::TYPE_OPTIONS) %>
    # @param block [Boolean] Whether button is full-width with `display: block`.
    # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
    def initialize(
      tag: DEFAULT_TAG,
      type: DEFAULT_TYPE,
      block: false,
      **system_arguments
    )
      @system_arguments = system_arguments
      @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)

      @system_arguments[:type] = fetch_or_fallback(TYPE_OPTIONS, type, DEFAULT_TYPE) if @system_arguments[:tag] == :button

      @system_arguments[:classes] = class_names(
        system_arguments[:classes],
        "btn-block" => block
      )
    end

    def call
      render(Primer::BaseComponent.new(**@system_arguments)) { content }
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
primer_view_components-0.0.85 app/components/primer/base_button.rb
primer_view_components-0.0.84 app/components/primer/base_button.rb
primer_view_components-0.0.83 app/components/primer/base_button.rb
primer_view_components-0.0.82 app/components/primer/base_button.rb
primer_view_components-0.0.81 app/components/primer/base_button.rb
primer_view_components-0.0.80 app/components/primer/base_button.rb
primer_view_components-0.0.79 app/components/primer/base_button.rb
primer_view_components-0.0.78 app/components/primer/base_button.rb
primer_view_components-0.0.77 app/components/primer/base_button.rb
primer_view_components-0.0.76 app/components/primer/base_button.rb
primer_view_components-0.0.75 app/components/primer/base_button.rb
primer_view_components-0.0.74 app/components/primer/base_button.rb
primer_view_components-0.0.73 app/components/primer/base_button.rb
primer_view_components-0.0.72 app/components/primer/base_button.rb
primer_view_components-0.0.71 app/components/primer/base_button.rb
primer_view_components-0.0.70 app/components/primer/base_button.rb
primer_view_components-0.0.69 app/components/primer/base_button.rb
primer_view_components-0.0.68 app/components/primer/base_button.rb
primer_view_components-0.0.67 app/components/primer/base_button.rb
primer_view_components-0.0.66 app/components/primer/base_button.rb