Sha256: 2d307103c6d3f6b33fb03c40339aa2686e1d4d058e5f9f7ccbe167db2c603f2f
Contents?: true
Size: 1.82 KB
Versions: 2
Compression:
Stored size: 1.82 KB
Contents
# frozen_string_literal: true module Ariadne # `List` is used to show a list of items in a vertical format. class ListComponent < Ariadne::Component DEFAULT_UL_CLASSES = "divide-y divide-gray-300" renders_many :items, "Item" # @example 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 %> # # # @param classes [String] <%= link_to_classes_docs %> # @param attributes [Hash] <%= link_to_attributes_docs %> def initialize(classes: "", attributes: {}) @tag = :ul @classes = class_names(DEFAULT_UL_CLASSES, classes) @attributes = attributes end def render? items.any? end # This component is part of `ListComponent` and should not be # used as a standalone component. class Item < Ariadne::Component DEFAULT_ITEM_CLASSES = "relative p-1.5 focus:ring-2 focus:ring-offset-2 focus:ring-purple-500 hover:bg-button-hover-color" renders_one :entry, lambda { |static_content = nil, &block| next static_content if static_content.present? render(Ariadne::BaseComponent.new(tag: :div)) do view_context.capture { block&.call } end } attr_reader :link, :classes, :attributes def initialize(link: {}, classes: "", attributes: {}) @link = link @classes = class_names(DEFAULT_ITEM_CLASSES, classes) @attributes = attributes end def selected? @selected end def linked? @link.present? end def call Ariadne::BaseComponent.new(tag: :div, classes: @classes, attributes: @attributes) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ariadne_view_components-0.0.6 | app/components/ariadne/list_component.rb |
ariadne_view_components-0.0.5 | app/components/ariadne/list_component.rb |