Sha256: f1da88a814dcb4cde3d8c147a965aedd1f4f6ef3aa7a56ac007c1c24e00cb6b3

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module Primer
  # Use HiddenTextExpander to indicate and toggle hidden text.
  class HiddenTextExpander < Primer::Component
    # @example Default
    #   <%= render(Primer::HiddenTextExpander.new) %>
    #
    # @example Inline
    #   <%= render(Primer::HiddenTextExpander.new(inline: true)) %>
    #
    # @example Styling the button
    #   <%= render(Primer::HiddenTextExpander.new(button_arguments: { p: 1, classes: "my-custom-class" })) %>
    #
    # @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 = system_arguments
      @system_arguments[:tag] ||= :span
      @system_arguments[:classes] = class_names(
        "hidden-text-expander",
        @system_arguments[:classes],
        "inline" => inline
      )

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

    def call
      render(Primer::BaseComponent.new(**@system_arguments)) do
        render(Primer::BaseButton.new(**@button_arguments)) { "&hellip;" }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
primer_view_components-0.0.38 app/components/primer/hidden_text_expander.rb