Sha256: afbf60a88b0db3ee863ebb5da36cdd971b41e9469d0df9309999810c82c6f8d4

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Primer
  # Use AutoCompleteItem to list results of an auto-completed search.
  class AutoCompleteItemComponent < Primer::Component
    # @example Default
    #   <%= render(Primer::AutoCompleteItemComponent.new(selected: true, value: "value")) do |c| %>
    #     Selected
    #   <% end %>
    #   <%= render(Primer::AutoCompleteItemComponent.new(value: "value")) do |c| %>
    #     Not selected
    #   <% end %>
    #
    # @param value [String] Value of the item.
    # @param selected [Boolean] Whether the item is selected.
    # @param disabled [Boolean] Whether the item is disabled.
    # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
    def initialize(value:, selected: false, disabled: false, **system_arguments)
      @system_arguments = system_arguments
      @system_arguments[:tag] = :li
      @system_arguments[:role] = :option
      @system_arguments[:"data-autocomplete-value"] = value

      @system_arguments[:"aria-selected"] = true if selected
      @system_arguments[:"aria-disabled"] = true if disabled

      @system_arguments[:classes] = class_names(
        "autocomplete-item",
        system_arguments[:classes],
        "disabled" => disabled
      )
    end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
primer_view_components-0.0.34 app/components/primer/auto_complete_item_component.rb
primer_view_components-0.0.33 app/components/primer/auto_complete_item_component.rb
primer_view_components-0.0.32 app/components/primer/auto_complete_item_component.rb