Class: Bootstrap5Helper::InputGroup

Inherits:
Component
  • Object
show all
Defined in:
lib/bootstrap5_helper/input_group.rb

Overview

The InputGroup helper is meant to help you rapidly build Bootstrap input group components quickly and easily.

Instance Method Summary collapse

Methods inherited from Component

#capture, #concat, #config, #content_tag, #parse_arguments, #parse_context_or_options, #parse_tag_or_options, #parse_text_or_options, #uuid

Constructor Details

#initialize(template, context_or_options = nil, opts = {}, &block) ⇒ InputGroup

Class constructor

Parameters:

  • template (Class)
    • Template in which your are binding too.

  • context_or_options (Symbol|Hash) (defaults to: nil)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :id (String)
  • :class (String)
  • :data (Hash)


16
17
18
19
20
21
22
23
24
25
# File 'lib/bootstrap5_helper/input_group.rb', line 16

def initialize(template, context_or_options = nil, opts = {}, &block)
  super(template)

  @context, args = parse_context_or_options(context_or_options, opts)

  @id      = args.fetch(:id,     nil)
  @class   = args.fetch(:class,  '')
  @data    = args.fetch(:data,   {})
  @content = block || proc { '' }
end

Instance Method Details

#text(opts = {}, &block) ⇒ String

This is the element that actually houses the icon or text used in the input group.

Parameters:

  • opts (Hash) (defaults to: {})

Returns:

  • (String)


33
34
35
36
# File 'lib/bootstrap5_helper/input_group.rb', line 33

def text(opts = {}, &block)
  opts[:class] = (opts[:class] || '') << ' input-group-text'
   :span, opts, &block
end

#to_sString

Used to render out the InputGroup component.

Returns:

  • (String)


42
43
44
45
46
47
48
49
50
51
# File 'lib/bootstrap5_helper/input_group.rb', line 42

def to_s
  (
    :div,
    id:    @id,
    class: "input-group #{size_class} #{@class}",
    data:  @data
  ) do
    @content.call(self)
  end
end