Sha256: 3c3dbf233ef80035f4677c17008a329ca84ce99eeb2eea47cf35252e2dd40056

Contents?: true

Size: 1.53 KB

Versions: 39

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module Primer
  module Beta
    # 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::Beta::BaseButton.new(block: :true)) { "Block" } %>
      #   <%= render(Primer::Beta::BaseButton.new(block: :true, scheme: :primary)) { "Primary block" } %>
      #
      # @param tag [Symbol] <%= one_of(Primer::Beta::BaseButton::TAG_OPTIONS) %>
      # @param type [Symbol] <%= one_of(Primer::Beta::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
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
primer_view_components-0.1.9 app/components/primer/beta/base_button.rb
primer_view_components-0.1.8 app/components/primer/beta/base_button.rb
primer_view_components-0.1.7 app/components/primer/beta/base_button.rb
primer_view_components-0.1.6 app/components/primer/beta/base_button.rb
primer_view_components-0.1.5 app/components/primer/beta/base_button.rb
primer_view_components-0.1.4 app/components/primer/beta/base_button.rb
primer_view_components-0.1.3 app/components/primer/beta/base_button.rb
primer_view_components-0.1.2 app/components/primer/beta/base_button.rb
primer_view_components-0.1.1 app/components/primer/beta/base_button.rb
primer_view_components-0.1.0 app/components/primer/beta/base_button.rb
primer_view_components-0.0.123 app/components/primer/beta/base_button.rb
primer_view_components-0.0.122 app/components/primer/beta/base_button.rb
primer_view_components-0.0.121 app/components/primer/beta/base_button.rb
primer_view_components-0.0.120 app/components/primer/beta/base_button.rb
primer_view_components-0.0.119 app/components/primer/beta/base_button.rb
primer_view_components-0.0.118 app/components/primer/beta/base_button.rb
primer_view_components-0.0.117 app/components/primer/beta/base_button.rb
primer_view_components-0.0.116 app/components/primer/beta/base_button.rb
primer_view_components-0.0.114 app/components/primer/beta/base_button.rb
primer_view_components-0.0.113 app/components/primer/beta/base_button.rb