Sha256: 343e33f436c77c39154c7bb9c3ffb39ecdc3646b6aca8db61a9eeaeb24a61858

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Primer
  class AutoComplete
    # Use AutoCompleteItem to list results of an auto-completed search.
    class Item < Primer::Component
      status :beta

      # @example Default
      #   <%= render(Primer::AutoComplete::Item.new(selected: true, value: "value")) do |c| %>
      #     Selected
      #   <% end %>
      #   <%= render(Primer::AutoComplete::Item.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
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
primer_view_components-0.0.38 app/components/primer/auto_complete/item.rb
primer_view_components-0.0.37 app/components/primer/auto_complete/item.rb
primer_view_components-0.0.36 app/components/primer/auto_complete/item.rb