Sha256: 8aa8ab5a62173e79186b822dcf53b44cdaa0cfee7584ebf990d857761698d5a2

Contents?: true

Size: 1.37 KB

Versions: 107

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Primer
  # Use `Truncate` to shorten overflowing text with an ellipsis.
  class Truncate < Primer::Component
    status :deprecated

    DEFAULT_TAG = :div
    TAG_OPTIONS = [DEFAULT_TAG, :span, :p, :strong].freeze

    # @param tag [Symbol] <%= one_of(Primer::Truncate::TAG_OPTIONS) %>
    # @param inline [Boolean] Whether the element is inline (or inline-block).
    # @param expandable [Boolean] Whether the entire string should be revealed on hover. Can only be used in conjunction with `inline`.
    # @param max_width [Integer] Sets the max-width of the text.
    # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
    def initialize(tag: DEFAULT_TAG, inline: false, expandable: false, max_width: nil, **system_arguments)
      @system_arguments = system_arguments
      @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)
      @system_arguments[:classes] = class_names(
        @system_arguments[:classes],
        "css-truncate",
        "css-truncate-overflow" => !inline,
        "css-truncate-target" => inline,
        "expandable" => inline && expandable
      )
      @system_arguments[:style] = join_style_arguments(@system_arguments[:style], "max-width: #{max_width}px;") unless max_width.nil?
    end

    def call
      render(Primer::BaseComponent.new(**@system_arguments)) { content }
    end
  end
end

Version data entries

107 entries across 107 versions & 2 rubygems

Version Path
primer_view_components-0.35.2 app/components/primer/truncate.rb
openproject-primer_view_components-0.49.1 app/components/primer/truncate.rb
openproject-primer_view_components-0.49.0 app/components/primer/truncate.rb
primer_view_components-0.35.1 app/components/primer/truncate.rb
primer_view_components-0.35.0 app/components/primer/truncate.rb
openproject-primer_view_components-0.48.2 app/components/primer/truncate.rb
openproject-primer_view_components-0.48.1 app/components/primer/truncate.rb
openproject-primer_view_components-0.48.0 app/components/primer/truncate.rb
openproject-primer_view_components-0.47.1 app/components/primer/truncate.rb
openproject-primer_view_components-0.47.0 app/components/primer/truncate.rb
primer_view_components-0.34.0 app/components/primer/truncate.rb
openproject-primer_view_components-0.46.1 app/components/primer/truncate.rb
openproject-primer_view_components-0.46.0 app/components/primer/truncate.rb
openproject-primer_view_components-0.45.0 app/components/primer/truncate.rb
openproject-primer_view_components-0.44.3 app/components/primer/truncate.rb
openproject-primer_view_components-0.44.2 app/components/primer/truncate.rb
openproject-primer_view_components-0.44.1 app/components/primer/truncate.rb
primer_view_components-0.33.0 app/components/primer/truncate.rb
openproject-primer_view_components-0.44.0 app/components/primer/truncate.rb
openproject-primer_view_components-0.43.1 app/components/primer/truncate.rb