Class: Bulmacomp::PanelComponent

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

Overview

Make an html structure for a bulma breadcrumb

Examples:

Empty panel:

render Bulmacomp::PanelComponent.new()

<nav class="panel">
</nav>

panel with option:

= render Bulmacomp::PanelComponent.new(title: 'test title') do
  <a class="panel-block is-active">
    <span class="panel-icon"><i class="fas fa-book" aria-hidden="true"></i></span>
    bulma
  </a>

<nav class="panel">
  <p class="panel-heading">test title</p>
  <a class="panel-block is-active">
    <span class="panel-icon"><i class="fas fa-book" aria-hidden="true"></i></span>
    bulma
  </a>
</nav>

Instance Method Summary collapse

Constructor Details

#initialize(title: nil, **opts) {|optional| ... } ⇒ PanelComponent

Returns a new instance of PanelComponent.

Parameters:

  • opts (Hash)

    options to generate content

Options Hash (**opts):

  • :title (String)

    panel title

  • :* (String)

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

Yields:

  • (optional)

    panel content



35
36
37
38
39
# File 'app/components/bulmacomp/panel_component.rb', line 35

def initialize(title: nil, **opts)
  super
  @title = title
  @opts = { class: 'panel' }.merge(opts)
end

Instance Method Details

#callObject

return [String] html_safe generated bulma panel



42
43
44
# File 'app/components/bulmacomp/panel_component.rb', line 42

def call
   :nav, safe_join([title, content]), **@opts
end

#titleObject

return [String] html_safe generated panel title



47
48
49
# File 'app/components/bulmacomp/panel_component.rb', line 47

def title
  tag.p @title, class: 'panel-heading' if @title
end