class CardComponent < ViewComponent::Base
def initialize(title: nil, image: nil, footer: nil, **opts)
super
@title = title
@image = image
@footer = footer
@opts = { class: 'card' }.merge(opts)
end
# @return [String] html_safe card
def call
tag.div safe_join([card_title, card_image, card_content, card_footer]), **@opts
end
# @return [String] title section if :title is set
# @example
# Bulmacomp::BreadcrumbComponent.new(title: 'test').title
#
#
def card_title
tag.div(tag.div(@title, class: 'card-header-title'), class: 'card-header') if @title
end
# return [String] image section if :image is set
# @example
# Bulmacomp::BreadcrumbComponent.new(title: 'test', image: 'test.jpg').image
#
#
def card_image
tag.div(tag.figure(image_tag(@image, alt: @title), class: 'image'), class: 'card-image') if @image
end
# return [String] content section if yield is present
# @example
# Bulmacomp::BreadcrumbComponent.new().title do
# test content
# end
#
#
def card_content
tag.div(tag.div(content, class: 'content'), class: 'card-content') if content
end
# return [String] footer section if a footer is present
# @example
# Bulmacomp::BreadcrumbComponent.new(footer: 'test').footer
#
#
def card_footer
tag.div @footer, class: 'card-footer' if @footer
end
end
end