Class: Ariadne::ListComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/ariadne/list_component.rb

Overview

List is used to show a list of items in a vertical format.

Defined Under Namespace

Classes: ListItem

Constant Summary collapse

DEFAULT_TAG =
:ul
DEFAULT_UL_CLASSES =
"ariadne-divide-y ariadne-divide-gray-300"

Constants inherited from Component

Component::BASE_BODY_CLASSES, Component::BASE_HTML_CLASSES, Component::BASE_MAIN_CLASSES, Component::BASE_WRAPPER_CLASSES, Component::INVALID_ARIA_LABEL_TAGS

Constants included from ActionViewExtensions::FormHelper

ActionViewExtensions::FormHelper::DEFAULT_FORM_CLASSES

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::INTEGER_TYPES, FetchOrFallbackHelper::InvalidValueError, FetchOrFallbackHelper::TRUE_OR_FALSE

Instance Method Summary collapse

Methods included from ActionViewExtensions::FormHelper

#ariadne_form_with

Methods included from ClassNameHelper

#class_names

Methods included from LoggerHelper

#logger, #silence_deprecations?, #silence_warnings?

Methods included from FetchOrFallbackHelper

#check_incoming_attribute, #check_incoming_tag, #check_incoming_value, #fetch_or_raise, #fetch_or_raise_boolean, #fetch_or_raise_integer

Constructor Details

#initialize(classes: "", attributes: {}) ⇒ ListComponent

Returns a new instance of ListComponent.

Examples:

Basic

<% numbers = [1, 2, 3] %>
<%= render(Ariadne::ListComponent.new) do |list| %>
  <% numbers.each do |number| %>
    <%= list.item do |item|  %>
      <%= item.entry { number } %>
    <% end %>
  <% end %>
<% end %>

Parameters:

  • classes (String) (defaults to: "")

    <%= link_to_classes_docs %>

  • attributes (Hash) (defaults to: {})

    <%= link_to_attributes_docs %>



24
25
26
27
28
# File 'app/components/ariadne/list_component.rb', line 24

def initialize(classes: "", attributes: {})
  @tag = DEFAULT_TAG
  @classes = class_names(DEFAULT_UL_CLASSES, classes)
  @attributes = attributes
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/components/ariadne/list_component.rb', line 30

def render?
  items.any?
end