vcfb 1.0.0 → 2.0.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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +30 -0
  4. data/lib/generators/vcfb/components/components_generator.rb +5 -0
  5. data/lib/generators/vcfb/components/templates/button/component.html.erb +1 -1
  6. data/lib/generators/vcfb/components/templates/button/component.rb.tt +1 -12
  7. data/lib/generators/vcfb/components/templates/check_box/component.rb.tt +1 -14
  8. data/lib/generators/vcfb/components/templates/collection_check_boxes/check_box/component.rb.tt +1 -14
  9. data/lib/generators/vcfb/components/templates/collection_check_boxes/component.html.erb +1 -1
  10. data/lib/generators/vcfb/components/templates/collection_check_boxes/component.rb.tt +1 -24
  11. data/lib/generators/vcfb/components/templates/collection_check_boxes/label/component.html.erb +1 -1
  12. data/lib/generators/vcfb/components/templates/collection_check_boxes/label/component.rb.tt +1 -14
  13. data/lib/generators/vcfb/components/templates/collection_radio_buttons/component.html.erb +1 -1
  14. data/lib/generators/vcfb/components/templates/collection_radio_buttons/component.rb.tt +1 -24
  15. data/lib/generators/vcfb/components/templates/collection_radio_buttons/label/component.html.erb +1 -1
  16. data/lib/generators/vcfb/components/templates/collection_radio_buttons/label/component.rb.tt +1 -14
  17. data/lib/generators/vcfb/components/templates/collection_radio_buttons/radio_button/component.rb.tt +1 -13
  18. data/lib/generators/vcfb/components/templates/collection_select/component.rb.tt +1 -16
  19. data/lib/generators/vcfb/components/templates/color_field/component.rb.tt +1 -12
  20. data/lib/generators/vcfb/components/templates/component.html.erb +3 -0
  21. data/lib/generators/vcfb/components/templates/component.rb.tt +4 -0
  22. data/lib/generators/vcfb/components/templates/date_field/component.rb.tt +1 -12
  23. data/lib/generators/vcfb/components/templates/date_select/component.rb.tt +1 -13
  24. data/lib/generators/vcfb/components/templates/datetime_field/component.rb.tt +1 -12
  25. data/lib/generators/vcfb/components/templates/datetime_select/component.rb.tt +1 -13
  26. data/lib/generators/vcfb/components/templates/email_field/component.rb.tt +1 -12
  27. data/lib/generators/vcfb/components/templates/file_field/component.rb.tt +1 -12
  28. data/lib/generators/vcfb/components/templates/grouped_collection_select/component.rb.tt +1 -18
  29. data/lib/generators/vcfb/components/templates/label/component.html.erb +1 -1
  30. data/lib/generators/vcfb/components/templates/label/component.rb.tt +1 -14
  31. data/lib/generators/vcfb/components/templates/month_field/component.rb.tt +1 -12
  32. data/lib/generators/vcfb/components/templates/number_field/component.rb.tt +1 -12
  33. data/lib/generators/vcfb/components/templates/password_field/component.rb.tt +1 -12
  34. data/lib/generators/vcfb/components/templates/radio_button/component.rb.tt +1 -13
  35. data/lib/generators/vcfb/components/templates/range_field/component.rb.tt +1 -12
  36. data/lib/generators/vcfb/components/templates/rich_text_area/component.rb.tt +1 -12
  37. data/lib/generators/vcfb/components/templates/search_field/component.rb.tt +1 -12
  38. data/lib/generators/vcfb/components/templates/select/component.rb.tt +1 -18
  39. data/lib/generators/vcfb/components/templates/submit/component.rb.tt +1 -12
  40. data/lib/generators/vcfb/components/templates/telephone_field/component.rb.tt +1 -12
  41. data/lib/generators/vcfb/components/templates/text_area/component.rb.tt +1 -12
  42. data/lib/generators/vcfb/components/templates/text_field/component.rb.tt +1 -12
  43. data/lib/generators/vcfb/components/templates/time_field/component.rb.tt +1 -12
  44. data/lib/generators/vcfb/components/templates/time_select/component.rb.tt +1 -13
  45. data/lib/generators/vcfb/components/templates/time_zone_select/component.rb.tt +1 -14
  46. data/lib/generators/vcfb/components/templates/url_field/component.rb.tt +1 -12
  47. data/lib/generators/vcfb/components/templates/week_field/component.rb.tt +1 -12
  48. data/lib/generators/vcfb/components/templates/weekday_select/component.rb.tt +1 -13
  49. data/lib/generators/vcfb/initializer/initializer_generator.rb +12 -0
  50. data/lib/generators/vcfb/initializer/template/vcfb.rb.tt +3 -0
  51. data/lib/vcfb/component/base.rb +27 -0
  52. data/lib/vcfb/component/base_collection.rb +16 -0
  53. data/lib/vcfb/component/button.rb +17 -0
  54. data/lib/vcfb/component/check_box.rb +19 -0
  55. data/lib/vcfb/component/collection_check_boxes.rb +36 -0
  56. data/lib/vcfb/component/collection_radio_buttons.rb +36 -0
  57. data/lib/vcfb/component/collection_select.rb +21 -0
  58. data/lib/vcfb/component/color_field.rb +17 -0
  59. data/lib/vcfb/component/date_field.rb +17 -0
  60. data/lib/vcfb/component/date_select.rb +18 -0
  61. data/lib/vcfb/component/datetime_field.rb +17 -0
  62. data/lib/vcfb/component/datetime_select.rb +18 -0
  63. data/lib/vcfb/component/email_field.rb +17 -0
  64. data/lib/vcfb/component/file_field.rb +17 -0
  65. data/lib/vcfb/component/form.rb +40 -0
  66. data/lib/vcfb/component/grouped_collection_select.rb +23 -0
  67. data/lib/vcfb/component/label.rb +28 -0
  68. data/lib/vcfb/component/month_field.rb +17 -0
  69. data/lib/vcfb/component/number_field.rb +17 -0
  70. data/lib/vcfb/component/password_field.rb +17 -0
  71. data/lib/vcfb/component/radio_button.rb +18 -0
  72. data/lib/vcfb/component/range_field.rb +17 -0
  73. data/lib/vcfb/component/rich_text_area.rb +17 -0
  74. data/lib/vcfb/component/search_field.rb +17 -0
  75. data/lib/vcfb/component/select.rb +23 -0
  76. data/lib/vcfb/component/submit.rb +17 -0
  77. data/lib/vcfb/component/telephone_field.rb +17 -0
  78. data/lib/vcfb/component/text_area.rb +17 -0
  79. data/lib/vcfb/component/text_field.rb +17 -0
  80. data/lib/vcfb/component/time_field.rb +17 -0
  81. data/lib/vcfb/component/time_select.rb +18 -0
  82. data/lib/vcfb/component/time_zone_select.rb +19 -0
  83. data/lib/vcfb/component/url_field.rb +17 -0
  84. data/lib/vcfb/component/week_field.rb +17 -0
  85. data/lib/vcfb/component/weekday_select.rb +18 -0
  86. data/lib/vcfb/errors/component_missing.rb +5 -0
  87. data/lib/vcfb/errors/error.rb +5 -0
  88. data/lib/vcfb/form_builder.rb +56 -19
  89. data/lib/vcfb/form_helper.rb +12 -0
  90. data/lib/vcfb/railtie.rb +7 -0
  91. data/lib/vcfb/resolver.rb +8 -6
  92. data/lib/vcfb/tags/collection_check_boxes.rb +2 -2
  93. data/lib/vcfb/tags/collection_helpers.rb +0 -2
  94. data/lib/vcfb/tags/collection_radio_buttons.rb +2 -2
  95. data/lib/vcfb/template.rb +8 -6
  96. data/lib/vcfb/version.rb +1 -1
  97. data/lib/vcfb.rb +68 -10
  98. metadata +44 -5
  99. data/lib/vcfb/acts_as_form_collection_component.rb +0 -19
  100. data/lib/vcfb/acts_as_form_component.rb +0 -22
  101. data/lib/vcfb/acts_as_form_label_component.rb +0 -21
@@ -1,17 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module RichTextArea
3
- class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
- include VCFB::ActsAsFormComponent
5
-
6
- def initialize(form, method, options = {})
7
- @form = form
8
- @method = method
9
- @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
- end
11
-
12
- def form_element(options = {})
13
- rich_text_area(@form.object_name, @method, options)
14
- end
3
+ class Component < VCFB::Component::RichTextArea
15
4
  end
16
5
  end
17
6
  <% end -%>
@@ -1,17 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module SearchField
3
- class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
- include VCFB::ActsAsFormComponent
5
-
6
- def initialize(form, method, options = {})
7
- @form = form
8
- @method = method
9
- @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
- end
11
-
12
- def form_element(options = {})
13
- search_field(@form.object_name, @method, options)
14
- end
3
+ class Component < VCFB::Component::SearchField
15
4
  end
16
5
  end
17
6
  <% end -%>
@@ -1,23 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module Select
3
- class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
- include VCFB::ActsAsFormComponent
5
-
6
- def initialize(form, method, choices = nil, options = {}, html_options = {})
7
- @form = form
8
- @method = method
9
- @choices = choices
10
- @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
11
- @html_options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(html_options)" : "html_options" %>
12
- end
13
-
14
- def before_render
15
- @choices = content if content.present?
16
- end
17
-
18
- def form_element(options = {}, html_options = {})
19
- select(@form.object_name, @method, @choices, options, html_options)
20
- end
3
+ class Component < VCFB::Component::Select
21
4
  end
22
5
  end
23
6
  <% end -%>
@@ -1,17 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module Submit
3
- class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
- include VCFB::ActsAsFormComponent
5
-
6
- def initialize(form, text = nil, options = {})
7
- @form = form
8
- @text = text
9
- @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
- end
11
-
12
- def form_element(options = {})
13
- submit_tag(@text, options)
14
- end
3
+ class Component < VCFB::Component::Submit
15
4
  end
16
5
  end
17
6
  <% end -%>
@@ -1,17 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module TelephoneField
3
- class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
- include VCFB::ActsAsFormComponent
5
-
6
- def initialize(form, method, options = {})
7
- @form = form
8
- @method = method
9
- @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
- end
11
-
12
- def form_element(options = {})
13
- telephone_field(@form.object_name, @method, options)
14
- end
3
+ class Component < VCFB::Component::TelephoneField
15
4
  end
16
5
  end
17
6
  <% end -%>
@@ -1,17 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module TextArea
3
- class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
- include VCFB::ActsAsFormComponent
5
-
6
- def initialize(form, method, options = {})
7
- @form = form
8
- @method = method
9
- @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
- end
11
-
12
- def form_element(options = {})
13
- text_area(@form.object_name, @method, options)
14
- end
3
+ class Component < VCFB::Component::TextArea
15
4
  end
16
5
  end
17
6
  <% end -%>
@@ -1,17 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module TextField
3
- class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
- include VCFB::ActsAsFormComponent
5
-
6
- def initialize(form, method, options = {})
7
- @form = form
8
- @method = method
9
- @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
- end
11
-
12
- def form_element(options = {})
13
- text_field(@form.object_name, @method, options)
14
- end
3
+ class Component < VCFB::Component::TextField
15
4
  end
16
5
  end
17
6
  <% end -%>
@@ -1,17 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module TimeField
3
- class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
- include VCFB::ActsAsFormComponent
5
-
6
- def initialize(form, method, options = {})
7
- @form = form
8
- @method = method
9
- @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
- end
11
-
12
- def form_element(options = {})
13
- time_field(@form.object_name, @method, options)
14
- end
3
+ class Component < VCFB::Component::TimeField
15
4
  end
16
5
  end
17
6
  <% end -%>
@@ -1,18 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module TimeSelect
3
- class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
- include VCFB::ActsAsFormComponent
5
-
6
- def initialize(form, method, options = {}, html_options = {})
7
- @form = form
8
- @method = method
9
- @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
- @html_options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(html_options)" : "html_options" %>
11
- end
12
-
13
- def form_element(options = {}, html_options = {})
14
- time_select(@form.object_name, @method, options, html_options)
15
- end
3
+ class Component < VCFB::Component::TimeSelect
16
4
  end
17
5
  end
18
6
  <% end -%>
@@ -1,19 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module TimeZoneSelect
3
- class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
- include VCFB::ActsAsFormComponent
5
-
6
- def initialize(form, method, priority_zones = nil, options = {}, html_options = {})
7
- @form = form
8
- @method = method
9
- @priority_zones = priority_zones
10
- @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
11
- @html_options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(html_options)" : "html_options" %>
12
- end
13
-
14
- def form_element(options = {}, html_options = {})
15
- time_zone_select(@form.object_name, @method, @priority_zones, options, html_options)
16
- end
3
+ class Component < VCFB::Component::TimeZoneSelect
17
4
  end
18
5
  end
19
6
  <% end -%>
@@ -1,17 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module UrlField
3
- class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
- include VCFB::ActsAsFormComponent
5
-
6
- def initialize(form, method, options = {})
7
- @form = form
8
- @method = method
9
- @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
- end
11
-
12
- def form_element(options = {})
13
- url_field(@form.object_name, @method, options)
14
- end
3
+ class Component < VCFB::Component::UrlField
15
4
  end
16
5
  end
17
6
  <% end -%>
@@ -1,17 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module WeekField
3
- class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
- include VCFB::ActsAsFormComponent
5
-
6
- def initialize(form, method, options = {})
7
- @form = form
8
- @method = method
9
- @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
- end
11
-
12
- def form_element(options = {})
13
- week_field(@form.object_name, @method, options)
14
- end
3
+ class Component < VCFB::Component::WeekField
15
4
  end
16
5
  end
17
6
  <% end -%>
@@ -1,18 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module WeekdaySelect
3
- class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
- include VCFB::ActsAsFormComponent
5
-
6
- def initialize(form, method, options = {}, html_options = {})
7
- @form = form
8
- @method = method
9
- @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
- @html_options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(html_options)" : "html_options" %>
11
- end
12
-
13
- def form_element(options = {}, html_options = {})
14
- weekday_select(@form.object_name, @method, options, html_options)
15
- end
3
+ class Component < VCFB::Component::WeekdaySelect
16
4
  end
17
5
  end
18
6
  <% end -%>
@@ -0,0 +1,12 @@
1
+ require "active_support/core_ext/string/inflections"
2
+ require "rails/generators/base"
3
+
4
+ module Vcfb
5
+ class InitializerGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path("template", __dir__)
7
+
8
+ def create_form_component
9
+ template "vcfb.rb.tt", "config/initializers/vcfb.rb"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ VCFB.configure do |config|
2
+ config.parent_component = <%= defined?(ApplicationComponent) ? '"ApplicationComponent"' : '"ViewComponent::Base"' %>
3
+ end
@@ -0,0 +1,27 @@
1
+ module VCFB
2
+ module Component
3
+ class Base < VCFB.parent_component.constantize
4
+ extend ActiveModel::Callbacks
5
+
6
+ # Define initialize callback to reduce need to override the initialize
7
+ # method on form components.
8
+ define_model_callbacks :initialize
9
+
10
+ # Work around ViewComponent not having access helpers we need via
11
+ # ActionText. For more information, see:
12
+ # https://github.com/github/view_component/blob/main/docs/compatibility.md#actiontext
13
+ delegate :rich_text_area_tag, to: :helpers
14
+
15
+ # Override the built-in methods to allow us to render custom collection
16
+ # tag builders that render using labels, check boxes, and radio buttons
17
+ # via components.
18
+ def collection_check_boxes(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
19
+ VCFB::Tags::CollectionCheckBoxes.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block)
20
+ end
21
+
22
+ def collection_radio_buttons(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
23
+ VCFB::Tags::CollectionRadioButtons.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ module VCFB
2
+ module Component
3
+ class BaseCollection < Base
4
+ private
5
+
6
+ def content
7
+ @__vc_content = if @view_context && @__vc_render_in_block
8
+ view_context.capture(@builder, &@__vc_render_in_block)
9
+ else
10
+ default_content
11
+ end
12
+ super()
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class Button < Base
4
+ def initialize(form, text = nil, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @text = text
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {}, &block)
13
+ button_tag(options, &block)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module VCFB
2
+ module Component
3
+ class CheckBox < Base
4
+ def initialize(form, method, options = {}, checked_value = "1", unchecked_value = "0")
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ @checked_value = checked_value
10
+ @unchecked_value = unchecked_value
11
+ end
12
+ end
13
+
14
+ def form_element(options = {})
15
+ check_box(@form.object_name, @method, options, @checked_value, @unchecked_value)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,36 @@
1
+ module VCFB
2
+ module Component
3
+ class CollectionCheckBoxes < BaseCollection
4
+ def initialize(form, method, collection, value_method, text_method, options = {}, html_options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @collection = collection
9
+ @value_method = value_method
10
+ @text_method = text_method
11
+ @options = options
12
+ @html_options = html_options
13
+ end
14
+ end
15
+
16
+ # The form element #collection_check_boxes yields a special builder that
17
+ # can be used to define a template to render each checkbox. We yield that
18
+ # builder here and override the ViewComponent #content method (see
19
+ # BaseCollection) to support render these elements using components.
20
+ def form_element(options = {}, html_options = {}, &block)
21
+ collection_check_boxes(@form.object_name, @method, @collection, @value_method, @text_method, options, html_options) do |builder|
22
+ @builder = builder
23
+ block&.call(@builder)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ # Define the default content / template to use if a block is not passed
30
+ # when calling #collection_check_boxes
31
+ def default_content
32
+ @builder.check_box + @builder.label
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ module VCFB
2
+ module Component
3
+ class CollectionRadioButtons < BaseCollection
4
+ def initialize(form, method, collection, value_method, text_method, options = {}, html_options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @collection = collection
9
+ @value_method = value_method
10
+ @text_method = text_method
11
+ @options = options
12
+ @html_options = html_options
13
+ end
14
+ end
15
+
16
+ # The form element #collection_radio_buttons yields a special builder that
17
+ # can be used to define a template to render each radio button. We yield
18
+ # that builder here and override the ViewComponent #content method (see
19
+ # BaseCollection) to support render these elements using components.
20
+ def form_element(options = {}, html_options = {}, &block)
21
+ collection_radio_buttons(@form.object_name, @method, @collection, @value_method, @text_method, options, html_options) do |builder|
22
+ @builder = builder
23
+ block&.call(@builder)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ # Define the default content / template to use if a block is not passed
30
+ # when calling #collection_radio_buttons
31
+ def default_content
32
+ @builder.radio_button + @builder.label
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ module VCFB
2
+ module Component
3
+ class CollectionSelect < Base
4
+ def initialize(form, method, collection, value_method, text_method, options = {}, html_options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @collection = collection
9
+ @value_method = value_method
10
+ @text_method = text_method
11
+ @options = options
12
+ @html_options = html_options
13
+ end
14
+ end
15
+
16
+ def form_element(options = {}, html_options = {})
17
+ collection_select(@form.object_name, @method, @collection, @value_method, @text_method, options, html_options)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class ColorField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ color_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class DateField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ date_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module VCFB
2
+ module Component
3
+ class DateSelect < Base
4
+ def initialize(form, method, options = {}, html_options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ @html_options = html_options
10
+ end
11
+ end
12
+
13
+ def form_element(options = {}, html_options = {})
14
+ date_select(@form.object_name, @method, options, html_options)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class DatetimeField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ datetime_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module VCFB
2
+ module Component
3
+ class DatetimeSelect < Base
4
+ def initialize(form, method, options = {}, html_options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ @html_options = html_options
10
+ end
11
+ end
12
+
13
+ def form_element(options = {}, html_options = {})
14
+ datetime_select(@form.object_name, @method, options, html_options)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class EmailField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ email_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class FileField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ file_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ module VCFB
2
+ module Component
3
+ class Form < Base
4
+ def initialize(model: nil, scope: nil, url: nil, format: nil, **options)
5
+ run_callbacks :initialize do
6
+ @model = model
7
+ @scope = scope
8
+ @url = url
9
+ @format = format
10
+ @options = options
11
+ @form = nil
12
+ end
13
+ end
14
+
15
+ # Because we've overridden the #content and #get_slot methods below to
16
+ # support yielding the form, we need to save the component to our custom
17
+ # form builder to support rendering slots in the form components.
18
+ def form_tag(options = {}, &block)
19
+ form_with(model: @model, scope: @scope, url: @url, format: @format, **options) do |form|
20
+ form.form_component = self if form.respond_to?(:form_component=)
21
+ @form = form
22
+ block&.call(@form)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ private
29
+
30
+ # Override #content and #get_slot from ViewComponent so that we can yield
31
+ # the form element (and not the component).
32
+ def content
33
+ if @view_context && @__vc_render_in_block
34
+ @__vc_content = view_context.capture(@form, &@__vc_render_in_block)
35
+ end
36
+ super()
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,23 @@
1
+ module VCFB
2
+ module Component
3
+ class GroupedCollectionSelect < Base
4
+ def initialize(form, method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @collection = collection
9
+ @group_method = group_method
10
+ @group_label_method = group_label_method
11
+ @option_key_method = option_key_method
12
+ @option_value_method = option_value_method
13
+ @options = options
14
+ @html_options = html_options
15
+ end
16
+ end
17
+
18
+ def form_element(options = {}, html_options = {})
19
+ grouped_collection_select(@form.object_name, @method, @collection, @group_method, @group_label_method, @option_key_method, @option_value_method, options, html_options)
20
+ end
21
+ end
22
+ end
23
+ end