Class: GOVUKDesignSystemFormBuilder::Elements::Submit

Inherits:
Base
  • Object
show all
Defined in:
lib/govuk_design_system_formbuilder/elements/submit.rb

Instance Method Summary collapse

Constructor Details

#initialize(builder, text, warning:, secondary:, prevent_double_click:, validate:, &block) ⇒ Submit

Returns a new instance of Submit.


4
5
6
7
8
9
10
11
12
13
14
# File 'lib/govuk_design_system_formbuilder/elements/submit.rb', line 4

def initialize(builder, text, warning:, secondary:, prevent_double_click:, validate:, &block)
  fail ArgumentError, 'buttons can be warning or secondary' if warning && secondary

  @builder              = builder
  @text                 = text
  @prevent_double_click = prevent_double_click
  @warning              = warning
  @secondary            = secondary
  @validate             = validate
  @block_content        = capture { block.call } if block_given?
end

Instance Method Details

#htmlObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/govuk_design_system_formbuilder/elements/submit.rb', line 16

def html
  ('div', class: %w(govuk-form-group)) do
    safe_join(
      [
        @builder.submit(
          @text,
          class: %w(govuk-button).push(
            warning_class,
            secondary_class,
            padding_class(@block_content.present?)
          ).compact,
          **extra_args
        ),
        @block_content
      ]
    )
  end
end