Module: NdrUi::Bootstrap::CardHelper

Includes:
CssHelper
Included in:
NdrUi::BootstrapHelper
Defined in:
app/helpers/ndr_ui/bootstrap/card_helper.rb

Overview

This provides accordion

Constant Summary collapse

CARD_TYPES =
%w[primary secondary success danger warning info light dark].freeze

Instance Method Summary collapse

Methods included from CssHelper

#css_class_options_merge

Instance Method Details

#bootstrap_card_body_tag(&block) ⇒ Object

Creates a simple bootstrap card body.

Signatures

bootstrap_card_body_tag do
  #content for card body
end

Examples

<%= bootstrap_card_body_tag do %>
  Check it out!!
<% end %>
# => <div class="card-body">Check it out!!</div>


60
61
62
63
64
# File 'app/helpers/ndr_ui/bootstrap/card_helper.rb', line 60

def bootstrap_card_body_tag(&block)
  return unless block_given?

  (:div, capture(&block), class: 'card-body')
end

#bootstrap_card_list(title, options = {}, &block) ⇒ Object

Creates a bootstrap card wrapper. the heading is wrapped in a card-header. The content is wrapped in a ul.list-group to enable seamless lists. It doesn’t support controls (controls = nil).



69
70
71
72
73
# File 'app/helpers/ndr_ui/bootstrap/card_helper.rb', line 69

def bootstrap_card_list(title, options = {}, &block)
  bootstrap_card_tag(title, nil, options) do
    (:div, capture(&block), class: 'list-group list-group-flush')
  end
end

#bootstrap_card_tag(heading, controls = nil, options = {}, &block) ⇒ Object

Creates a bootstrap card wrapper. the heading is wrapped in a card-header. The content is not wrapped in a card-body to enable seamless tables and lists.

Signatures

bootstrap_card_tag(heading, options = {}) do
  #content for card
end

Examples

<%= bootstrap_card_tag 'Apples', type: :warning, id: 'fruit' do %>
  Check it out!!
<% end %>
# => <div id="fruit" class="card mb-3 text-bg-warning">
       <div class="card-header d-flex">
         <h4 class="card-title">Apples</h4>
         <div class="ms-auto"></div>
       </div>
       Check it out!!
     </div>


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/ndr_ui/bootstrap/card_helper.rb', line 30

def bootstrap_card_tag(heading, controls = nil, options = {}, &block)
  return unless block_given?

  options.stringify_keys!
  classes = %w[card mb-3]
  classes << "bg-#{options.delete('type')}-subtle" if CARD_TYPES.include?(options['type'].to_s)
  options = css_class_options_merge(options, classes)

  header = (:div, class: "card-header#{' d-flex' if controls.present?}") do
    concat (:h4, heading, class: 'card-title')
    concat (:div, controls, class: 'ms-auto') if controls.present?
  end

  (:div, header + capture(&block), options)
end

#bootstrap_well_tag(options = {}, &block) ⇒ Object

Bootstrap v4 dropped Wells for Card component create a wrapper for Wells - a Card without heading



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/helpers/ndr_ui/bootstrap/card_helper.rb', line 77

def bootstrap_well_tag(options = {}, &block)
  return unless block_given?

  options.stringify_keys!
  classes = %w[card mb-3]
  classes << (CARD_TYPES.include?(options['type'].to_s) ? "bg-#{options.delete('type')}-subtle" : 'text-bg-light')
  classes += options['class'].to_s.split if options['class'].present?
  options['class'] = classes.uniq.join(' ')

  (:div, options) do
    bootstrap_card_body_tag do
      capture(&block)
    end
  end
end