# frozen_string_literal: true
module Yattho
module Beta
# Use `TimelineItem` to display items on a vertical timeline, connected by badge elements.
class TimelineItem < Yattho::Component
status :beta
# Avatar to be rendered to the left of the Badge.
#
# @param kwargs [Hash] The same arguments as <%= link_to_component(Yattho::Beta::Avatar) %>.
renders_one :avatar, lambda { |src:, size: 40, shape: :square, **system_arguments|
system_arguments[:classes] = class_names(
"TimelineItem-avatar",
system_arguments[:classes]
)
Yattho::Beta::Avatar.new(src: src, size: size, shape: shape, **system_arguments)
}
# Badge that will be connected to other TimelineItems.
#
# @param icon [String] Name of <%= link_to_octicons %> to use.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
renders_one :badge, "Badge"
# Body to be rendered to the left of the Badge.
#
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
renders_one :body, lambda { |**system_arguments|
deny_tag_argument(**system_arguments)
system_arguments[:tag] = :div
system_arguments[:classes] = class_names(
"TimelineItem-body",
system_arguments[:classes]
)
Yattho::BaseComponent.new(**system_arguments)
}
# @example Default
#
# <%= render(Yattho::Beta::TimelineItem.new) do |component| %>
# <% component.with_avatar(src: Yattho::ExampleImage::BASE64_SRC, alt: "github") %>
# <% component.with_badge(bg: :success_emphasis, color: :on_emphasis, icon: :check) %>
# <% component.with_body { "Success!" } %>
# <% end %>
#
#
# @param condensed [Boolean] Reduce the vertical padding and remove the background from the badge item. Most commonly used in commits.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(condensed: false, **system_arguments)
@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:tag] = :div
@system_arguments[:classes] = class_names(
"TimelineItem",
condensed ? "TimelineItem--condensed" : "",
system_arguments[:classes]
)
end
def render?
avatar? || badge? || body?
end
# This component is part of `Yattho::Beta::TimelineItem` and should not be
# used as a standalone component.
class Badge < Yattho::Component
status :beta
def initialize(icon: nil, **system_arguments)
@icon = icon
@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:tag] = :div
@system_arguments[:classes] = class_names(
"TimelineItem-badge",
system_arguments[:classes]
)
end
def call
render(Yattho::BaseComponent.new(**@system_arguments)) do
render(Yattho::Beta::Octicon.new(@icon))
end
end
end
end
end
end