Sha256: c7da05a356349181dd60fe75d89ad2117387a3003a9ab677d841e584387b7638

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Primer
  # Use AutoCompleteItem to list results of an auto-completed search.
  class AutoCompleteItemComponent < Primer::Component
    include ViewComponent::SlotableV2

    # @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

4 entries across 4 versions & 1 rubygems

Version Path
primer_view_components-0.0.31 app/components/primer/auto_complete_item_component.rb
primer_view_components-0.0.30 app/components/primer/auto_complete_item_component.rb
primer_view_components-0.0.29 app/components/primer/auto_complete_item_component.rb
primer_view_components-0.0.28 app/components/primer/auto_complete_item_component.rb