Sha256: d5a8e8290653deec70b662aff07439e42e1ae66ffb1e32d401a2685d43a3e621

Contents?: true

Size: 1.38 KB

Versions: 24

Compression:

Stored size: 1.38 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 = deny_tag_argument(**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

24 entries across 24 versions & 1 rubygems

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