Sha256: 3020482a1fc17699e2c9f59c7554960d36d1ae74a40fe5063774181ebb89b362

Contents?: true

Size: 1.79 KB

Versions: 120

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

module Primer
  module Alpha
    # Use `HiddenTextExpander` to indicate and toggle hidden text.
    #
    # @accessibility
    #   `HiddenTextExpander` requires an `aria-label`, which will provide assistive technologies with an accessible label.
    #   The `aria-label` should describe the action to be invoked by the `HiddenTextExpander`. For instance,
    #   if your `HiddenTextExpander` expands a list of 5 comments, the `aria-label` should be
    #   `"Expand 5 more comments"` instead of `"More"`.
    class HiddenTextExpander < Primer::Component
      status :alpha

      # @param inline [Boolean] Whether or not the expander is inline.
      # @param button_arguments [Hash] <%= link_to_system_arguments_docs %> for the button element.
      # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
      def initialize(inline: false, button_arguments: {}, **system_arguments)
        @system_arguments = deny_tag_argument(**system_arguments)
        @button_arguments = button_arguments

        @system_arguments[:tag] = :span
        @system_arguments[:classes] = class_names(
          "hidden-text-expander",
          @system_arguments[:classes],
          "inline" => inline
        )

        aria_label = system_arguments[:"aria-label"] || system_arguments.dig(:aria, :label) || @aria_label
        if aria_label.present?
          @button_arguments[:"aria-label"] = aria_label
          @system_arguments[:aria]&.delete(:label)
        end

        @button_arguments[:classes] = class_names(
          "ellipsis-expander",
          button_arguments[:classes]
        )
      end

      def call
        render(Primer::BaseComponent.new(**@system_arguments)) do
          render(Primer::Alpha::HellipButton.new(**@button_arguments))
        end
      end
    end
  end
end

Version data entries

120 entries across 120 versions & 2 rubygems

Version Path
primer_view_components-0.36.5 app/components/primer/alpha/hidden_text_expander.rb
openproject-primer_view_components-0.52.2 app/components/primer/alpha/hidden_text_expander.rb
primer_view_components-0.36.4 app/components/primer/alpha/hidden_text_expander.rb
openproject-primer_view_components-0.52.1 app/components/primer/alpha/hidden_text_expander.rb
openproject-primer_view_components-0.52.0 app/components/primer/alpha/hidden_text_expander.rb
primer_view_components-0.36.3 app/components/primer/alpha/hidden_text_expander.rb
openproject-primer_view_components-0.51.0 app/components/primer/alpha/hidden_text_expander.rb
primer_view_components-0.36.2 app/components/primer/alpha/hidden_text_expander.rb
openproject-primer_view_components-0.50.1 app/components/primer/alpha/hidden_text_expander.rb
openproject-primer_view_components-0.50.0 app/components/primer/alpha/hidden_text_expander.rb
primer_view_components-0.36.1 app/components/primer/alpha/hidden_text_expander.rb
primer_view_components-0.36.0 app/components/primer/alpha/hidden_text_expander.rb
openproject-primer_view_components-0.49.2 app/components/primer/alpha/hidden_text_expander.rb
primer_view_components-0.35.2 app/components/primer/alpha/hidden_text_expander.rb
openproject-primer_view_components-0.49.1 app/components/primer/alpha/hidden_text_expander.rb
openproject-primer_view_components-0.49.0 app/components/primer/alpha/hidden_text_expander.rb
primer_view_components-0.35.1 app/components/primer/alpha/hidden_text_expander.rb
primer_view_components-0.35.0 app/components/primer/alpha/hidden_text_expander.rb
openproject-primer_view_components-0.48.2 app/components/primer/alpha/hidden_text_expander.rb
openproject-primer_view_components-0.48.1 app/components/primer/alpha/hidden_text_expander.rb