Class: Primer::Truncate
- Defined in:
- app/components/primer/truncate.rb
Overview
Use ‘Truncate` to shorten overflowing text with an ellipsis.
Constant Summary collapse
- DEFAULT_TAG =
:div
- TAG_OPTIONS =
[DEFAULT_TAG, :span, :p, :strong].freeze
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
Primer::TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Constants included from AttributesHelper
AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(tag: DEFAULT_TAG, inline: false, expandable: false, max_width: nil, **system_arguments) ⇒ Truncate
constructor
A new instance of Truncate.
Methods inherited from Component
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Methods included from AttributesHelper
#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Methods included from ExperimentalSlotHelpers
Methods included from ExperimentalRenderHelpers
Constructor Details
#initialize(tag: DEFAULT_TAG, inline: false, expandable: false, max_width: nil, **system_arguments) ⇒ Truncate
Returns a new instance of Truncate.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/components/primer/truncate.rb', line 16 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 && ) @system_arguments[:style] = join_style_arguments(@system_arguments[:style], "max-width: #{max_width}px;") unless max_width.nil? end |
Instance Method Details
#call ⇒ Object
29 30 31 |
# File 'app/components/primer/truncate.rb', line 29 def call render(Primer::BaseComponent.new(**@system_arguments)) { content } end |