headmin 0.3.3 → 0.4.1

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 (160) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +27 -0
  3. data/.gitignore +14 -0
  4. data/.nvmrc +1 -0
  5. data/CHANGELOG.md +24 -0
  6. data/Gemfile +7 -4
  7. data/Gemfile.lock +171 -3
  8. data/README.md +9 -1
  9. data/Rakefile +1 -7
  10. data/app/assets/javascripts/headmin/config/i18n.js +9 -9
  11. data/app/assets/javascripts/headmin/controllers/autocomplete_controller.js +318 -0
  12. data/app/assets/javascripts/headmin/controllers/blocks_controller.js +74 -79
  13. data/app/assets/javascripts/headmin/controllers/date_range_controller.js +24 -24
  14. data/app/assets/javascripts/headmin/controllers/dropzone_controller.js +23 -25
  15. data/app/assets/javascripts/headmin/controllers/file_preview_controller.js +237 -237
  16. data/app/assets/javascripts/headmin/controllers/filter_controller.js +44 -44
  17. data/app/assets/javascripts/headmin/controllers/filters_controller.js +57 -61
  18. data/app/assets/javascripts/headmin/controllers/flatpickr_controller.js +29 -29
  19. data/app/assets/javascripts/headmin/controllers/hello_controller.js +3 -3
  20. data/app/assets/javascripts/headmin/controllers/notification_controller.js +7 -6
  21. data/app/assets/javascripts/headmin/controllers/popup_controller.js +57 -51
  22. data/app/assets/javascripts/headmin/controllers/redactorx_controller.js +36 -9
  23. data/app/assets/javascripts/headmin/controllers/repeater_controller.js +122 -125
  24. data/app/assets/javascripts/headmin/controllers/select_controller.js +40 -39
  25. data/app/assets/javascripts/headmin/controllers/table_actions_controller.js +88 -77
  26. data/app/assets/javascripts/headmin/controllers/table_controller.js +115 -116
  27. data/app/assets/javascripts/headmin/index.js +38 -35
  28. data/app/assets/javascripts/headmin.js +309 -42
  29. data/app/assets/stylesheets/headmin/forms/autocomplete.scss +21 -0
  30. data/app/assets/stylesheets/headmin/forms/file.scss +46 -0
  31. data/app/assets/stylesheets/headmin/forms/repeater.scss +62 -0
  32. data/app/assets/stylesheets/headmin/forms/search.scss +12 -0
  33. data/app/assets/stylesheets/headmin/forms.scss +11 -0
  34. data/app/assets/stylesheets/headmin/general.scss +14 -0
  35. data/app/assets/stylesheets/headmin/overrides/bootstrap.scss +5 -3
  36. data/app/assets/stylesheets/headmin/overrides/redactorx.scss +74 -0
  37. data/app/assets/stylesheets/headmin/popup.scss +1 -0
  38. data/app/assets/stylesheets/headmin/syntax.scss +36 -349
  39. data/app/assets/stylesheets/headmin/table.scss +1 -1
  40. data/app/assets/stylesheets/headmin/utilities/buttons.scss +19 -0
  41. data/app/assets/stylesheets/headmin/utilities/dropzone.scss +72 -0
  42. data/app/assets/stylesheets/headmin/utilities.scss +2 -68
  43. data/app/assets/stylesheets/headmin.css +209 -205
  44. data/app/assets/stylesheets/headmin.scss +1 -1
  45. data/app/helpers/headmin/admin_helper.rb +0 -1
  46. data/app/helpers/headmin/form_helper.rb +2 -8
  47. data/app/models/concerns/headmin/blockable.rb +1 -1
  48. data/app/models/concerns/headmin/field.rb +1 -0
  49. data/app/models/concerns/headmin/form/autocompletable.rb +38 -0
  50. data/app/models/concerns/headmin/form/hintable.rb +19 -0
  51. data/app/models/concerns/headmin/form/input_groupable.rb +23 -0
  52. data/app/models/concerns/headmin/form/labelable.rb +33 -0
  53. data/app/models/concerns/headmin/form/listable.rb +28 -0
  54. data/app/models/concerns/headmin/form/placeholderable.rb +13 -0
  55. data/app/models/concerns/headmin/form/validatable.rb +40 -0
  56. data/app/models/concerns/headmin/form/wrappable.rb +21 -0
  57. data/app/models/headmin/.DS_Store +0 -0
  58. data/app/models/headmin/blocks_view.rb +15 -0
  59. data/app/models/headmin/form/blocks_view.rb +29 -0
  60. data/app/models/headmin/form/checkbox_view.rb +52 -0
  61. data/app/models/headmin/form/date_range_view.rb +25 -0
  62. data/app/models/headmin/form/date_view.rb +45 -0
  63. data/app/models/headmin/form/email_view.rb +48 -0
  64. data/app/models/headmin/form/file_view.rb +116 -0
  65. data/app/models/headmin/form/flatpickr_range_view.rb +102 -0
  66. data/app/models/headmin/form/flatpickr_view.rb +37 -0
  67. data/app/models/headmin/form/hidden_view.rb +10 -0
  68. data/app/models/headmin/form/hint_view.rb +6 -0
  69. data/app/models/headmin/form/input_group_view.rb +19 -0
  70. data/app/models/headmin/form/label_view.rb +24 -0
  71. data/app/models/headmin/form/number_view.rb +49 -0
  72. data/app/models/headmin/form/password_view.rb +44 -0
  73. data/app/models/headmin/form/redactorx_view.rb +59 -0
  74. data/app/models/headmin/form/search_view.rb +48 -0
  75. data/app/models/headmin/form/select_view.rb +62 -0
  76. data/app/models/headmin/form/switch_view.rb +23 -0
  77. data/app/models/headmin/form/text_view.rb +48 -0
  78. data/app/models/headmin/form/textarea_view.rb +44 -0
  79. data/app/models/headmin/form/url_view.rb +48 -0
  80. data/app/models/headmin/form/wrapper_view.rb +19 -0
  81. data/app/models/headmin/form/wysiwyg_view.rb +17 -0
  82. data/app/models/headmin/{thumbnail.rb → thumbnail_view.rb} +6 -1
  83. data/app/models/view_model.rb +58 -0
  84. data/app/views/headmin/_blocks.html.erb +13 -9
  85. data/app/views/headmin/_heading.html.erb +7 -1
  86. data/app/views/headmin/_thumbnail.html.erb +1 -37
  87. data/app/views/headmin/forms/_autocomplete.html.erb +11 -0
  88. data/app/views/headmin/forms/_blocks.html.erb +16 -17
  89. data/app/views/headmin/forms/_checkbox.html.erb +24 -29
  90. data/app/views/headmin/forms/_datalist.html.erb +3 -0
  91. data/app/views/headmin/forms/_date.html.erb +24 -24
  92. data/app/views/headmin/forms/_date_range.html.erb +19 -21
  93. data/app/views/headmin/forms/_email.html.erb +27 -32
  94. data/app/views/headmin/forms/_errors.html.erb +2 -3
  95. data/app/views/headmin/forms/_file.html.erb +84 -181
  96. data/app/views/headmin/forms/_flatpickr.html.erb +19 -20
  97. data/app/views/headmin/forms/_flatpickr_range.html.erb +28 -37
  98. data/app/views/headmin/forms/_hidden.html.erb +9 -10
  99. data/app/views/headmin/forms/_hint.html.erb +16 -0
  100. data/app/views/headmin/forms/_input_group.html.erb +21 -0
  101. data/app/views/headmin/forms/_label.html.erb +5 -13
  102. data/app/views/headmin/forms/_number.html.erb +23 -35
  103. data/app/views/headmin/forms/_password.html.erb +21 -30
  104. data/app/views/headmin/forms/_redactorx.html.erb +21 -40
  105. data/app/views/headmin/forms/_repeater.html.erb +55 -60
  106. data/app/views/headmin/forms/_search.html.erb +43 -0
  107. data/app/views/headmin/forms/_select.html.erb +24 -49
  108. data/app/views/headmin/forms/_switch.html.erb +29 -0
  109. data/app/views/headmin/forms/_text.html.erb +42 -96
  110. data/app/views/headmin/forms/_textarea.html.erb +21 -32
  111. data/app/views/headmin/forms/_url.html.erb +26 -31
  112. data/app/views/headmin/forms/_validation.html.erb +10 -13
  113. data/app/views/headmin/forms/_wrapper.html.erb +9 -0
  114. data/app/views/headmin/forms/_wysiwyg.html.erb +28 -0
  115. data/app/views/headmin/forms/autocomplete/_item.html.erb +3 -0
  116. data/app/views/headmin/forms/autocomplete/_list.html.erb +3 -0
  117. data/app/views/headmin/forms/fields/_group.html.erb +9 -2
  118. data/app/views/headmin/forms/repeater/_row.html.erb +4 -4
  119. data/app/views/headmin/table/_actions.html.erb +1 -1
  120. data/app/views/headmin/table/actions/_action.html.erb +2 -1
  121. data/app/views/headmin/table/actions/_delete.html.erb +1 -1
  122. data/bin/console +0 -1
  123. data/config/locales/headmin/forms/en.yml +1 -12
  124. data/config/locales/headmin/forms/nl.yml +1 -12
  125. data/esbuild-css.js +18 -18
  126. data/esbuild-js.js +8 -8
  127. data/headmin.gemspec +1 -3
  128. data/lib/generators/templates/controllers/auth/confirmations_controller.rb +0 -2
  129. data/lib/generators/templates/controllers/auth/omniauth_callbacks_controller.rb +0 -2
  130. data/lib/generators/templates/controllers/auth/passwords_controller.rb +0 -2
  131. data/lib/generators/templates/controllers/auth/registrations_controller.rb +0 -2
  132. data/lib/generators/templates/controllers/auth/sessions_controller.rb +0 -2
  133. data/lib/generators/templates/controllers/auth/unlocks_controller.rb +0 -2
  134. data/lib/headmin/version.rb +1 -3
  135. data/lib/headmin.rb +0 -2
  136. data/package-lock.json +5359 -0
  137. data/package.json +13 -6
  138. data/view_model_benchmark.rb +74 -0
  139. data/yarn-error.log +367 -0
  140. data/yarn.lock +1575 -31
  141. metadata +63 -24
  142. data/app/assets/stylesheets/headmin/form.scss +0 -132
  143. data/app/assets/stylesheets/headmin/overrides/redactorx.css +0 -3
  144. data/app/helpers/headmin/documentation_helper.rb +0 -35
  145. data/app/models/headmin/documentation_renderer.rb +0 -32
  146. data/app/models/headmin/form/base.rb +0 -78
  147. data/app/models/headmin/form/text.rb +0 -51
  148. data/app/services/block_service.rb +0 -72
  149. data/app/views/headmin/_card.html.erb +0 -52
  150. data/app/views/headmin/forms/_actions.html.erb +0 -28
  151. data/app/views/headmin/forms/_base.html.erb +0 -114
  152. data/app/views/headmin/forms/_image.html.erb +0 -21
  153. data/app/views/headmin/forms/_video.html.erb +0 -21
  154. data/app/views/headmin/forms/actions/_destroy.html.erb +0 -13
  155. data/app/views/headmin/forms/actions/_save.html.erb +0 -12
  156. data/app/views/headmin/forms/actions/_view.html.erb +0 -15
  157. data/docs/blocks-and-fields.md +0 -54
  158. data/docs/blocks.md +0 -48
  159. data/docs/devise.md +0 -41
  160. data/docs/fields.md +0 -79
@@ -3,48 +3,39 @@
3
3
  #
4
4
  # ==== Required parameters
5
5
  # * +form+ - Form object
6
- # * +start_attribute+ - Name of the start date attribute of the form model
7
- # * +end_attribute+ - Name of the end date attribute of the form model
6
+ # * +start+ - Hash with all options for the start date input (:attribute is required)
7
+ # * +end+ - Hash with all options for the end date input (:attribute is required)
8
8
  #
9
9
  # ==== Optional parameters
10
- # * +aria+ - Provide a hash to define all aria attributes
11
- # * +data+ - Optional HTML data attributes
12
- # * +disabled+ - Set to true if the input should be shown as disabled
13
- # * +end_label+ - Label for the end attribute
14
- # * +label+ - Text to show as label. Label will be hidden if value is false
15
- # * +readonly+ - Set to true if the value of the field can only be read and not be modified
16
- # * +start_label+ - Label for the start attribute
17
- # * +value+ - Overrides the value of the form
18
- #
19
- # ==== Extra parameters
20
- # Listed in 'headmin/forms/base'
10
+ # * +append+ - Display as input group with text on the right-hand side
11
+ # * +float+ - Use floating labels. Defaults to false
12
+ # * +flatpickr+ - Hash with all options you can pass to flatpickr JS config
13
+ # * +hint+ - Informative text to assist with data input. HTML markup is allowed.
14
+ # * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
15
+ # * +list+ - Options are passed through options_for_select
16
+ # * +plaintext+ - Render input as plain text.
17
+ # * +prepend+ - Display as input group with text on the left-hand side
18
+ # * +wrapper+ - Hash with all options for the surrounding html tag
21
19
  #
22
20
  # ==== Examples
23
21
  # Basic version
24
- # <%= render 'headmin/forms/flatpickr_range', form: form, start_attribute: :start_date, end_attribute: :end_date %#>
22
+ # <%= form_with do |form| %#>
23
+ # <%= render 'headmin/forms/flatpickr_range', form: form, start: {attribute: :start_date}, end: {attribute: :end_date} %#>
24
+ # <% end %#>
25
25
 
26
- start_attribute = local_assigns[:start_attribute]
27
- end_attribute = local_assigns[:end_attribute]
28
- options = local_assigns.merge(
29
- attribute: local_assigns[:attribute] || :period,
30
- data: {
31
- action: 'change->date-range#update',
32
- 'flatpickr-target': 'input',
33
- 'flatpickr-options': {
34
- mode: 'range',
35
- defaultDate: [
36
- form.object&.send(start_attribute)&.strftime('%d/%m/%Y'),
37
- form.object&.send(end_attribute)&.strftime('%d/%m/%Y'),
38
- ]
39
- }
40
- }
41
- )
26
+ flatpickr_range = Headmin::Form::FlatpickrRangeView.new(local_assigns)
42
27
  %>
43
28
 
44
- <div data-controller="flatpickr">
45
- <div data-controller="date-range">
46
- <%= render 'headmin/forms/hidden', form: form, attribute: start_attribute, data: { 'date-range-target': 'startDateInput' } %>
47
- <%= render 'headmin/forms/hidden', form: form, attribute: end_attribute, data: { 'date-range-target': 'endDateInput' } %>
48
- <%= render 'headmin/forms/date', options %>
49
- </div>
50
- </div>
29
+ <%= render "headmin/forms/wrapper", flatpickr_range.wrapper_options do %>
30
+ <%= form.hidden_field(flatpickr_range.start[:attribute], flatpickr_range.start_options) %>
31
+ <%= form.hidden_field(flatpickr_range.end[:attribute], flatpickr_range.end_options) %>
32
+
33
+ <%= render "headmin/forms/label", flatpickr_range.label_options if flatpickr_range.prepend_label? %>
34
+ <%= render "headmin/forms/input_group", flatpickr_range.input_group_options do %>
35
+ <%= form.date_field(flatpickr_range.attribute, flatpickr_range.input_options) %>
36
+ <% end %>
37
+ <%= render "headmin/forms/validation", flatpickr_range.validation_options if flatpickr_range.validate? %>
38
+ <%= render "headmin/forms/hint", flatpickr_range.hint_options if flatpickr_range.hint? %>
39
+ <%= render "headmin/forms/datalist", flatpickr_range.datalist_options if flatpickr_range.datalist? %>
40
+ <%= render "headmin/forms/label", flatpickr_range.label_options if flatpickr_range.append_label? %>
41
+ <% end %>
@@ -2,23 +2,22 @@
2
2
  # headmin/forms/hidden
3
3
  #
4
4
  # ==== Required parameters
5
- # * +form+ - Form object
6
5
  # * +attribute+ - Name of the attribute of the form model
7
- #
8
- # ==== Optional parameters
9
- # * +autocomplete+ - Value to be autofilled by the browser
10
- # * +data+ - Optional HTML data attributes
6
+ # * +form+ - Form object
11
7
  #
12
8
  # ==== References
9
+ # https://headmin.dev/docs/forms/hidden
13
10
  # https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/hidden
14
- # https://apidock.com/rails/ActionView/Helpers/FormHelper/text_field
11
+ # https://apidock.com/rails/ActionView/Helpers/FormHelper/hidden_field
15
12
  #
16
13
  # ==== Examples
17
14
  # Basic version
18
- # <%= render 'headmin/forms/hidden', form: form, attribute: :title %#>
15
+ # <%= form_with do |form| %#>
16
+ # <%= render "headmin/forms/hidden", form: form, attribute: :id %#>
17
+ # <% end %#>
19
18
 
20
- option_keys = %i(autocomplete data)
21
- options = local_assigns.slice(*option_keys)
19
+ hidden = Headmin::Form::HiddenView.new(local_assigns)
22
20
  %>
23
21
 
24
- <%= form.hidden_field(attribute, options) %>
22
+ <%= form.hidden_field(attribute, hidden.input_options) %>
23
+
@@ -0,0 +1,16 @@
1
+ <%
2
+ # headmin/forms/hint
3
+ #
4
+ # ==== Required parameters
5
+ # * +content+ - Content to be displayed as input hint
6
+ #
7
+ # ==== Examples
8
+ # Basic version
9
+ # <%= form_with do |form| %#>
10
+ # <%= render "headmin/forms/hint", content: "Hello" %#>
11
+ # <% end %#>
12
+
13
+ hint = Headmin::Form::HintView.new(local_assigns)
14
+ %>
15
+
16
+ <div class="form-text"><%= raw(hint.content) %></div>
@@ -0,0 +1,21 @@
1
+ <% input_group = Headmin::Form::InputGroupView.new(local_assigns) %>
2
+
3
+ <% if input_group.bypass %>
4
+ <%= yield %>
5
+ <% else %>
6
+ <div <%= tag.attributes(input_group.options) %>>
7
+ <% if input_group.prepend %>
8
+ <span class="input-group-text">
9
+ <%= input_group.prepend %>
10
+ </span>
11
+ <% end %>
12
+
13
+ <%= yield %>
14
+
15
+ <% if input_group.append %>
16
+ <span class="input-group-text">
17
+ <%= input_group.append %>
18
+ </span>
19
+ <% end %>
20
+ </div>
21
+ <% end %>
@@ -5,26 +5,18 @@
5
5
  # * +form+ - Form object
6
6
  # * +attribute+ - Name of the attribute of the form model
7
7
  #
8
- # ==== Options
9
- # * +class+ - Optional HTML class attribute
10
- # * +for+ - Set reference to the input id
11
- # * +required+ - Set to true if you want to highlight the requirement
8
+ # ==== Optional parameters
12
9
  # * +text+ - Custom label to be used instead of the attribute
13
10
  #
14
11
  # ==== References
12
+ # https://headmin.dev/docs/forms/label
15
13
  # https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label
16
- # https://apidock.com/rails/v5.2.3/ActionView/Helpers/FormHelper/label
14
+ # https://apidock.com/rails/ActionView/Helpers/FormHelper/label
17
15
  #
18
16
  # ==== Examples
19
17
  # Basic version
20
18
  # <%= render 'headmin/forms/label', form: form, attribute: :image %#>
21
-
22
- text = local_assigns[:text]
23
- default_options = {
24
- class: ['form-label', local_assigns[:class]].join(' '),
25
- form: form.options[:id],
26
- }
27
- options = default_options.merge(local_assigns.slice(*%i(for required)).compact)
28
19
  %>
29
20
 
30
- <%= form.label attribute, text, options %>
21
+ <% label = Headmin::Form::LabelView.new(local_assigns) %>
22
+ <%= form.label label.attribute, label.text, label.options %>
@@ -2,52 +2,40 @@
2
2
  # headmin/forms/number
3
3
  #
4
4
  # ==== Required parameters
5
- # * +form+ - Form object
6
5
  # * +attribute+ - Name of the attribute of the form model
6
+ # * +form+ - Form object
7
7
  #
8
8
  # ==== Optional parameters
9
- # * +aria+ - Provide a hash to define all aria attributes
10
- # * +autocomplete+ - Value to be autofilled by the browser
11
- # * +autofocus+ - Set to true to focus on this field when the page renders
12
- # * +data+ - Provide a hash to define all data attributes
13
- # * +disabled+ - Sets the placeholder of the field
14
- # * +id+ - Input identifier
15
- # * +in+ - Range specifying the +min+ and +max+ values
16
- # * +list+ - Add array of options to show in a data list
17
- # * +max+ - The maximum acceptable value
18
- # * +min+ - The minimum acceptable value
19
- # * +placeholder+ - Sets the placeholder of the field
20
- # * +readonly+ - Sets the placeholder of the field
21
- # * +required+ - Set to true to mark as required
22
- # * +step+ - The acceptable value granularity
23
- # * +value+ - Overrides the value of the form
24
- # * +within+ - Same as +in+
25
- #
26
- # ==== Extra parameters
27
- # Listed in 'headmin/forms/base'
9
+ # * +append+ - Display as input group with text on the right-hand side
10
+ # * +float+ - Use floating labels. Defaults to false
11
+ # * +hint+ - Informative text to assist with data input. HTML markup is allowed.
12
+ # * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
13
+ # * +list+ - Options are passed through options_for_select
14
+ # * +plaintext+ - Render input as plain text.
15
+ # * +prepend+ - Display as input group with text on the left-hand side
16
+ # * +wrapper+ - Hash with all options for the surrounding html tag
28
17
  #
29
18
  # ==== References
19
+ # https://headmin.dev/docs/forms/number
30
20
  # https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number
31
21
  # https://apidock.com/rails/ActionView/Helpers/FormHelper/number_field
32
22
  #
33
23
  # ==== Examples
34
24
  # Basic version
35
- # <%= render 'headmin/forms/number', form: form, attribute: :amount %#>
36
- #
37
- # With data-list
38
- # <%= render 'headmin/forms/number', form: form, attribute: :amount, list: [2,4,6,8,10] %#>
39
-
40
- placeholder = local_assigns[:float] ? local_assigns[:placeholder] || attribute : local_assigns[:placeholder]
25
+ # <%= form_with do |form| %#>
26
+ # <%= render "headmin/forms/number", form: form, attribute: :number %#>
27
+ # <% end %#>
41
28
 
42
- option_keys = %i(aria autocomplete autofocus data disabled id in list max min placeholder readonly required step value within)
43
- options = local_assigns.slice(*option_keys).merge(
44
- aria: { describedby: form_field_validation_id(form, attribute) },
45
- class: ['form-control', form_field_validation_class(form, attribute)].join(' '),
46
- list: local_assigns[:list] ? "#{attribute}_list" : nil,
47
- placeholder: placeholder
48
- )
29
+ number = Headmin::Form::NumberView.new(local_assigns)
49
30
  %>
50
31
 
51
- <%= render 'headmin/forms/base', local_assigns do |form| %>
52
- <%= form.number_field(attribute, options) %>
32
+ <%= render "headmin/forms/wrapper", number.wrapper_options do %>
33
+ <%= render "headmin/forms/label", number.label_options if number.prepend_label? %>
34
+ <%= render "headmin/forms/input_group", number.input_group_options do %>
35
+ <%= form.number_field(number.attribute, number.input_options) %>
36
+ <%= render "headmin/forms/datalist", number.datalist_options if number.datalist? %>
37
+ <% end %>
38
+ <%= render "headmin/forms/validation", number.validation_options if number.validate? %>
39
+ <%= render "headmin/forms/hint", number.hint_options if number.hint? %>
40
+ <%= render "headmin/forms/label", number.label_options if number.append_label? %>
53
41
  <% end %>
@@ -2,47 +2,38 @@
2
2
  # headmin/forms/password
3
3
  #
4
4
  # ==== Required parameters
5
- # * +form+ - Form object
6
5
  # * +attribute+ - Name of the attribute of the form model
6
+ # * +form+ - Form object
7
7
  #
8
8
  # ==== Optional parameters
9
- # * +aria+ - Provide a hash to define all aria attributes
10
- # * +autocomplete+ - Value to be autofilled by the browser
11
- # * +autofocus+ - Set to true to focus on this field when the page renders
12
- # * +data+ - Provide a hash to define all data attributes
13
- # * +disabled+ - Sets the placeholder of the field
14
- # * +id+ - Input identifier
15
- # * +list+ - Add array of options to show in a data list
16
- # * +maxlength+ - The maximum number of characters that the browser will allow the user to enter.
17
- # * +minlength+ - The minimum number of characters that the browser will allow the user to enter.
18
- # * +placeholder+ - Sets the placeholder of the field
19
- # * +readonly+ - Sets the placeholder of the field
20
- # * +required+ - Set to true to mark as required
21
- # * +size+ - The number of visible characters that will fit in the input
22
- # * +value+ - Overrides the value of the form
23
- #
24
- # ==== Extra parameters
25
- # Listed in 'headmin/forms/base'
9
+ # * +append+ - Display as input group with text on the right-hand side
10
+ # * +float+ - Use floating labels. Defaults to false
11
+ # * +hint+ - Informative text to assist with data input. HTML markup is allowed.
12
+ # * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
13
+ # * +plaintext+ - Render input as plain text.
14
+ # * +prepend+ - Display as input group with text on the left-hand side
15
+ # * +wrapper+ - Hash with all options for the surrounding html tag
26
16
  #
27
17
  # ==== References
18
+ # https://headmin.dev/docs/forms/password
28
19
  # https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/password
29
20
  # https://apidock.com/rails/ActionView/Helpers/FormHelper/password_field
30
21
  #
31
22
  # ==== Examples
32
23
  # Basic version
33
- # <%= render 'headmin/forms/password', form: form, attribute: :password %#>
34
-
35
- placeholder = local_assigns[:float] ? local_assigns[:placeholder] || attribute : local_assigns[:placeholder]
24
+ # <%= form_with do |form| %#>
25
+ # <%= render "headmin/forms/password", form: form, attribute: :password %#>
26
+ # <% end %#>
36
27
 
37
- option_keys = %i(aria autocomplete autofocus data disabled id list maxlength minlength placeholder readonly required size value)
38
- options = local_assigns.slice(*option_keys).merge(
39
- autocomplete: true,
40
- aria: { describedby: form_field_validation_id(form, attribute) },
41
- class: ['form-control', form_field_validation_class(form, attribute)].join(' '),
42
- placeholder: placeholder
43
- )
28
+ password = Headmin::Form::PasswordView.new(local_assigns)
44
29
  %>
45
30
 
46
- <%= render 'headmin/forms/base', local_assigns do |form| %>
47
- <%= form.password_field(attribute, options) %>
31
+ <%= render "headmin/forms/wrapper", password.wrapper_options do %>
32
+ <%= render "headmin/forms/label", password.label_options if password.prepend_label? %>
33
+ <%= render "headmin/forms/input_group", password.input_group_options do %>
34
+ <%= form.password_field(password.attribute, password.input_options) %>
35
+ <% end %>
36
+ <%= render "headmin/forms/validation", password.validation_options if password.validate? %>
37
+ <%= render "headmin/forms/hint", password.hint_options if password.hint? %>
38
+ <%= render "headmin/forms/label", password.label_options if password.append_label? %>
48
39
  <% end %>
@@ -1,50 +1,31 @@
1
1
  <%
2
2
  # headmin/forms/redactorx
3
3
  #
4
- # ==== Options
5
- # * +form+ - Form object
4
+ # ==== Required parameters
6
5
  # * +attribute+ - Name of the attribute of the form model
7
- # * +label+ - Text to show as label. Label will be hidden if value is false
8
- # * +addbar+ - Items to show in the addbar
9
- # * +topbar+ - Items to show in the topbar
10
- # * +plugins+ - Plugin items to work with
6
+ # * +form+ - Form object
7
+ #
8
+ # ==== Optional parameters
9
+ # * +append+ - Display as input group with text on the right-hand side
10
+ # * +hint+ - Informative text to assist with data input. HTML markup is allowed.
11
+ # * +hybrid+ - Enables hybrid mode when set to true (default = false)
12
+ # * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
13
+ # * +prepend+ - Display as input group with text on the left-hand side
14
+ # * +redactor+ - Hash with all options you can pass to redactor JS config
15
+ # * +wrapper+ - Hash with all options for the surrounding html tag
16
+ #
17
+ # ==== References
18
+ # https://headmin.dev/docs/forms/redactorx
19
+ # https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea
20
+ # https://apidock.com/rails/ActionView/Helpers/FormHelper/text_area
11
21
  #
12
22
  # ==== Examples
13
23
  # Basic version
14
- # <%= render 'headmin/forms/redactorx', form: form, attribute: :title %#>
15
-
16
- class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
17
- data = local_assigns.has_key?(:data) ? data : {}
18
- disabled = local_assigns.has_key?(:disabled) ? disabled : false
19
- label = local_assigns.has_key?(:label) ? label : nil
20
- readonly = local_assigns.has_key?(:readonly) ? readonly : false
21
- required = local_assigns.has_key?(:required) ? required : false
22
- addbar = local_assigns.has_key?(:addbar) ? addbar : ['paragraph', 'image', 'embed', 'table', 'quote', 'pre', 'line']
23
- plugins = local_assigns.has_key?(:plugins) ? plugins : ['shortcut']
24
- topbar = local_assigns.has_key?(:topbar) ? topbar : []
25
-
26
- data = data.merge(
27
- controller: 'redactorx',
28
- 'redactor-options': {
29
- buttons: {
30
- addbar: addbar,
31
- plugins: plugins,
32
- topbar: topbar,
33
- }
34
- }
35
- )
24
+ # <%= form_with do |form| %#>
25
+ # <%= render "headmin/forms/redactorx", form: form, attribute: :text %#>
26
+ # <% end %#>
36
27
 
37
- options = {
38
- 'aria-describedby': form_field_validation_id(form, attribute),
39
- class: "form-control redactorx #{form_field_validation_class(form, attribute)} #{class_names}",
40
- data: data,
41
- disabled: disabled,
42
- placeholder: attribute,
43
- readonly: readonly,
44
- required: required,
45
- }
28
+ redactor = Headmin::Form::RedactorxView.new(local_assigns)
46
29
  %>
47
30
 
48
- <%= render 'headmin/forms/base', form: form, attribute: attribute, label: label, required: required do |form| %>
49
- <%= form.text_area(attribute, options) %>
50
- <% end %>
31
+ <%= render "headmin/forms/textarea", redactor.options %>
@@ -26,7 +26,7 @@
26
26
  # <% end %#>
27
27
  #
28
28
  # # Allow more than one type of fields to be inserted. You must specify the templates as an array of view paths
29
- # <% templates = ['admin/questions/fields/_type_1.html.erb', 'admin/questions/fields/_type_2.html.erb'] %#>
29
+ # <% templates = ['admin/questions/fields/type_1', 'admin/questions/fields/type_2'] %#>
30
30
  # <% render 'headmin/forms/repeater', form: form, attribute: :questions, templates: templates do |question| %#>
31
31
  # <% render 'admin/questions/fields, form: :question' %#>
32
32
  # <% end %#>
@@ -50,80 +50,75 @@
50
50
  show_label = label != false
51
51
  %>
52
52
 
53
- <div class="repeater" data-controller="repeater" data-repeater-id-value="<%= repeater_id %>">
53
+ <!-- Label -->
54
+ <% if show_label %>
55
+ <%= render 'headmin/forms/label', form: form, attribute: attribute, text: label, required: required %>
56
+ <% end %>
54
57
 
55
- <!-- Label -->
56
- <% if show_label %>
57
- <%= render 'headmin/forms/label', form: form, attribute: attribute, text: label, required: required %>
58
- <% end %>
59
-
60
- <ul class="list-group <%= 'list-group-flush' if flush %>" data-repeater-target="list">
58
+ <ul class="repeater list-group <%= 'list-group-flush' if flush %>" data-controller="repeater" data-repeater-target="list" data-repeater-id-value="<%= repeater_id %>">
61
59
 
62
- <!-- Header -->
63
- <% if header %>
64
- <li class="list-group-item">
65
- <%= render header %>
66
- </li>
67
- <% end %>
60
+ <!-- Header -->
61
+ <% if header %>
62
+ <li class="list-group-item">
63
+ <%= render header %>
64
+ </li>
65
+ <% end %>
68
66
 
69
- <!-- Rows -->
70
- <%= form.fields_for attribute, associations do |ff| %>
71
- <%= render 'headmin/forms/repeater/row', pass_thru: pass_thru, form: ff, repeater_id: repeater_id do %>
72
- <%= yield(ff) %>
73
- <% end %>
67
+ <!-- Rows -->
68
+ <%= form.fields_for attribute, associations do |ff| %>
69
+ <%= render 'headmin/forms/repeater/row', pass_thru: pass_thru, form: ff, repeater_id: repeater_id do %>
70
+ <%= yield(ff) %>
74
71
  <% end %>
72
+ <% end %>
75
73
 
76
- <!-- Footer -->
77
- <li class="list-group-item d-flex justify-content-between align-items-center" data-repeater-target="footer">
74
+ <!-- Footer -->
75
+ <li class="list-group-item d-flex justify-content-between align-items-center" data-repeater-target="footer">
78
76
 
79
- <!-- Empty notice -->
80
- <div class="text-secondary invisible" data-repeater-target="empty">
81
- <%= t('.empty') %>
82
- </div>
77
+ <!-- Empty notice -->
78
+ <div class="text-secondary invisible" data-repeater-target="empty">
79
+ <%= t('.empty') %>
80
+ </div>
83
81
 
84
- <!-- Button -->
85
- <a href="#"
86
- class="btn btn-sm h-btn-outline-light"
87
- data-repeater-target="addButton"
88
- data-popup-target="button"
89
- data-popup-id="<%= "repeater-buttons-#{repeater_id}" %>"
90
- data-popup-pass-thru="<%= pass_thru %>"
91
- data-action="click->repeater#resetButtonIndices click->popup#open"
92
- >
93
- <%= bootstrap_icon('plus') %>
94
- <%= t('.add', name: association_model.model_name.human) %>
95
- </a>
82
+ <!-- Button -->
83
+ <div
84
+ class="btn btn-sm h-btn-outline-light"
85
+ data-repeater-target="addButton"
86
+ data-popup-target="button"
87
+ data-popup-id="<%= "repeater-buttons-#{repeater_id}" %>"
88
+ data-popup-pass-thru="<%= pass_thru %>"
89
+ data-action="click->repeater#resetButtonIndices click->popup#open"
90
+ >
91
+ <%= bootstrap_icon('plus') %>
92
+ <%= t('.add', name: association_model.model_name.human) %>
93
+ </div>
96
94
 
97
- <!-- Popup -->
98
- <%= render 'headmin/popup', id: "repeater-buttons-#{repeater_id}" do %>
99
- <div class="d-grid gap-2">
100
- <% template_names.each do |name| %>
101
- <a href="#"
102
- class="btn btn-sm h-btn-outline-light"
103
- data-popup-target="button"
104
- data-popup-id="<%= "repeater-buttons-#{repeater_id}" %>"
105
- data-action="click->repeater#addRow click->popup#close"
106
- data-row-index=""
107
- data-template-name="<%= name %>"
108
- >
109
- <%= name.humanize %>
110
- </a>
111
- <% end %>
112
- </div>
113
- <% end %>
114
- </li>
95
+ <!-- Popup -->
96
+ <%= render 'headmin/popup', id: "repeater-buttons-#{repeater_id}" do %>
97
+ <div class="d-grid gap-2">
98
+ <% template_names.each do |name| %>
99
+ <div
100
+ class="btn btn-sm h-btn-outline-light"
101
+ data-popup-target="button"
102
+ data-popup-id="<%= "repeater-buttons-#{repeater_id}" %>"
103
+ data-action="click->repeater#addRow click->popup#close"
104
+ data-row-index=""
105
+ data-template-name="<%= name %>"
106
+ >
107
+ <%= t("blocks.#{name}", default: name).humanize %>
108
+ </div>
109
+ <% end %>
110
+ </div>
111
+ <% end %>
115
112
 
116
113
  <!-- Templates -->
117
114
  <% template_names.each do |name| %>
118
115
  <template data-repeater-target="template" data-template-name="<%= name %>" data-template-id-regex="<%= association_object.object_id %>">
119
116
  <%= form.fields_for attribute, association_object, child_index: association_object.object_id do |ff| %>
120
117
  <%= render 'headmin/forms/repeater/row', form: ff, pass_thru: pass_thru, repeater_id: repeater_id do %>
121
- <% template = templates.detect { |t| t.include?("/#{name}.") } %>
122
- <% yield(ff, template&.gsub('/_', '/')) %>
118
+ <% yield(ff, name) %>
123
119
  <% end %>
124
120
  <% end %>
125
121
  </template>
126
122
  <% end %>
127
-
128
- </ul>
129
- </div>
123
+ </li>
124
+ </ul>
@@ -0,0 +1,43 @@
1
+ <%
2
+ # headmin/forms/search
3
+ #
4
+ # ==== Required parameters
5
+ # * +attribute+ - Name of the attribute of the form model
6
+ # * +form+ - Form object
7
+ #
8
+ # ==== Optional parameters
9
+ # * +append+ - Display as input group with text on the right-hand side
10
+ # * +collection+ - Values to be suggested while typing. Can be an collection array or a remote URL.
11
+ # * +float+ - Use floating labels. Defaults to false
12
+ # * +hint+ - Informative text to assist with data input. HTML markup is allowed.
13
+ # * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
14
+ # * +list+ - Options are passed through options_for_select
15
+ # * +plaintext+ - Render input as plain text.
16
+ # * +prepend+ - Display as input group with text on the left-hand side
17
+ # * +wrapper+ - Hash with all options for the surrounding html tag
18
+ #
19
+ # ==== Documentation
20
+ # https://headmin.dev/docs/forms/search
21
+ # https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/search
22
+ # https://apidock.com/rails/ActionView/Helpers/FormHelper/search_field
23
+ #
24
+ # ==== Examples
25
+ # Basic version
26
+ # <%= form_with do |form| %#>
27
+ # <%= render "headmin/forms/search", form: form, attribute: "basic_example" %#>
28
+ # <% end %#>
29
+
30
+ search = Headmin::Form::SearchView.new(local_assigns)
31
+ %>
32
+
33
+ <%= render "headmin/forms/wrapper", search.wrapper_options do %>
34
+ <%= render "headmin/forms/label", search.label_options if search.prepend_label? %>
35
+ <%= render "headmin/forms/input_group", search.input_group_options do %>
36
+ <%= form.search_field(search.attribute, search.input_options) %>
37
+ <%= render "headmin/forms/datalist", search.datalist_options if search.datalist? %>
38
+ <%= render "headmin/forms/autocomplete", search.autocomplete_options if search.autocomplete? %>
39
+ <% end %>
40
+ <%= render "headmin/forms/validation", search.validation_options if search.validate? %>
41
+ <%= render "headmin/forms/hint", search.hint_options if search.hint? %>
42
+ <%= render "headmin/forms/label", search.label_options if search.append_label? %>
43
+ <% end %>