Sha256: cfe807ba487df189e1d06ae3c91d23c7962a94f99a2907a14a6339b427864ba9

Contents?: true

Size: 1.89 KB

Versions: 95

Compression:

Stored size: 1.89 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, :"clipboard-copy"].freeze

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

      attr_reader :disabled
      alias disabled? disabled

      # @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 disabled [Boolean] Whether or not the button is disabled. If true, this option forces `tag:` to `:button`.
      # @param inactive [Boolean] Whether the button looks visually disabled, but can still accept all the same interactions as an enabled button.
      # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
      def initialize(
        tag: DEFAULT_TAG,
        type: DEFAULT_TYPE,
        block: false,
        disabled: false,
        inactive: 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,
          "Button--inactive" => inactive
        )

        @disabled = disabled
        return unless @disabled

        @system_arguments[:tag] = :button
        @system_arguments[:disabled] = ""
      end

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

Version data entries

95 entries across 95 versions & 2 rubygems

Version Path
primer_view_components-0.36.5 app/components/primer/beta/base_button.rb
openproject-primer_view_components-0.52.2 app/components/primer/beta/base_button.rb
primer_view_components-0.36.4 app/components/primer/beta/base_button.rb
openproject-primer_view_components-0.52.1 app/components/primer/beta/base_button.rb
openproject-primer_view_components-0.52.0 app/components/primer/beta/base_button.rb
primer_view_components-0.36.3 app/components/primer/beta/base_button.rb
openproject-primer_view_components-0.51.0 app/components/primer/beta/base_button.rb
primer_view_components-0.36.2 app/components/primer/beta/base_button.rb
openproject-primer_view_components-0.50.1 app/components/primer/beta/base_button.rb
openproject-primer_view_components-0.50.0 app/components/primer/beta/base_button.rb
primer_view_components-0.36.1 app/components/primer/beta/base_button.rb
primer_view_components-0.36.0 app/components/primer/beta/base_button.rb
openproject-primer_view_components-0.49.2 app/components/primer/beta/base_button.rb
primer_view_components-0.35.2 app/components/primer/beta/base_button.rb
openproject-primer_view_components-0.49.1 app/components/primer/beta/base_button.rb
openproject-primer_view_components-0.49.0 app/components/primer/beta/base_button.rb
primer_view_components-0.35.1 app/components/primer/beta/base_button.rb
primer_view_components-0.35.0 app/components/primer/beta/base_button.rb
openproject-primer_view_components-0.48.2 app/components/primer/beta/base_button.rb
openproject-primer_view_components-0.48.1 app/components/primer/beta/base_button.rb