Sha256: c3f51a59f329fb436da7109fa044639efae1d7cd707c2a1893e270bbcb73bb1e

Contents?: true

Size: 1.36 KB

Versions: 23

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Primer
  # Use `CloseButton` to render an `×` without default button styles.
  #
  # @accessibility
  #   `CloseButton` has a default `aria-label` of "Close" to provides assistive technologies with an accessible label.
  #   You may choose to override this label with something more descriptive via [system_arguments][0].
  # [0]: https://primer.style/view-components/system-arguments#html-attributes
  class CloseButton < Primer::Component
    status :beta

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

    # @example Default
    #   <%= render(Primer::CloseButton.new) %>
    #
    # @param type [Symbol] <%= one_of(Primer::CloseButton::TYPE_OPTIONS) %>
    # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
    def initialize(type: DEFAULT_TYPE, **system_arguments)
      @system_arguments = system_arguments
      @system_arguments[:tag] = :button
      @system_arguments[:block] = false
      @system_arguments[:type] = fetch_or_fallback(TYPE_OPTIONS, type, DEFAULT_TYPE)
      @system_arguments[:classes] = class_names(
        "close-button",
        system_arguments[:classes]
      )
      @system_arguments[:"aria-label"] ||= "Close"
    end

    def call
      render(Primer::BaseButton.new(**@system_arguments)) do
        render(Primer::OcticonComponent.new("x"))
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

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