Sha256: 359fd46355e52f36c5c83472b8ba9e02894e8f5964b1c2eed801ead914bed962

Contents?: true

Size: 1.49 KB

Versions: 22

Compression:

Stored size: 1.49 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)

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

      @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

22 entries across 22 versions & 1 rubygems

Version Path
primer_view_components-0.0.60 app/components/primer/base_button.rb
primer_view_components-0.0.59 app/components/primer/base_button.rb
primer_view_components-0.0.58 app/components/primer/base_button.rb
primer_view_components-0.0.57 app/components/primer/base_button.rb
primer_view_components-0.0.56 app/components/primer/base_button.rb
primer_view_components-0.0.55 app/components/primer/base_button.rb
primer_view_components-0.0.54 app/components/primer/base_button.rb
primer_view_components-0.0.53 app/components/primer/base_button.rb
primer_view_components-0.0.52 app/components/primer/base_button.rb
primer_view_components-0.0.51 app/components/primer/base_button.rb
primer_view_components-0.0.50 app/components/primer/base_button.rb
primer_view_components-0.0.49 app/components/primer/base_button.rb
primer_view_components-0.0.48 app/components/primer/base_button.rb
primer_view_components-0.0.47 app/components/primer/base_button.rb
primer_view_components-0.0.46 app/components/primer/base_button.rb
primer_view_components-0.0.45 app/components/primer/base_button.rb
primer_view_components-0.0.44 app/components/primer/base_button.rb
primer_view_components-0.0.43 app/components/primer/base_button.rb
primer_view_components-0.0.42 app/components/primer/base_button.rb
primer_view_components-0.0.41 app/components/primer/base_button.rb