Class: Yattho::Beta::Truncate

Inherits:
Component
  • Object
show all
Defined in:
app/components/yattho/beta/truncate.rb

Overview

Use ‘Truncate` to shorten overflowing text with an ellipsis.

Defined Under Namespace

Classes: TruncateText

Constant Summary

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(**system_arguments) ⇒ Truncate

Returns a new instance of Truncate.

Examples:

Default

<%= render(Yattho::Beta::Truncate.new) { "branch-name-that-is-really-long" } %>

Multiple items

<%= render(Yattho::Beta::Truncate.new) do |component| %>
  <% component.with_item do %>really-long-repository-owner-name<% end %>
  <% component.with_item(font_weight: :bold) do %>
    <%= render(Yattho::BaseComponent.new(tag: :span, font_weight: :normal)) { "/" } %> really-long-repository-name
  <% end %>
<% end %>

Advanced multiple items

<%= render(Yattho::Beta::Truncate.new(tag: :ol)) do |component| %>
  <% component.with_item(tag: :li) do %>yattho<% end %>
  <% component.with_item(tag: :li, priority: true) do %>/ css<% end %>
  <% component.with_item(tag: :li) do %>/ Issues<% end %>
  <% component.with_item(tag: :li) do %>/ #123 —<% end %>
  <% component.with_item(tag: :li, priority: true) do %>
    Visual bug on yattho.com found in lists
  <% end %>
<% end %>

Expand on hover or focus

<%= render(Yattho::Beta::Truncate.new) do |component| %>
  <% component.with_item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
  <% component.with_item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
  <% component.with_item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
  <% component.with_item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
<% end %>

Max widths

<%= render(Yattho::Beta::Truncate.new) do |component| %>
  <% component.with_item(max_width: 300, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
  <% component.with_item(max_width: 200, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
  <% component.with_item(max_width: 100, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
<% end %>

Max widths on new lines

<%= render(Yattho::Beta::Truncate.new) do |component| %>
  <% component.with_item(max_width: 300, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
<% end %>
<br/>
<%= render(Yattho::Beta::Truncate.new) do |component| %>
  <% component.with_item(max_width: 200, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
<% end %>
<br/>
<%= render(Yattho::Beta::Truncate.new) do |component| %>
  <% component.with_item(max_width: 100, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
<% end %>

Parameters:

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



68
69
70
71
72
73
74
75
# File 'app/components/yattho/beta/truncate.rb', line 68

def initialize(**system_arguments)
  @system_arguments = system_arguments
  @system_arguments[:tag] = system_arguments[:tag] || :span
  @system_arguments[:classes] = class_names(
    "Truncate",
    system_arguments[:classes]
  )
end

Instance Method Details

#before_renderObject



77
78
79
80
81
# File 'app/components/yattho/beta/truncate.rb', line 77

def before_render
  return unless content.present? && items.empty?

  with_item { content }
end

#render?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/components/yattho/beta/truncate.rb', line 83

def render?
  items?
end