# frozen_string_literal: true module Bulmacomp # Make an HTML strucrure for a bulma tabs # # @example # render Bulmacomp::TabsComponent.new() # #
# #
# # @example tabs with elements # elements = [link_to('one','#'), link_to('two','#')] # render Bulmacomp::TabsComponent.new(elements: elements) # #
# #
# # @example tabs with yield content # = render Bulmacomp::TabsComponent.new() do # %li some text # #
# #
# # @example tabs with full options # elements = [link_to('one','#'), link_to('two','#')] # = render Bulmacomp::TabsComponent.new(elements: elements, id: 'ok') do # %li some text # #
# #
class TabsComponent < ViewComponent::Base # @param [Hash] opts # options to generate content # @param [Array] elements # array of elements for tabs collection # @option opts [String] :* # each other key going as tag option, default is class: 'tabs' # @yield [optional] tabs content def initialize(elements: [], **opts) super @elements = elements @opts = { class: 'tabs' }.merge(opts) end # @return [String] html_safe tabs def call tag.div tag.ul(ul_content), **@opts end # @return [Text], safe join of elements arguments and proc content def ul_content safe_join([@elements.map { |e| tag.li(e) }, content]) end end end