Class: Yattho::Truncate
- Defined in:
- app/components/yattho/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
Yattho::TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
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
Constructor Details
#initialize(tag: DEFAULT_TAG, inline: false, expandable: false, max_width: nil, **system_arguments) ⇒ Truncate
Returns a new instance of Truncate.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/components/yattho/truncate.rb', line 35 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 && ) return if max_width.nil? @system_arguments[:style] = join_style_arguments(@system_arguments[:style], "max-width: #{max_width}px;") end |
Instance Method Details
#call ⇒ Object
51 52 53 |
# File 'app/components/yattho/truncate.rb', line 51 def call render(Yattho::BaseComponent.new(**@system_arguments)) { content } end |