stimulus_plumbers 0.2.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +52 -0
- data/README.md +8 -4
- data/app/assets/javascripts/stimulus-plumbers/stimulus-plumbers-controllers.es.js +450 -436
- data/app/assets/javascripts/stimulus-plumbers/stimulus-plumbers-controllers.umd.js +1 -1
- data/lib/stimulus_plumbers/components/action_list/item.rb +27 -0
- data/lib/stimulus_plumbers/components/action_list/section.rb +21 -0
- data/lib/stimulus_plumbers/components/action_list.rb +23 -0
- data/lib/stimulus_plumbers/components/avatar.rb +73 -0
- data/lib/stimulus_plumbers/components/button/group.rb +17 -0
- data/lib/stimulus_plumbers/components/button.rb +27 -0
- data/lib/stimulus_plumbers/components/calendar/month/turbo/days_of_month.rb +60 -41
- data/lib/stimulus_plumbers/components/calendar/month/turbo/days_of_week.rb +15 -12
- data/lib/stimulus_plumbers/components/calendar/month/turbo.rb +55 -0
- data/lib/stimulus_plumbers/components/calendar.rb +56 -0
- data/lib/stimulus_plumbers/components/card/section.rb +25 -0
- data/lib/stimulus_plumbers/components/card.rb +27 -0
- data/lib/stimulus_plumbers/components/combobox/autocomplete.rb +30 -34
- data/lib/stimulus_plumbers/components/combobox/date.rb +16 -18
- data/lib/stimulus_plumbers/components/combobox/dropdown.rb +13 -16
- data/lib/stimulus_plumbers/components/combobox/options/option.rb +34 -0
- data/lib/stimulus_plumbers/components/combobox/options/option_group.rb +29 -0
- data/lib/stimulus_plumbers/components/combobox/options.rb +59 -0
- data/lib/stimulus_plumbers/components/combobox/popover.rb +20 -0
- data/lib/stimulus_plumbers/components/combobox/time/drum.rb +37 -0
- data/lib/stimulus_plumbers/components/combobox/time.rb +32 -15
- data/lib/stimulus_plumbers/components/combobox/trigger.rb +38 -0
- data/lib/stimulus_plumbers/components/combobox.rb +59 -0
- data/lib/stimulus_plumbers/components/date_picker/navigation.rb +14 -22
- data/lib/stimulus_plumbers/components/date_picker/navigator.rb +1 -1
- data/lib/stimulus_plumbers/components/icon.rb +43 -0
- data/lib/stimulus_plumbers/components/popover/builder.rb +25 -0
- data/lib/stimulus_plumbers/components/popover.rb +31 -0
- data/lib/stimulus_plumbers/configuration.rb +3 -18
- data/lib/stimulus_plumbers/engine.rb +2 -2
- data/lib/stimulus_plumbers/form/builder.rb +8 -6
- data/lib/stimulus_plumbers/form/{field_component.rb → field.rb} +1 -1
- data/lib/stimulus_plumbers/form/fields/combobox.rb +7 -4
- data/lib/stimulus_plumbers/form/fields/error.rb +14 -0
- data/lib/stimulus_plumbers/form/fields/group.rb +14 -0
- data/lib/stimulus_plumbers/form/fields/hint.rb +14 -0
- data/lib/stimulus_plumbers/form/fields/label.rb +21 -0
- data/lib/stimulus_plumbers/form/fields/renderer.rb +20 -21
- data/lib/stimulus_plumbers/form/fields/search.rb +23 -9
- data/lib/stimulus_plumbers/form/fields/submit.rb +23 -0
- data/lib/stimulus_plumbers/helpers/action_list_helper.rb +2 -2
- data/lib/stimulus_plumbers/helpers/avatar_helper.rb +2 -2
- data/lib/stimulus_plumbers/helpers/button_helper.rb +2 -2
- data/lib/stimulus_plumbers/helpers/calendar_helper.rb +1 -1
- data/lib/stimulus_plumbers/helpers/calendar_turbo_helper.rb +1 -1
- data/lib/stimulus_plumbers/helpers/card_helper.rb +2 -2
- data/lib/stimulus_plumbers/helpers/combobox_helper.rb +5 -5
- data/lib/stimulus_plumbers/helpers/popover_helper.rb +2 -2
- data/lib/stimulus_plumbers/plumber/base.rb +20 -0
- data/lib/stimulus_plumbers/plumber/dispatcher/callable_inspector.rb +19 -0
- data/lib/stimulus_plumbers/plumber/dispatcher/instance_exec.rb +35 -0
- data/lib/stimulus_plumbers/plumber/dispatcher/klass_proxy.rb +34 -0
- data/lib/stimulus_plumbers/plumber/dispatcher/method_call.rb +36 -0
- data/lib/stimulus_plumbers/plumber/dispatcher.rb +28 -0
- data/lib/stimulus_plumbers/plumber/html_options.rb +52 -0
- data/lib/stimulus_plumbers/plumber/renderer.rb +89 -0
- data/lib/stimulus_plumbers/themes/base.rb +34 -20
- data/lib/stimulus_plumbers/themes/configuration.rb +38 -0
- data/lib/stimulus_plumbers/themes/schema/form/ranges.rb +14 -0
- data/lib/stimulus_plumbers/themes/schema/icon.rb +32 -0
- data/lib/stimulus_plumbers/themes/schema/ranges.rb +5 -5
- data/lib/stimulus_plumbers/themes/schema.rb +103 -0
- data/lib/stimulus_plumbers/version.rb +1 -1
- data/lib/stimulus_plumbers.rb +29 -19
- metadata +40 -34
- data/lib/stimulus_plumbers/components/action_list/renderer.rb +0 -47
- data/lib/stimulus_plumbers/components/avatar/renderer.rb +0 -74
- data/lib/stimulus_plumbers/components/button/renderer.rb +0 -33
- data/lib/stimulus_plumbers/components/calendar/month/turbo/renderer.rb +0 -57
- data/lib/stimulus_plumbers/components/calendar/renderer.rb +0 -35
- data/lib/stimulus_plumbers/components/card/renderer.rb +0 -41
- data/lib/stimulus_plumbers/components/combobox/option.rb +0 -27
- data/lib/stimulus_plumbers/components/combobox/option_group.rb +0 -52
- data/lib/stimulus_plumbers/components/combobox/renderer.rb +0 -78
- data/lib/stimulus_plumbers/components/icon/renderer.rb +0 -51
- data/lib/stimulus_plumbers/components/plumber/base.rb +0 -22
- data/lib/stimulus_plumbers/components/plumber/dispatcher.rb +0 -113
- data/lib/stimulus_plumbers/components/plumber/html_options.rb +0 -53
- data/lib/stimulus_plumbers/components/plumber/renderer.rb +0 -91
- data/lib/stimulus_plumbers/components/popover/renderer.rb +0 -46
- data/lib/stimulus_plumbers/components/time_picker/renderer.rb +0 -38
- data/lib/stimulus_plumbers/themes/base/action_list.rb +0 -14
- data/lib/stimulus_plumbers/themes/base/avatar.rb +0 -14
- data/lib/stimulus_plumbers/themes/base/button.rb +0 -18
- data/lib/stimulus_plumbers/themes/base/calendar.rb +0 -15
- data/lib/stimulus_plumbers/themes/base/card.rb +0 -12
- data/lib/stimulus_plumbers/themes/base/form.rb +0 -34
- data/lib/stimulus_plumbers/themes/base/layout.rb +0 -12
- data/lib/stimulus_plumbers/themes/tailwind/action_list.rb +0 -33
- data/lib/stimulus_plumbers/themes/tailwind/avatar.rb +0 -52
- data/lib/stimulus_plumbers/themes/tailwind/button.rb +0 -89
- data/lib/stimulus_plumbers/themes/tailwind/calendar.rb +0 -34
- data/lib/stimulus_plumbers/themes/tailwind/card.rb +0 -24
- data/lib/stimulus_plumbers/themes/tailwind/form.rb +0 -108
- data/lib/stimulus_plumbers/themes/tailwind/layout.rb +0 -25
- data/lib/stimulus_plumbers/themes/tailwind_theme.rb +0 -29
|
@@ -19,30 +19,22 @@ module StimulusPlumbers
|
|
|
19
19
|
|
|
20
20
|
def navigators(stimulus_controller, step)
|
|
21
21
|
[
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)
|
|
27
|
-
Navigator.new(template).render(
|
|
28
|
-
aria: { label: "Day" },
|
|
29
|
-
data: { "#{stimulus_controller}-target" => "day" }
|
|
30
|
-
),
|
|
31
|
-
Navigator.new(template).render(
|
|
32
|
-
aria: { label: "Month" },
|
|
33
|
-
data: { "#{stimulus_controller}-target" => "month" }
|
|
34
|
-
),
|
|
35
|
-
Navigator.new(template).render(
|
|
36
|
-
aria: { label: "Year" },
|
|
37
|
-
data: { "#{stimulus_controller}-target" => "year" }
|
|
38
|
-
),
|
|
39
|
-
Navigator.new(template).render(
|
|
40
|
-
icon_options: { name: "arrow-right" },
|
|
41
|
-
aria: { label: ["next", step].join(" ").titleize },
|
|
42
|
-
data: { "#{stimulus_controller}-target" => "next" }
|
|
43
|
-
)
|
|
22
|
+
navigator(stimulus_controller, target: "previous", icon: "arrow-left", label: ["previous", step].join(" ").titleize),
|
|
23
|
+
navigator(stimulus_controller, target: "day", label: "Day"),
|
|
24
|
+
navigator(stimulus_controller, target: "month", label: "Month"),
|
|
25
|
+
navigator(stimulus_controller, target: "year", label: "Year"),
|
|
26
|
+
navigator(stimulus_controller, target: "next", icon: "arrow-right", label: ["next", step].join(" ").titleize)
|
|
44
27
|
]
|
|
45
28
|
end
|
|
29
|
+
|
|
30
|
+
def navigator(stimulus_controller, target:, label:, icon: nil)
|
|
31
|
+
opts = {
|
|
32
|
+
aria: { label: label },
|
|
33
|
+
data: { "#{stimulus_controller}-target" => target }
|
|
34
|
+
}
|
|
35
|
+
opts[:icon_options] = { name: icon } if icon
|
|
36
|
+
Navigator.new(template).render(**opts)
|
|
37
|
+
end
|
|
46
38
|
end
|
|
47
39
|
end
|
|
48
40
|
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StimulusPlumbers
|
|
4
|
+
module Components
|
|
5
|
+
class Icon < Plumber::Base
|
|
6
|
+
def render(name:, **kwargs)
|
|
7
|
+
html_options = merge_html_options(
|
|
8
|
+
{ classes: theme.resolve(:icon).fetch(:classes, "") },
|
|
9
|
+
kwargs
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
icon_data = Themes::Schema::Icon.resolve(theme.icons[name])
|
|
13
|
+
if icon_data
|
|
14
|
+
svg_icon(icon_data, html_options)
|
|
15
|
+
else
|
|
16
|
+
template.tag.span(**html_options)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def svg_icon(icon_data, html_options)
|
|
23
|
+
template.content_tag(
|
|
24
|
+
:svg,
|
|
25
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
26
|
+
fill: icon_data[:fill],
|
|
27
|
+
viewBox: icon_data[:view_box],
|
|
28
|
+
width: icon_data[:width],
|
|
29
|
+
height: icon_data[:height],
|
|
30
|
+
stroke: icon_data[:stroke],
|
|
31
|
+
"stroke-width": icon_data[:stroke_width],
|
|
32
|
+
**html_options
|
|
33
|
+
) do
|
|
34
|
+
template.tag.path(
|
|
35
|
+
"stroke-linecap": icon_data[:stroke_linecap],
|
|
36
|
+
"stroke-linejoin": icon_data[:stroke_linejoin],
|
|
37
|
+
d: icon_data[:d]
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StimulusPlumbers
|
|
4
|
+
module Components
|
|
5
|
+
class Popover
|
|
6
|
+
class Builder
|
|
7
|
+
attr_reader :activator_html, :content_html
|
|
8
|
+
|
|
9
|
+
def initialize(template)
|
|
10
|
+
@template = template
|
|
11
|
+
@activator_html = "".html_safe
|
|
12
|
+
@content_html = "".html_safe
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def activator(&block)
|
|
16
|
+
@activator_html = @template.capture(&block)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def content(&block)
|
|
20
|
+
@content_html = @template.capture(&block)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StimulusPlumbers
|
|
4
|
+
module Components
|
|
5
|
+
class Popover < Plumber::Base
|
|
6
|
+
def render(interactive: true, **kwargs, &block)
|
|
7
|
+
html_options = merge_html_options(
|
|
8
|
+
{ classes: theme.resolve(:popover).fetch(:classes, "") },
|
|
9
|
+
kwargs
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
builder = Popover::Builder.new(template)
|
|
13
|
+
template.capture(builder, &block)
|
|
14
|
+
|
|
15
|
+
template.content_tag(:div, **html_options) do
|
|
16
|
+
template.safe_join([builder.activator_html, wrap_content(interactive, builder)])
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def wrap_content(interactive, builder)
|
|
23
|
+
if interactive
|
|
24
|
+
template.content_tag(:template, builder.content_html)
|
|
25
|
+
else
|
|
26
|
+
builder.content_html
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "themes/base"
|
|
4
|
-
require_relative "themes/
|
|
4
|
+
require_relative "themes/configuration"
|
|
5
5
|
|
|
6
6
|
module StimulusPlumbers
|
|
7
7
|
class Configuration
|
|
8
|
-
DEFAULT_LOG_FORMATTER
|
|
9
|
-
THEME_KLASS_FORMATTER = ->(type) { "StimulusPlumbers::Themes::#{type.to_s.classify}Theme" }
|
|
8
|
+
DEFAULT_LOG_FORMATTER = ->(message) { "[StimulusPlumbers] #{message}" }
|
|
10
9
|
|
|
11
10
|
def theme
|
|
12
|
-
@theme ||=
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def theme=(value)
|
|
16
|
-
@theme = build_theme(value)
|
|
11
|
+
@theme ||= Themes::Configuration.new
|
|
17
12
|
end
|
|
18
13
|
|
|
19
14
|
def log_formatter
|
|
@@ -25,15 +20,5 @@ module StimulusPlumbers
|
|
|
25
20
|
|
|
26
21
|
@log_formatter = callable
|
|
27
22
|
end
|
|
28
|
-
|
|
29
|
-
private
|
|
30
|
-
|
|
31
|
-
def build_theme(type)
|
|
32
|
-
return type if type.is_a?(Themes::Base)
|
|
33
|
-
|
|
34
|
-
klass_name = THEME_KLASS_FORMATTER.call(type)
|
|
35
|
-
klass_name.safe_constantize&.new or
|
|
36
|
-
raise ArgumentError, "Unknown theme #{type.inspect}: #{klass_name} is not defined."
|
|
37
|
-
end
|
|
38
23
|
end
|
|
39
24
|
end
|
|
@@ -8,8 +8,8 @@ module StimulusPlumbers
|
|
|
8
8
|
|
|
9
9
|
config.autoload_paths << File.expand_path("../stimulus-plumbers", __dir__)
|
|
10
10
|
|
|
11
|
-
initializer "stimulus_plumbers.assets" do |app|
|
|
12
|
-
app.config.assets.
|
|
11
|
+
initializer "stimulus_plumbers.assets", after: :set_default_precompile do |app|
|
|
12
|
+
app.config.assets.precompile += %w[stimulus_plumbers/tokens.css] if app.config.respond_to?(:assets)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
initializer "stimulus_plumbers.helpers" do
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "action_view/version"
|
|
4
4
|
|
|
5
|
-
require_relative "
|
|
5
|
+
require_relative "field"
|
|
6
6
|
require_relative "fields/choice"
|
|
7
7
|
require_relative "fields/combobox"
|
|
8
8
|
require_relative "fields/file"
|
|
@@ -12,25 +12,27 @@ require_relative "fields/search"
|
|
|
12
12
|
require_relative "fields/select"
|
|
13
13
|
require_relative "fields/text"
|
|
14
14
|
require_relative "fields/text_area"
|
|
15
|
-
require_relative "
|
|
15
|
+
require_relative "fields/submit"
|
|
16
|
+
require_relative "../plumber/html_options"
|
|
16
17
|
|
|
17
18
|
module StimulusPlumbers
|
|
18
19
|
module Form
|
|
19
20
|
class Builder < ActionView::Helpers::FormBuilder
|
|
20
|
-
include
|
|
21
|
+
include Plumber::HtmlOptions
|
|
21
22
|
include Fields::Choice
|
|
22
23
|
include Fields::Combobox
|
|
23
24
|
include Fields::File
|
|
24
25
|
include Fields::Password
|
|
25
26
|
include Fields::Search
|
|
26
27
|
include Fields::Select
|
|
28
|
+
include Fields::Submit
|
|
27
29
|
include Fields::Text
|
|
28
30
|
include Fields::TextArea
|
|
29
31
|
|
|
30
32
|
private
|
|
31
33
|
|
|
32
34
|
def build_field(attribute, form_field_opts, input_id: field_id(attribute))
|
|
33
|
-
|
|
35
|
+
Field.new(
|
|
34
36
|
object: object,
|
|
35
37
|
attribute: attribute,
|
|
36
38
|
input_id: input_id,
|
|
@@ -57,7 +59,7 @@ module StimulusPlumbers
|
|
|
57
59
|
end
|
|
58
60
|
|
|
59
61
|
def extract_options(options)
|
|
60
|
-
[options.except(*
|
|
62
|
+
[options.except(*Field::OPTIONS), options.slice(*Field::OPTIONS)]
|
|
61
63
|
end
|
|
62
64
|
|
|
63
65
|
def field_theme(key, **variants)
|
|
@@ -65,7 +67,7 @@ module StimulusPlumbers
|
|
|
65
67
|
end
|
|
66
68
|
|
|
67
69
|
def theme
|
|
68
|
-
StimulusPlumbers.config.theme
|
|
70
|
+
StimulusPlumbers.config.theme.current
|
|
69
71
|
end
|
|
70
72
|
|
|
71
73
|
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
|
@@ -19,21 +19,24 @@ module StimulusPlumbers
|
|
|
19
19
|
|
|
20
20
|
rails_opts, field_opts = extract_options(html_options)
|
|
21
21
|
field = build_field(attribute, field_opts)
|
|
22
|
-
base_id = field_id(attribute)
|
|
23
22
|
current_value = object&.public_send(attribute)
|
|
24
23
|
|
|
24
|
+
wrapper = build_combobox_wrapper(klass, attribute, field, current_value, options, rails_opts)
|
|
25
|
+
render_field(field, wrapper)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def build_combobox_wrapper(klass, attribute, field, current_value, options, rails_opts)
|
|
25
29
|
popover = klass.new(@template).render(options: options, value: current_value, **rails_opts)
|
|
26
30
|
opts = klass.default_opts.deep_merge(
|
|
27
31
|
input: { name: field_name(attribute), value: current_value },
|
|
28
32
|
popover: { content: popover }
|
|
29
33
|
)
|
|
30
|
-
|
|
31
|
-
base_id:
|
|
34
|
+
Components::Combobox.new(@template).render(
|
|
35
|
+
base_id: field_id(attribute),
|
|
32
36
|
options: opts,
|
|
33
37
|
**field_theme(:form_combobox, error: field.error?),
|
|
34
38
|
**field.html_opts
|
|
35
39
|
)
|
|
36
|
-
render_field(field, wrapper)
|
|
37
40
|
end
|
|
38
41
|
end
|
|
39
42
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StimulusPlumbers
|
|
4
|
+
module Form
|
|
5
|
+
module Fields
|
|
6
|
+
class Error < Plumber::Base
|
|
7
|
+
def render(message:, id:)
|
|
8
|
+
klass = theme.resolve(:form_error).fetch(:classes, "")
|
|
9
|
+
template.content_tag(:p, message, id: id, class: klass.presence, role: "alert")
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StimulusPlumbers
|
|
4
|
+
module Form
|
|
5
|
+
module Fields
|
|
6
|
+
class Group < Plumber::Base
|
|
7
|
+
def render(layout: :stacked, error: false, &block)
|
|
8
|
+
klass = theme.resolve(:form_group, layout: layout, error: error).fetch(:classes, "")
|
|
9
|
+
template.content_tag(:div, class: klass.presence, &block)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StimulusPlumbers
|
|
4
|
+
module Form
|
|
5
|
+
module Fields
|
|
6
|
+
class Hint < Plumber::Base
|
|
7
|
+
def render(text:, id:)
|
|
8
|
+
klass = theme.resolve(:form_details).fetch(:classes, "")
|
|
9
|
+
template.content_tag(:p, text, id: id, class: klass.presence)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StimulusPlumbers
|
|
4
|
+
module Form
|
|
5
|
+
module Fields
|
|
6
|
+
class Label < Plumber::Base
|
|
7
|
+
def render(text:, for_id:, required: false, hidden: false)
|
|
8
|
+
klass = theme.resolve(:form_label, required: required, hidden: hidden).fetch(:classes, "")
|
|
9
|
+
|
|
10
|
+
inner = text.dup.html_safe
|
|
11
|
+
if required
|
|
12
|
+
mark_klass = theme.resolve(:form_required_mark).fetch(:classes, "")
|
|
13
|
+
inner += template.content_tag(:span, "*", "aria-hidden": "true", class: mark_klass.presence)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
template.content_tag(:label, inner, for: for_id, class: klass.presence)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -13,43 +13,42 @@ module StimulusPlumbers
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def call(input_html)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
template.content_tag(:div, class: field_klass) do
|
|
19
|
-
label_html + input_html.html_safe + hint_html + errors_html
|
|
16
|
+
Group.new(template).render(layout: field.layout, error: field.error?) do
|
|
17
|
+
(field_label + input_html.html_safe + field_hint + field_errors).html_safe
|
|
20
18
|
end
|
|
21
19
|
end
|
|
22
20
|
|
|
23
21
|
private
|
|
24
22
|
|
|
25
|
-
def
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
template.content_tag(:label, inner, for: field.input_id, class: klass)
|
|
23
|
+
def field_label
|
|
24
|
+
Label.new(template).render(
|
|
25
|
+
text: field.label_text,
|
|
26
|
+
for_id: field.input_id,
|
|
27
|
+
required: field.required,
|
|
28
|
+
hidden: field.label_hidden?
|
|
29
|
+
)
|
|
35
30
|
end
|
|
36
31
|
|
|
37
|
-
def
|
|
32
|
+
def field_hint
|
|
38
33
|
return "".html_safe unless field.details.present?
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
Hint.new(template).render(
|
|
36
|
+
text: field.details,
|
|
37
|
+
id: field.hint_id
|
|
38
|
+
)
|
|
42
39
|
end
|
|
43
40
|
|
|
44
|
-
def
|
|
41
|
+
def field_errors
|
|
45
42
|
return "".html_safe if field.errors.none?
|
|
46
43
|
|
|
47
|
-
klass = theme.resolve(:form_error).fetch(:classes, "")
|
|
48
44
|
field.errors.map.with_index(1) do |message, i|
|
|
49
|
-
|
|
50
|
-
template.content_tag(:p, message, id: id, class: klass, role: "alert")
|
|
45
|
+
Error.new(template).render(message: message, id: error_id_for(i))
|
|
51
46
|
end.join.html_safe
|
|
52
47
|
end
|
|
48
|
+
|
|
49
|
+
def error_id_for(index)
|
|
50
|
+
field.errors.one? ? field.error_id : "#{field.error_id}_#{index}"
|
|
51
|
+
end
|
|
53
52
|
end
|
|
54
53
|
end
|
|
55
54
|
end
|
|
@@ -9,14 +9,26 @@ module StimulusPlumbers
|
|
|
9
9
|
clearable = form_field_opts.delete(:clearable) { false }
|
|
10
10
|
field = build_field(attribute, form_field_opts)
|
|
11
11
|
|
|
12
|
-
html_opts = merge_html_options(
|
|
13
|
-
rails_opts,
|
|
14
|
-
field_theme(:form_input, error: field.error?),
|
|
15
|
-
field.html_opts
|
|
16
|
-
)
|
|
17
12
|
input_html = if clearable
|
|
18
|
-
|
|
13
|
+
input_opts = merge_html_options(
|
|
14
|
+
rails_opts,
|
|
15
|
+
field_theme(:form_input, error: field.error?),
|
|
16
|
+
field.html_opts,
|
|
17
|
+
{ "data-input-search-target": "input", inputmode: "search" }
|
|
18
|
+
)
|
|
19
|
+
build_input_group(
|
|
20
|
+
super(attribute, input_opts),
|
|
21
|
+
field,
|
|
22
|
+
trailing: clear_button,
|
|
23
|
+
"data-controller": "input-search",
|
|
24
|
+
role: "search"
|
|
25
|
+
)
|
|
19
26
|
else
|
|
27
|
+
html_opts = merge_html_options(
|
|
28
|
+
rails_opts,
|
|
29
|
+
field_theme(:form_input, error: field.error?),
|
|
30
|
+
field.html_opts
|
|
31
|
+
)
|
|
20
32
|
super(attribute, html_opts)
|
|
21
33
|
end
|
|
22
34
|
|
|
@@ -29,9 +41,11 @@ module StimulusPlumbers
|
|
|
29
41
|
@template.content_tag(
|
|
30
42
|
:button,
|
|
31
43
|
"",
|
|
32
|
-
type:
|
|
33
|
-
class:
|
|
34
|
-
"aria-label":
|
|
44
|
+
type: "button",
|
|
45
|
+
class: field_theme(:form_button_reveal)[:class],
|
|
46
|
+
"aria-label": "Clear search",
|
|
47
|
+
"data-input-search-target": "clear",
|
|
48
|
+
"data-action": "click->input-search#clear"
|
|
35
49
|
)
|
|
36
50
|
end
|
|
37
51
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StimulusPlumbers
|
|
4
|
+
module Form
|
|
5
|
+
module Fields
|
|
6
|
+
module Submit
|
|
7
|
+
def submit(value = nil, options = {})
|
|
8
|
+
if value.is_a?(Hash)
|
|
9
|
+
options = value
|
|
10
|
+
value = nil
|
|
11
|
+
end
|
|
12
|
+
value ||= submit_default_value
|
|
13
|
+
variant = options.delete(:variant) { :default }
|
|
14
|
+
@template.tag.input(
|
|
15
|
+
type: "submit",
|
|
16
|
+
value: value,
|
|
17
|
+
**merge_html_options(field_theme(:form_submit, variant: variant), options)
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -4,7 +4,7 @@ module StimulusPlumbers
|
|
|
4
4
|
module Helpers
|
|
5
5
|
module ActionListHelper
|
|
6
6
|
def sp_action_list(**html_options, &block)
|
|
7
|
-
action_list_renderer.
|
|
7
|
+
action_list_renderer.render(**html_options, &block)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def sp_action_list_section(title: nil, **html_options, &block)
|
|
@@ -18,7 +18,7 @@ module StimulusPlumbers
|
|
|
18
18
|
private
|
|
19
19
|
|
|
20
20
|
def action_list_renderer
|
|
21
|
-
Components::ActionList
|
|
21
|
+
Components::ActionList.new(self)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -4,13 +4,13 @@ module StimulusPlumbers
|
|
|
4
4
|
module Helpers
|
|
5
5
|
module AvatarHelper
|
|
6
6
|
def sp_avatar(name: nil, initials: nil, url: nil, color: nil, size: :md, **html_options, &block)
|
|
7
|
-
avatar_renderer.
|
|
7
|
+
avatar_renderer.render(name: name, initials: initials, url: url, color: color, size: size, **html_options, &block)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
private
|
|
11
11
|
|
|
12
12
|
def avatar_renderer
|
|
13
|
-
Components::Avatar
|
|
13
|
+
Components::Avatar.new(self)
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
end
|
|
@@ -4,7 +4,7 @@ module StimulusPlumbers
|
|
|
4
4
|
module Helpers
|
|
5
5
|
module ButtonHelper
|
|
6
6
|
def sp_button(content = nil, url: nil, external: false, variant: :primary, size: :md, **html_options, &block)
|
|
7
|
-
button_renderer.
|
|
7
|
+
button_renderer.render(
|
|
8
8
|
content,
|
|
9
9
|
url: url, external: external, variant: variant, size: size, **html_options,
|
|
10
10
|
&block
|
|
@@ -18,7 +18,7 @@ module StimulusPlumbers
|
|
|
18
18
|
private
|
|
19
19
|
|
|
20
20
|
def button_renderer
|
|
21
|
-
Components::Button
|
|
21
|
+
Components::Button.new(self)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -4,7 +4,7 @@ module StimulusPlumbers
|
|
|
4
4
|
module Helpers
|
|
5
5
|
module CardHelper
|
|
6
6
|
def sp_card(title: nil, **html_options, &block)
|
|
7
|
-
card_renderer.
|
|
7
|
+
card_renderer.render(title: title, **html_options, &block)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def sp_card_section(title: nil, **html_options, &block)
|
|
@@ -14,7 +14,7 @@ module StimulusPlumbers
|
|
|
14
14
|
private
|
|
15
15
|
|
|
16
16
|
def card_renderer
|
|
17
|
-
Components::Card
|
|
17
|
+
Components::Card.new(self)
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -9,7 +9,7 @@ module StimulusPlumbers
|
|
|
9
9
|
popover: { content: Components::Combobox::Date.new(self).render(value: value) }
|
|
10
10
|
)
|
|
11
11
|
opts = opts.deep_merge(trigger: { aria_label: label }) if label
|
|
12
|
-
Components::Combobox
|
|
12
|
+
Components::Combobox.new(self).render(
|
|
13
13
|
base_id: sp_dom_id,
|
|
14
14
|
options: opts,
|
|
15
15
|
data: { input_format_type_value: "date" },
|
|
@@ -23,7 +23,7 @@ module StimulusPlumbers
|
|
|
23
23
|
popover: { content: Components::Combobox::Dropdown.new(self).render(options: options, value: value, label: label) }
|
|
24
24
|
)
|
|
25
25
|
opts = opts.deep_merge(trigger: { aria_label: label }) if label
|
|
26
|
-
Components::Combobox
|
|
26
|
+
Components::Combobox.new(self).render(
|
|
27
27
|
base_id: sp_dom_id,
|
|
28
28
|
options: opts,
|
|
29
29
|
**html_options
|
|
@@ -45,12 +45,12 @@ module StimulusPlumbers
|
|
|
45
45
|
}
|
|
46
46
|
)
|
|
47
47
|
opts = opts.deep_merge(trigger: { aria_label: label }) if label
|
|
48
|
-
Components::Combobox
|
|
48
|
+
Components::Combobox.new(self).render(
|
|
49
49
|
base_id: id,
|
|
50
50
|
options: opts,
|
|
51
51
|
data: {
|
|
52
52
|
input_combobox_combobox_dropdown_outlet: "##{popover_id}",
|
|
53
|
-
action: "input->input-combobox#
|
|
53
|
+
action: "input->input-combobox#onInput"
|
|
54
54
|
},
|
|
55
55
|
**html_options
|
|
56
56
|
)
|
|
@@ -62,7 +62,7 @@ module StimulusPlumbers
|
|
|
62
62
|
popover: { content: Components::Combobox::Time.new(self).render(format: format, step: step, value: value) }
|
|
63
63
|
)
|
|
64
64
|
opts = opts.deep_merge(trigger: { aria_label: label }) if label
|
|
65
|
-
Components::Combobox
|
|
65
|
+
Components::Combobox.new(self).render(
|
|
66
66
|
base_id: sp_dom_id,
|
|
67
67
|
options: opts,
|
|
68
68
|
data: { input_format_type_value: "time", input_format_options_value: { format: format }.to_json },
|
|
@@ -4,13 +4,13 @@ module StimulusPlumbers
|
|
|
4
4
|
module Helpers
|
|
5
5
|
module PopoverHelper
|
|
6
6
|
def sp_popover(interactive: true, **html_options, &block)
|
|
7
|
-
popover_renderer.
|
|
7
|
+
popover_renderer.render(interactive: interactive, **html_options, &block)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
private
|
|
11
11
|
|
|
12
12
|
def popover_renderer
|
|
13
|
-
Components::Popover
|
|
13
|
+
Components::Popover.new(self)
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
end
|