Sha256: 58548a9517dd6c31d2ed520ae3feb3f23854708d2eff424774280df0e89e21eb

Contents?: true

Size: 1.24 KB

Versions: 172

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require_relative "base"

module ERBLint
  module Linters
    module ArgumentMappers
      # Maps classes in a close-button element to arguments for the CloseButton component.
      class CloseButton < Base
        ATTRIBUTES = %w[type].freeze

        TYPE_OPTIONS = Primer::ViewComponents::Constants.get(
          component: "Primer::Beta::CloseButton",
          constant: "TYPE_OPTIONS"
        ).freeze

        DEFAULT_TYPE = Primer::ViewComponents::Constants.get(
          component: "Primer::Beta::CloseButton",
          constant: "DEFAULT_TYPE"
        ).freeze

        DEFAULT_CLASS = "close-button"

        def attribute_to_args(attribute)
          # button is the default type, so we don't need to do anything.
          return {} if attribute.value == DEFAULT_TYPE

          raise ConversionError, "CloseButton component does not support type \"#{attribute.value}\"" unless TYPE_OPTIONS.include?(attribute.value)

          { type: ":#{attribute.value}" }
        end

        def classes_to_args(classes)
          classes.each_with_object({ classes: [] }) do |class_name, acc|
            next if class_name == DEFAULT_CLASS

            acc[:classes] << class_name
          end
        end
      end
    end
  end
end

Version data entries

172 entries across 172 versions & 2 rubygems

Version Path
primer_view_components-0.36.5 lib/primer/view_components/linters/argument_mappers/close_button.rb
openproject-primer_view_components-0.52.2 lib/primer/view_components/linters/argument_mappers/close_button.rb
primer_view_components-0.36.4 lib/primer/view_components/linters/argument_mappers/close_button.rb
openproject-primer_view_components-0.52.1 lib/primer/view_components/linters/argument_mappers/close_button.rb
openproject-primer_view_components-0.52.0 lib/primer/view_components/linters/argument_mappers/close_button.rb
primer_view_components-0.36.3 lib/primer/view_components/linters/argument_mappers/close_button.rb
openproject-primer_view_components-0.51.0 lib/primer/view_components/linters/argument_mappers/close_button.rb
primer_view_components-0.36.2 lib/primer/view_components/linters/argument_mappers/close_button.rb
openproject-primer_view_components-0.50.1 lib/primer/view_components/linters/argument_mappers/close_button.rb
openproject-primer_view_components-0.50.0 lib/primer/view_components/linters/argument_mappers/close_button.rb
primer_view_components-0.36.1 lib/primer/view_components/linters/argument_mappers/close_button.rb
primer_view_components-0.36.0 lib/primer/view_components/linters/argument_mappers/close_button.rb
openproject-primer_view_components-0.49.2 lib/primer/view_components/linters/argument_mappers/close_button.rb
primer_view_components-0.35.2 lib/primer/view_components/linters/argument_mappers/close_button.rb
openproject-primer_view_components-0.49.1 lib/primer/view_components/linters/argument_mappers/close_button.rb
openproject-primer_view_components-0.49.0 lib/primer/view_components/linters/argument_mappers/close_button.rb
primer_view_components-0.35.1 lib/primer/view_components/linters/argument_mappers/close_button.rb
primer_view_components-0.35.0 lib/primer/view_components/linters/argument_mappers/close_button.rb
openproject-primer_view_components-0.48.2 lib/primer/view_components/linters/argument_mappers/close_button.rb
openproject-primer_view_components-0.48.1 lib/primer/view_components/linters/argument_mappers/close_button.rb