stimulus_plumbers 0.3.3 → 0.4.2
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 +69 -0
- data/README.md +11 -4
- data/app/assets/javascripts/stimulus-plumbers/controllers.manifest.json +386 -0
- data/app/assets/javascripts/stimulus-plumbers/stimulus-plumbers-controllers.es.js +756 -304
- data/app/assets/javascripts/stimulus-plumbers/stimulus-plumbers-controllers.umd.js +1 -1
- data/app/assets/stylesheets/stimulus_plumbers/tokens.css +66 -26
- data/config/locales/en.yml +31 -0
- data/lib/stimulus_plumbers/components/avatar.rb +22 -13
- data/lib/stimulus_plumbers/components/button/group.rb +9 -4
- data/lib/stimulus_plumbers/components/button/slots.rb +11 -0
- data/lib/stimulus_plumbers/components/button.rb +30 -34
- data/lib/stimulus_plumbers/components/calendar/turbo/days_of_month.rb +191 -0
- data/lib/stimulus_plumbers/components/calendar/turbo/days_of_week.rb +62 -0
- data/lib/stimulus_plumbers/components/calendar/turbo/months_of_year.rb +137 -0
- data/lib/stimulus_plumbers/components/calendar/turbo/years_of_decade.rb +114 -0
- data/lib/stimulus_plumbers/components/calendar/turbo.rb +112 -0
- data/lib/stimulus_plumbers/components/calendar.rb +57 -32
- data/lib/stimulus_plumbers/components/card/slots.rb +26 -0
- data/lib/stimulus_plumbers/components/card.rb +53 -13
- data/lib/stimulus_plumbers/components/combobox/builder.rb +45 -0
- data/lib/stimulus_plumbers/components/combobox/date/navigation.rb +80 -0
- data/lib/stimulus_plumbers/components/combobox/date/navigator.rb +27 -0
- data/lib/stimulus_plumbers/components/combobox/date.rb +55 -28
- data/lib/stimulus_plumbers/components/combobox/dropdown.rb +27 -24
- data/lib/stimulus_plumbers/components/combobox/options/option.rb +1 -1
- data/lib/stimulus_plumbers/components/combobox/options/option_group.rb +1 -1
- data/lib/stimulus_plumbers/components/combobox/time.rb +83 -78
- data/lib/stimulus_plumbers/components/combobox/trigger.rb +17 -12
- data/lib/stimulus_plumbers/components/combobox/typeahead.rb +63 -16
- data/lib/stimulus_plumbers/components/combobox.rb +58 -38
- data/lib/stimulus_plumbers/components/divider.rb +9 -8
- data/lib/stimulus_plumbers/components/icon.rb +5 -1
- data/lib/stimulus_plumbers/components/input_group.rb +2 -2
- data/lib/stimulus_plumbers/components/link/slots.rb +11 -0
- data/lib/stimulus_plumbers/components/link.rb +63 -0
- data/lib/stimulus_plumbers/components/list/item/slots.rb +13 -0
- data/lib/stimulus_plumbers/components/list/item.rb +83 -0
- data/lib/stimulus_plumbers/components/list/section.rb +73 -0
- data/lib/stimulus_plumbers/components/list.rb +31 -0
- data/lib/stimulus_plumbers/components/popover/panel.rb +32 -0
- data/lib/stimulus_plumbers/components/popover/trigger.rb +27 -0
- data/lib/stimulus_plumbers/components/popover.rb +44 -18
- data/lib/stimulus_plumbers/components/timeline/event/slots.rb +18 -0
- data/lib/stimulus_plumbers/components/timeline/event.rb +189 -0
- data/lib/stimulus_plumbers/components/timeline/group.rb +42 -0
- data/lib/stimulus_plumbers/components/timeline.rb +40 -0
- data/lib/stimulus_plumbers/engine.rb +1 -0
- data/lib/stimulus_plumbers/form/base.rb +103 -0
- data/lib/stimulus_plumbers/form/builder.rb +78 -23
- data/lib/stimulus_plumbers/form/field.rb +55 -88
- data/lib/stimulus_plumbers/form/fields/error.rb +1 -1
- data/lib/stimulus_plumbers/form/fields/fieldset.rb +11 -8
- data/lib/stimulus_plumbers/form/fields/hint.rb +1 -1
- data/lib/stimulus_plumbers/form/fields/inputs/checkbox.rb +115 -0
- data/lib/stimulus_plumbers/form/fields/inputs/combobox.rb +24 -0
- data/lib/stimulus_plumbers/form/fields/inputs/datetime.rb +52 -58
- data/lib/stimulus_plumbers/form/fields/inputs/file.rb +15 -9
- data/lib/stimulus_plumbers/form/fields/inputs/password.rb +46 -28
- data/lib/stimulus_plumbers/form/fields/inputs/radio.rb +72 -0
- data/lib/stimulus_plumbers/form/fields/inputs/search.rb +73 -65
- data/lib/stimulus_plumbers/form/fields/inputs/select/grouped.rb +22 -33
- data/lib/stimulus_plumbers/form/fields/inputs/select/timezone.rb +3 -46
- data/lib/stimulus_plumbers/form/fields/inputs/select/weekday.rb +3 -26
- data/lib/stimulus_plumbers/form/fields/inputs/select.rb +64 -61
- data/lib/stimulus_plumbers/form/fields/inputs/submit.rb +10 -7
- data/lib/stimulus_plumbers/form/fields/inputs/text.rb +34 -22
- data/lib/stimulus_plumbers/form/fields/inputs/text_area.rb +15 -9
- data/lib/stimulus_plumbers/form/fields/label/floating.rb +41 -0
- data/lib/stimulus_plumbers/form/fields/label.rb +9 -3
- data/lib/stimulus_plumbers/form/fields/renderer.rb +39 -0
- data/lib/stimulus_plumbers/helpers/button_helper.rb +1 -1
- data/lib/stimulus_plumbers/helpers/calendar_helper.rb +2 -2
- data/lib/stimulus_plumbers/helpers/calendar_turbo_helper.rb +76 -4
- data/lib/stimulus_plumbers/helpers/card_helper.rb +1 -11
- data/lib/stimulus_plumbers/helpers/combobox_helper.rb +27 -60
- data/lib/stimulus_plumbers/helpers/icon_helper.rb +11 -0
- data/lib/stimulus_plumbers/helpers/link_helper.rb +11 -0
- data/lib/stimulus_plumbers/helpers/list_helper.rb +11 -0
- data/lib/stimulus_plumbers/helpers/plumber_helper.rb +3 -6
- data/lib/stimulus_plumbers/helpers/timeline_helper.rb +15 -0
- data/lib/stimulus_plumbers/helpers.rb +8 -2
- data/lib/stimulus_plumbers/logger.rb +4 -3
- data/lib/stimulus_plumbers/plumber/base.rb +6 -1
- data/lib/stimulus_plumbers/plumber/dispatcher/klass_proxy.rb +4 -3
- data/lib/stimulus_plumbers/plumber/dispatcher/method_call.rb +4 -3
- data/lib/stimulus_plumbers/plumber/dispatcher.rb +4 -4
- data/lib/stimulus_plumbers/plumber/options/aria.rb +17 -0
- data/lib/stimulus_plumbers/plumber/options/html.rb +29 -0
- data/lib/stimulus_plumbers/plumber/options/stimulus.rb +29 -0
- data/lib/stimulus_plumbers/plumber/options/theme.rb +19 -0
- data/lib/stimulus_plumbers/plumber/options/token_list.rb +29 -0
- data/lib/stimulus_plumbers/plumber/renderer.rb +136 -41
- data/lib/stimulus_plumbers/plumber/slots.rb +74 -0
- data/lib/stimulus_plumbers/themes/base.rb +6 -7
- data/lib/stimulus_plumbers/themes/schema/avatar/ranges.rb +13 -0
- data/lib/stimulus_plumbers/themes/schema/button/ranges.rb +16 -0
- data/lib/stimulus_plumbers/themes/schema/card/ranges.rb +13 -0
- data/lib/stimulus_plumbers/themes/schema/form/checkbox/ranges.rb +16 -0
- data/lib/stimulus_plumbers/themes/schema/form/floating/ranges.rb +15 -0
- data/lib/stimulus_plumbers/themes/schema/form/radio/ranges.rb +16 -0
- data/lib/stimulus_plumbers/themes/schema/form/ranges.rb +1 -2
- data/lib/stimulus_plumbers/themes/schema/link/ranges.rb +14 -0
- data/lib/stimulus_plumbers/themes/schema/ranges.rb +1 -5
- data/lib/stimulus_plumbers/themes/schema.rb +169 -51
- data/lib/stimulus_plumbers/version.rb +1 -1
- data/lib/stimulus_plumbers.rb +24 -16
- metadata +48 -16
- data/lib/stimulus_plumbers/components/action_list/item.rb +0 -30
- data/lib/stimulus_plumbers/components/action_list/section.rb +0 -28
- data/lib/stimulus_plumbers/components/action_list.rb +0 -29
- data/lib/stimulus_plumbers/components/calendar/month/turbo/days_of_month.rb +0 -149
- data/lib/stimulus_plumbers/components/calendar/month/turbo/days_of_week.rb +0 -43
- data/lib/stimulus_plumbers/components/calendar/month/turbo.rb +0 -59
- data/lib/stimulus_plumbers/components/card/section.rb +0 -31
- data/lib/stimulus_plumbers/components/combobox/popover.rb +0 -47
- data/lib/stimulus_plumbers/components/combobox/time/drum.rb +0 -43
- data/lib/stimulus_plumbers/components/date_picker/navigation.rb +0 -41
- data/lib/stimulus_plumbers/components/date_picker/navigator.rb +0 -23
- data/lib/stimulus_plumbers/components/popover/builder.rb +0 -25
- data/lib/stimulus_plumbers/form/fields/inputs/choice.rb +0 -69
- data/lib/stimulus_plumbers/helpers/action_list_helper.rb +0 -25
- data/lib/stimulus_plumbers/plumber/html_options.rb +0 -52
|
@@ -7,34 +7,11 @@ module StimulusPlumbers
|
|
|
7
7
|
module Select
|
|
8
8
|
module Weekday
|
|
9
9
|
if ActionView.version >= Gem::Version.new("7.1")
|
|
10
|
-
def weekday_select(attribute, options = {},
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
icon_trailing = options.delete(:icon_trailing) { "chevron-down" }
|
|
14
|
-
icons = { icon_leading: icon_leading, icon_trailing: icon_trailing }
|
|
15
|
-
with_select_field(attribute, options, html_options) do |opts, merged, error|
|
|
16
|
-
if html_native
|
|
17
|
-
super(attribute, opts, merged)
|
|
18
|
-
else
|
|
19
|
-
render_select_dropdown(attribute, opts, merged, err: error, **icons) do
|
|
20
|
-
build_weekday_choices(opts)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
10
|
+
def weekday_select(attribute, options = {}, html_opts = {})
|
|
11
|
+
html_options = merge_html_options(theme.resolve(:form_select), html_opts)
|
|
12
|
+
super(attribute, options, html_options)
|
|
24
13
|
end
|
|
25
14
|
end
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
def build_weekday_choices(opts)
|
|
30
|
-
index_as_value = opts.delete(:index_as_value) { false }
|
|
31
|
-
day_format = opts.delete(:day_format) { :day_names }
|
|
32
|
-
beginning_of_week = opts.delete(:beginning_of_week) { Date.beginning_of_week }
|
|
33
|
-
|
|
34
|
-
day_names = I18n.t("date.#{day_format}")
|
|
35
|
-
choices = day_names.each_with_index.map { |name, i| index_as_value ? [name, i] : [name, name] }
|
|
36
|
-
choices.rotate(Date::DAYS_INTO_WEEK.fetch(beginning_of_week))
|
|
37
|
-
end
|
|
38
15
|
end
|
|
39
16
|
end
|
|
40
17
|
end
|
|
@@ -1,86 +1,89 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "combobox"
|
|
4
|
+
|
|
3
5
|
module StimulusPlumbers
|
|
4
6
|
module Form
|
|
5
7
|
module Fields
|
|
6
8
|
module Inputs
|
|
7
9
|
module Select
|
|
10
|
+
include Combobox
|
|
11
|
+
|
|
8
12
|
def select(attribute, choices = nil, options = {}, html_options = {})
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
icon_trailing = options.delete(:icon_trailing) { "chevron-down" }
|
|
12
|
-
icons = { icon_leading: icon_leading, icon_trailing: icon_trailing }
|
|
13
|
-
with_select_field(attribute, options, html_options) do |opts, merged, error|
|
|
14
|
-
if html_native
|
|
15
|
-
super(attribute, choices, opts, merged)
|
|
16
|
-
else
|
|
17
|
-
render_select_dropdown(attribute, opts, merged, err: error, **icons) do
|
|
18
|
-
Array(choices)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
13
|
+
merged = merge_html_options(theme.resolve(:form_field_input_select), html_options)
|
|
14
|
+
super(attribute, choices, options, merged)
|
|
22
15
|
end
|
|
23
16
|
|
|
24
|
-
def collection_select(
|
|
25
|
-
|
|
26
|
-
collection,
|
|
27
|
-
value_method,
|
|
28
|
-
text_method,
|
|
29
|
-
options = {},
|
|
30
|
-
html_options = {}
|
|
31
|
-
)
|
|
32
|
-
html_native = options.delete(:html_native) { false }
|
|
33
|
-
icon_leading = options.delete(:icon_leading)
|
|
34
|
-
icon_trailing = options.delete(:icon_trailing) { "chevron-down" }
|
|
35
|
-
icons = { icon_leading: icon_leading, icon_trailing: icon_trailing }
|
|
36
|
-
with_select_field(attribute, options, html_options) do |opts, merged, error|
|
|
37
|
-
if html_native
|
|
38
|
-
super(attribute, collection, value_method, text_method, opts, merged)
|
|
39
|
-
else
|
|
40
|
-
render_select_dropdown(attribute, opts, merged, err: error, **icons) do
|
|
41
|
-
collection.map { |item| [item.public_send(text_method), item.public_send(value_method)] }
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
17
|
+
def collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {})
|
|
18
|
+
merged = merge_html_options(theme.resolve(:form_field_input_select), html_options)
|
|
19
|
+
super(attribute, collection, value_method, text_method, options, merged)
|
|
45
20
|
end
|
|
46
21
|
|
|
47
22
|
private
|
|
48
23
|
|
|
49
|
-
def
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
24
|
+
def render_combobox_dropdown(
|
|
25
|
+
attribute,
|
|
26
|
+
html_opts,
|
|
27
|
+
opts,
|
|
28
|
+
error,
|
|
29
|
+
floating: nil,
|
|
30
|
+
icon_leading: nil,
|
|
31
|
+
icon_trailing: nil,
|
|
32
|
+
choices: [],
|
|
33
|
+
include_blank: nil,
|
|
34
|
+
prompt: nil,
|
|
35
|
+
selected: nil,
|
|
36
|
+
**kwargs
|
|
37
|
+
)
|
|
38
|
+
current_value = selected || (object.respond_to?(attribute) ? object.public_send(attribute) : nil)
|
|
39
|
+
all_choices = build_select_dropdown_choices(Array(choices), include_blank: include_blank, prompt: prompt)
|
|
40
|
+
labelledby = Field.label_id(html_opts[:id])
|
|
60
41
|
combobox_opts = build_select_dropdown_opts(
|
|
61
|
-
html_opts,
|
|
62
|
-
current_value,
|
|
63
|
-
icon_leading: icon_leading,
|
|
64
|
-
icon_trailing: icon_trailing
|
|
42
|
+
html_opts, current_value, opts: opts, icon_leading: icon_leading, icon_trailing: icon_trailing
|
|
65
43
|
)
|
|
66
|
-
render_combobox(
|
|
67
|
-
|
|
44
|
+
render_combobox(
|
|
45
|
+
attribute,
|
|
46
|
+
input_id: html_opts[:id],
|
|
47
|
+
opts: combobox_opts,
|
|
48
|
+
error: error,
|
|
49
|
+
floating: floating
|
|
50
|
+
) do |c|
|
|
51
|
+
c.dropdown(options: all_choices, value: current_value, labelledby: labelledby, **kwargs)
|
|
68
52
|
end
|
|
69
53
|
end
|
|
70
54
|
|
|
71
|
-
def
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
55
|
+
def render_collection_combobox_dropdown(
|
|
56
|
+
attribute,
|
|
57
|
+
collection,
|
|
58
|
+
value_method,
|
|
59
|
+
text_method,
|
|
60
|
+
field_opts,
|
|
61
|
+
**kwargs
|
|
62
|
+
)
|
|
63
|
+
choices = collection.map { |item| [item.public_send(text_method), item.public_send(value_method)] }
|
|
64
|
+
render_field(:select, attribute, field_opts, { choices: choices, **kwargs })
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def render_grouped_collection_combobox_dropdown(
|
|
68
|
+
attribute,
|
|
69
|
+
collection,
|
|
70
|
+
value_method,
|
|
71
|
+
text_method,
|
|
72
|
+
field_opts,
|
|
73
|
+
group_method:,
|
|
74
|
+
group_label_method:,
|
|
75
|
+
**kwargs
|
|
76
|
+
)
|
|
77
|
+
choices = build_grouped_choices(collection, group_label_method, group_method, value_method, text_method)
|
|
78
|
+
render_field(:select, attribute, field_opts, { choices: choices, **kwargs })
|
|
77
79
|
end
|
|
78
80
|
|
|
79
|
-
def build_select_dropdown_opts(html_opts, current_value, icon_leading:, icon_trailing:)
|
|
80
|
-
|
|
81
|
+
def build_select_dropdown_opts(html_opts, current_value, opts:, icon_leading:, icon_trailing:)
|
|
82
|
+
{
|
|
81
83
|
input: { value: current_value },
|
|
82
|
-
trigger:
|
|
83
|
-
|
|
84
|
+
trigger: { aria: html_opts[:aria], icon_leading: icon_leading, icon_trailing: icon_trailing }.compact,
|
|
85
|
+
**opts
|
|
86
|
+
}
|
|
84
87
|
end
|
|
85
88
|
|
|
86
89
|
def build_select_dropdown_choices(choices, include_blank:, prompt:)
|
|
@@ -10,13 +10,16 @@ module StimulusPlumbers
|
|
|
10
10
|
options = value
|
|
11
11
|
value = nil
|
|
12
12
|
end
|
|
13
|
-
value
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
value ||= submit_default_value
|
|
14
|
+
type = options.delete(:type) { :default }
|
|
15
|
+
variant = options.delete(:variant) { :primary }
|
|
16
|
+
|
|
17
|
+
Components::Button.new(@template).build(type: type, variant: variant) do |attrs|
|
|
18
|
+
@template.tag.button(
|
|
19
|
+
type: "submit",
|
|
20
|
+
**merge_html_options(attrs, theme.resolve(:form_submit, type: type, variant: variant), options)
|
|
21
|
+
) { @template.content_tag(:span, value) }
|
|
22
|
+
end
|
|
20
23
|
end
|
|
21
24
|
end
|
|
22
25
|
end
|
|
@@ -5,31 +5,43 @@ module StimulusPlumbers
|
|
|
5
5
|
module Fields
|
|
6
6
|
module Inputs
|
|
7
7
|
module Text
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
TEXT_FIELD_METHODS = {
|
|
9
|
+
text: :text_field,
|
|
10
|
+
email: :email_field,
|
|
11
|
+
number: :number_field,
|
|
12
|
+
url: :url_field,
|
|
13
|
+
tel: :telephone_field,
|
|
14
|
+
color: :color_field,
|
|
15
|
+
month: :month_field,
|
|
16
|
+
week: :week_field,
|
|
17
|
+
range: :range_field,
|
|
18
|
+
datetime_local: :datetime_local_field
|
|
19
|
+
}.freeze
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
define_method(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
attribute,
|
|
26
|
-
input_id: field_id(attribute)
|
|
27
|
-
) do |html_opts, opts, error|
|
|
28
|
-
html_options = merge_html_options(opts, html_opts, field_theme(:form_input, error: error))
|
|
29
|
-
super(attribute, html_options)
|
|
30
|
-
end
|
|
21
|
+
TEXT_FIELD_METHODS.each_value do |template_method|
|
|
22
|
+
define_method(template_method) do |attribute, floating: nil, **options|
|
|
23
|
+
html_options = merge_html_options(theme.resolve(:form_field_input, floating: floating), options)
|
|
24
|
+
super(attribute, html_options)
|
|
31
25
|
end
|
|
32
26
|
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
TEXT_FIELD_METHODS.each do |as_key, template_method|
|
|
31
|
+
define_method(:"render_#{as_key}_input") do |attribute, html_opts, opts, error, **kwargs|
|
|
32
|
+
render_text(attribute, html_opts, opts, error, template_method, **kwargs)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def render_text(attribute, html_opts, opts, error, template_method, floating: nil, **kwargs)
|
|
37
|
+
html_options = merge_html_options(
|
|
38
|
+
theme.resolve(:form_field_input, floating: floating, error: error),
|
|
39
|
+
opts,
|
|
40
|
+
html_opts,
|
|
41
|
+
kwargs
|
|
42
|
+
)
|
|
43
|
+
@template.public_send(template_method, @object_name, attribute, objectify_options(html_options))
|
|
44
|
+
end
|
|
33
45
|
end
|
|
34
46
|
end
|
|
35
47
|
end
|
|
@@ -5,15 +5,21 @@ module StimulusPlumbers
|
|
|
5
5
|
module Fields
|
|
6
6
|
module Inputs
|
|
7
7
|
module TextArea
|
|
8
|
-
def text_area(attribute,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
def text_area(attribute, floating: nil, **options)
|
|
9
|
+
html_options = merge_html_options(theme.resolve(:form_field_input_textarea, floating: floating), options)
|
|
10
|
+
super(attribute, html_options)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def render_text_area_input(attribute, html_opts, opts, error, floating: nil, **kwargs)
|
|
16
|
+
html_options = merge_html_options(
|
|
17
|
+
theme.resolve(:form_field_input_textarea, floating: floating, error: error),
|
|
18
|
+
opts,
|
|
19
|
+
html_opts,
|
|
20
|
+
kwargs
|
|
21
|
+
)
|
|
22
|
+
@template.text_area(@object_name, attribute, objectify_options(html_options))
|
|
17
23
|
end
|
|
18
24
|
end
|
|
19
25
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StimulusPlumbers
|
|
4
|
+
module Form
|
|
5
|
+
module Fields
|
|
6
|
+
class Label
|
|
7
|
+
class Floating < Plumber::Base
|
|
8
|
+
def render(text:, for_id:, id:, floating:, required:, error:, &block)
|
|
9
|
+
html_options = merge_html_options(theme.resolve(:form_field_input_group, floating: floating))
|
|
10
|
+
label_options = merge_html_options(theme.resolve(:form_field_label, floating: floating, error: error))
|
|
11
|
+
mark_options = required && merge_html_options(
|
|
12
|
+
{ aria: { hidden: true } },
|
|
13
|
+
theme.resolve(:form_field_required_mark)
|
|
14
|
+
)
|
|
15
|
+
template.content_tag(:div, **html_options) do
|
|
16
|
+
template.safe_join(
|
|
17
|
+
[
|
|
18
|
+
template.capture(&block),
|
|
19
|
+
render_label(text, mark_options, for: for_id, id: id, **label_options)
|
|
20
|
+
]
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def render_label(text, mark_options, **html_options)
|
|
28
|
+
template.content_tag(:label, **html_options) do
|
|
29
|
+
template.safe_join(
|
|
30
|
+
[
|
|
31
|
+
text,
|
|
32
|
+
mark_options ? template.content_tag(:span, "*", **mark_options) : nil
|
|
33
|
+
]
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -7,10 +7,16 @@ module StimulusPlumbers
|
|
|
7
7
|
def render(text:, for_id: nil, id: nil, required: false, hidden: false, tag: :label)
|
|
8
8
|
mark_options = required && merge_html_options(
|
|
9
9
|
{ aria: { hidden: true } },
|
|
10
|
-
theme.resolve(:
|
|
10
|
+
theme.resolve(:form_field_required_mark)
|
|
11
11
|
)
|
|
12
|
-
html_options = merge_html_options(theme.resolve(:
|
|
13
|
-
|
|
12
|
+
html_options = merge_html_options(theme.resolve(:form_field_label, required: required, hidden: hidden))
|
|
13
|
+
render_label(text, mark_options, tag, for: for_id, id: id, **html_options)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def render_label(text, mark_options, tag, **html_options)
|
|
19
|
+
template.content_tag(tag, **html_options) do
|
|
14
20
|
template.safe_join(
|
|
15
21
|
[
|
|
16
22
|
text,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StimulusPlumbers
|
|
4
|
+
module Form
|
|
5
|
+
module Fields
|
|
6
|
+
module Renderer
|
|
7
|
+
FIELD = {
|
|
8
|
+
text: :render_text_input,
|
|
9
|
+
email: :render_email_input,
|
|
10
|
+
number: :render_number_input,
|
|
11
|
+
url: :render_url_input,
|
|
12
|
+
tel: :render_tel_input,
|
|
13
|
+
color: :render_color_input,
|
|
14
|
+
month: :render_month_input,
|
|
15
|
+
week: :render_week_input,
|
|
16
|
+
range: :render_range_input,
|
|
17
|
+
datetime_local: :render_datetime_local_input,
|
|
18
|
+
text_area: :render_text_area_input,
|
|
19
|
+
file: :render_file_input,
|
|
20
|
+
password: :render_password_input,
|
|
21
|
+
date: :render_combobox_date,
|
|
22
|
+
time: :render_combobox_time,
|
|
23
|
+
select: :render_combobox_dropdown,
|
|
24
|
+
search: :render_combobox_typeahead
|
|
25
|
+
}.freeze
|
|
26
|
+
|
|
27
|
+
COLLECTION = {
|
|
28
|
+
collection_select: :render_collection_combobox_dropdown,
|
|
29
|
+
grouped_collection_select: :render_grouped_collection_combobox_dropdown
|
|
30
|
+
}.freeze
|
|
31
|
+
|
|
32
|
+
CHOICE = {
|
|
33
|
+
radio: :render_collection_radio_button,
|
|
34
|
+
check_box: :render_check_box
|
|
35
|
+
}.freeze
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module StimulusPlumbers
|
|
4
4
|
module Helpers
|
|
5
5
|
module CalendarHelper
|
|
6
|
-
def sp_calendar_month(**kwargs
|
|
6
|
+
def sp_calendar_month(**kwargs)
|
|
7
7
|
date = kwargs.delete(:date)
|
|
8
8
|
html_options = if date
|
|
9
9
|
kwargs.deep_merge(
|
|
@@ -16,7 +16,7 @@ module StimulusPlumbers
|
|
|
16
16
|
else
|
|
17
17
|
kwargs
|
|
18
18
|
end
|
|
19
|
-
calendar_renderer.month(**html_options
|
|
19
|
+
calendar_renderer.month(**html_options)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
private
|
|
@@ -3,14 +3,86 @@
|
|
|
3
3
|
module StimulusPlumbers
|
|
4
4
|
module Helpers
|
|
5
5
|
module CalendarTurboHelper
|
|
6
|
-
def
|
|
7
|
-
|
|
6
|
+
def sp_calendar_turbo_month(**kwargs)
|
|
7
|
+
calendar_turbo_renderer.month(**kwargs)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def sp_calendar_turbo_year(**kwargs)
|
|
11
|
+
calendar_turbo_renderer.year(**kwargs)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def sp_calendar_turbo_decade(**kwargs)
|
|
15
|
+
calendar_turbo_renderer.decade(**kwargs)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def sp_calendar_turbo(
|
|
19
|
+
date: Date.today,
|
|
20
|
+
today: Date.today,
|
|
21
|
+
selectable: false,
|
|
22
|
+
selected_date: nil,
|
|
23
|
+
show_other_months: false,
|
|
24
|
+
since: nil,
|
|
25
|
+
till: nil,
|
|
26
|
+
disabled_months: [],
|
|
27
|
+
disabled_years: [],
|
|
28
|
+
**kwargs
|
|
29
|
+
)
|
|
30
|
+
safe_join(
|
|
31
|
+
[
|
|
32
|
+
content_tag(
|
|
33
|
+
:turbo_frame,
|
|
34
|
+
id: "calendar-month-frame",
|
|
35
|
+
data: { "combobox-date-target": "monthView" }
|
|
36
|
+
) do
|
|
37
|
+
calendar_turbo_renderer.month(
|
|
38
|
+
date: date,
|
|
39
|
+
today: today,
|
|
40
|
+
selectable: selectable,
|
|
41
|
+
selected_date: selected_date,
|
|
42
|
+
show_other_months: show_other_months,
|
|
43
|
+
since: since,
|
|
44
|
+
till: till,
|
|
45
|
+
**kwargs
|
|
46
|
+
)
|
|
47
|
+
end,
|
|
48
|
+
content_tag(
|
|
49
|
+
:turbo_frame,
|
|
50
|
+
id: "calendar-year-frame",
|
|
51
|
+
hidden: true,
|
|
52
|
+
data: { "combobox-date-target": "yearView" }
|
|
53
|
+
) do
|
|
54
|
+
calendar_turbo_renderer.year(
|
|
55
|
+
date: date,
|
|
56
|
+
today: today,
|
|
57
|
+
selected_date: selected_date,
|
|
58
|
+
since: since,
|
|
59
|
+
till: till,
|
|
60
|
+
disabled_months: disabled_months
|
|
61
|
+
)
|
|
62
|
+
end,
|
|
63
|
+
content_tag(
|
|
64
|
+
:turbo_frame,
|
|
65
|
+
id: "calendar-decade-frame",
|
|
66
|
+
hidden: true,
|
|
67
|
+
data: { "combobox-date-target": "decadeView" }
|
|
68
|
+
) do
|
|
69
|
+
calendar_turbo_renderer.decade(
|
|
70
|
+
date: date,
|
|
71
|
+
today: today,
|
|
72
|
+
selected_date: selected_date,
|
|
73
|
+
since: since,
|
|
74
|
+
till: till,
|
|
75
|
+
disabled_years: disabled_years
|
|
76
|
+
)
|
|
77
|
+
end
|
|
78
|
+
]
|
|
79
|
+
)
|
|
8
80
|
end
|
|
9
81
|
|
|
10
82
|
private
|
|
11
83
|
|
|
12
|
-
def
|
|
13
|
-
Components::Calendar::
|
|
84
|
+
def calendar_turbo_renderer
|
|
85
|
+
@calendar_turbo_renderer ||= Components::Calendar::Turbo.new(self)
|
|
14
86
|
end
|
|
15
87
|
end
|
|
16
88
|
end
|
|
@@ -4,17 +4,7 @@ module StimulusPlumbers
|
|
|
4
4
|
module Helpers
|
|
5
5
|
module CardHelper
|
|
6
6
|
def sp_card(...)
|
|
7
|
-
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def sp_card_section(...)
|
|
11
|
-
card_renderer.section(...)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
def card_renderer
|
|
17
|
-
Components::Card.new(self)
|
|
7
|
+
Components::Card.new(self).render(...)
|
|
18
8
|
end
|
|
19
9
|
end
|
|
20
10
|
end
|
|
@@ -3,76 +3,43 @@
|
|
|
3
3
|
module StimulusPlumbers
|
|
4
4
|
module Helpers
|
|
5
5
|
module ComboboxHelper
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
value = kwargs.delete(:value)
|
|
9
|
-
id = sp_dom_id
|
|
10
|
-
opts = Components::Combobox::Date.default_opts.deep_merge(
|
|
11
|
-
input: { value: value },
|
|
12
|
-
trigger: { id: id, aria: ({ label: label } if label), icon_trailing: "calendar" }.compact
|
|
13
|
-
)
|
|
6
|
+
# Single entry point; panel type chosen by a block method (c.dropdown/date/...).
|
|
7
|
+
def sp_combobox(value: nil, label: nil, id: nil, close_on_select: nil, **kwargs, &block)
|
|
14
8
|
Components::Combobox.new(self).render(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
id: id || sp_dom_id,
|
|
10
|
+
label: label,
|
|
11
|
+
input: { value: value },
|
|
12
|
+
close_on_select: close_on_select,
|
|
13
|
+
**kwargs,
|
|
14
|
+
&block
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def sp_combobox_date(value: nil, label: nil, **kwargs)
|
|
19
|
+
sp_combobox(value: value, label: label, **kwargs) do |c|
|
|
20
|
+
panel_opts = { value: value }
|
|
21
|
+
panel_opts[:label] = label if label
|
|
22
|
+
c.date(**panel_opts)
|
|
20
23
|
end
|
|
21
24
|
end
|
|
22
25
|
|
|
23
|
-
def sp_combobox_dropdown(**kwargs)
|
|
24
|
-
label
|
|
25
|
-
|
|
26
|
-
options = kwargs.delete(:options) { [] }
|
|
27
|
-
id = sp_dom_id
|
|
28
|
-
opts = Components::Combobox::Dropdown.default_opts.deep_merge(
|
|
29
|
-
input: { value: value },
|
|
30
|
-
trigger: { id: id, aria: ({ label: label } if label), icon_trailing: "chevron-down" }.compact
|
|
31
|
-
)
|
|
32
|
-
Components::Combobox.new(self).render(**opts, **kwargs) do
|
|
33
|
-
Components::Combobox::Dropdown.new(self).render(options: options, value: value, label: label)
|
|
26
|
+
def sp_combobox_dropdown(options: [], value: nil, label: nil, **kwargs)
|
|
27
|
+
sp_combobox(value: value, label: label, **kwargs) do |c|
|
|
28
|
+
c.dropdown(options: options, value: value, label: label)
|
|
34
29
|
end
|
|
35
30
|
end
|
|
36
31
|
|
|
37
|
-
def sp_combobox_typeahead(**kwargs)
|
|
38
|
-
label
|
|
39
|
-
|
|
40
|
-
options = kwargs.delete(:options) { [] }
|
|
41
|
-
url = kwargs.delete(:url)
|
|
42
|
-
id = sp_dom_id
|
|
43
|
-
opts = Components::Combobox::Typeahead.default_opts.deep_merge(
|
|
44
|
-
input: { value: value },
|
|
45
|
-
trigger: { id: id, aria: ({ label: label } if label) }.compact,
|
|
46
|
-
popover: { data: url ? { combobox_dropdown_url_value: url } : {} }
|
|
47
|
-
)
|
|
48
|
-
Components::Combobox.new(self).render(
|
|
49
|
-
**opts,
|
|
50
|
-
data: {
|
|
51
|
-
input_combobox_combobox_dropdown_outlet: "##{Components::Combobox.popover_id_for(id)}",
|
|
52
|
-
action: "input->input-combobox#onInput"
|
|
53
|
-
},
|
|
54
|
-
**kwargs
|
|
55
|
-
) do
|
|
56
|
-
Components::Combobox::Typeahead.new(self).render(options: options, value: value, label: label)
|
|
32
|
+
def sp_combobox_typeahead(options: [], value: nil, label: nil, url: nil, **kwargs)
|
|
33
|
+
sp_combobox(value: value, label: label, **kwargs) do |c|
|
|
34
|
+
c.typeahead(options: options, value: value, label: label, url: url)
|
|
57
35
|
end
|
|
58
36
|
end
|
|
59
37
|
|
|
60
|
-
def sp_combobox_time(**kwargs)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
id = sp_dom_id
|
|
66
|
-
opts = Components::Combobox::Time.default_opts.deep_merge(
|
|
67
|
-
input: { value: value },
|
|
68
|
-
trigger: { id: id, aria: ({ label: label } if label), icon_trailing: "clock" }.compact
|
|
69
|
-
)
|
|
70
|
-
Components::Combobox.new(self).render(
|
|
71
|
-
**opts,
|
|
72
|
-
data: { input_formatter_format_value: "time", input_formatter_options_value: { format: format }.to_json },
|
|
73
|
-
**kwargs
|
|
74
|
-
) do
|
|
75
|
-
Components::Combobox::Time.new(self).render(format: format, step: step, value: value)
|
|
38
|
+
def sp_combobox_time(format: :h12, step: 1, value: nil, label: nil, **kwargs)
|
|
39
|
+
sp_combobox(value: value, label: label, **kwargs) do |c|
|
|
40
|
+
panel_opts = { format: format, step: step, value: value }
|
|
41
|
+
panel_opts[:label] = label if label
|
|
42
|
+
c.time(**panel_opts)
|
|
76
43
|
end
|
|
77
44
|
end
|
|
78
45
|
end
|