-
Notifications
You must be signed in to change notification settings - Fork 353
Expand file tree
/
Copy pathsubmit.rb
More file actions
59 lines (52 loc) · 1.64 KB
/
submit.rb
File metadata and controls
59 lines (52 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true
module BootstrapForm
module Inputs
module Submit
def button(value=nil, options={}, &)
if options.key? :submits_with
options[:data] = { turbo_submits_with: setup_turbo_submit(options[:submits_with]) }
options.except! :submits_with
end
value = setup_css_class "btn btn-secondary", value, options
super
end
def submit(value=nil, options={})
value = setup_css_class "btn btn-secondary", value, options
layout == :inline ? form_group { super } : super
end
def primary(value=nil, options={}, &block)
value = setup_css_class "btn btn-primary", value, options
if options[:render_as_button] || options[:submits_with] || block
options.except! :render_as_button
button(value, options, &block)
else
submit(value, options)
end
end
private
def setup_css_class(the_class, value, options)
if value.is_a?(Hash)
options.merge!(value)
value = nil
end
unless options.key? :class
if (extra_class = options.delete(:extra_class))
the_class = "#{the_class} #{extra_class}"
end
options[:class] = the_class
end
value
end
def setup_turbo_submit(submits_with)
case submits_with
when :spinner, "spinner"
<<~HTML.strip
<div class="spinner-border d-block mx-auto" role="status" style="--bs-spinner-width: 1lh; --bs-spinner-height: 1lh;"></div>
HTML
else
submits_with.to_s
end
end
end
end
end