Sha256: 2c9c2ab2ae5c12682deb742bcd8475cd7afc6861f903a7f7ab280f9fa3688641

Contents?: true

Size: 1.5 KB

Versions: 15

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

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

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
primer_view_components-0.0.61 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.60 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.59 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.58 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.57 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.56 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.55 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.54 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.53 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.52 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.51 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.50 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.49 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.48 app/components/primer/beta/auto_complete/item.rb
primer_view_components-0.0.47 app/components/primer/beta/auto_complete/item.rb