Class: Bulmacomp::TabsComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/bulmacomp/tabs_component.rb

Overview

Make an HTML strucrure for a bulma tabs

Examples:

render Bulmacomp::TabsComponent.new()

<div class="tabs">
  <ul></ul>
</div>

tabs with elements

elements = [link_to('one','#'), link_to('two','#')]
render Bulmacomp::TabsComponent.new(elements: elements)

<div class="tabs">
  <ul>
    <li><a href='#'>one</li>
    <li><a href='#'>two</li>
  </ul>
</div>

tabs with yield content

= render Bulmacomp::TabsComponent.new() do
  %li some text

<div class="tabs">
  <ul>
    <li>some text</li>
  </ul>
</div>

tabs with full options

elements = [link_to('one','#'), link_to('two','#')]
= render Bulmacomp::TabsComponent.new(elements: elements, id: 'ok') do
  %li some text

<div class="tabs" id="ok">
  <ul>
    <li><a href='#'>one</li>
    <li><a href='#'>two</li>
    <li>some text</li>
  </ul>
</div>

Instance Method Summary collapse

Constructor Details

#initialize(elements: [], **opts) {|optional| ... } ⇒ TabsComponent

Returns a new instance of TabsComponent.

Parameters:

  • opts (Hash)

    options to generate content

  • elements (Array<String>) (defaults to: [])

    array of elements for tabs collection

Options Hash (**opts):

  • :* (String)

    each other key going as tag option, default is class: ‘tabs’

Yields:

  • (optional)

    tabs content



54
55
56
57
58
# File 'app/components/bulmacomp/tabs_component.rb', line 54

def initialize(elements: [], **opts)
  super
  @elements = elements
  @opts = { class: 'tabs' }.merge(opts)
end

Instance Method Details

#callString

Returns html_safe tabs.

Returns:

  • (String)

    html_safe tabs



61
62
63
# File 'app/components/bulmacomp/tabs_component.rb', line 61

def call
  tag.div tag.ul(ul_content), **@opts
end

#ul_contentText

Returns , safe join of elements arguments and proc content.

Returns:

  • (Text)

    , safe join of elements arguments and proc content



66
67
68
# File 'app/components/bulmacomp/tabs_component.rb', line 66

def ul_content
  safe_join([@elements.map { |e| tag.li(e) }, content])
end