diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /lib/gitlab/form_builders | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'lib/gitlab/form_builders')
-rw-r--r-- | lib/gitlab/form_builders/gitlab_ui_form_builder.rb | 80 |
1 files changed, 27 insertions, 53 deletions
diff --git a/lib/gitlab/form_builders/gitlab_ui_form_builder.rb b/lib/gitlab/form_builders/gitlab_ui_form_builder.rb index e8e87a864cc..9174ca165cd 100644 --- a/lib/gitlab/form_builders/gitlab_ui_form_builder.rb +++ b/lib/gitlab/form_builders/gitlab_ui_form_builder.rb @@ -5,76 +5,50 @@ module Gitlab class GitlabUiFormBuilder < ActionView::Helpers::FormBuilder def gitlab_ui_checkbox_component( method, - label, + label = nil, help_text: nil, checkbox_options: {}, checked_value: '1', unchecked_value: '0', - label_options: {} + label_options: {}, + &block ) - @template.content_tag( - :div, - class: 'gl-form-checkbox custom-control custom-checkbox' - ) do - value = checkbox_options[:multiple] ? checked_value : nil - - @template.check_box( - @object_name, - method, - format_options(checkbox_options, ['custom-control-input']), - checked_value, - unchecked_value - ) + generic_label(method, label, label_options, help_text: help_text, value: value) - end + Pajamas::CheckboxComponent.new( + form: self, + method: method, + label: label, + help_text: help_text, + checkbox_options: format_options(checkbox_options), + checked_value: checked_value, + unchecked_value: unchecked_value, + label_options: format_options(label_options) + ).render_in(@template, &block) end def gitlab_ui_radio_component( method, value, - label, + label = nil, help_text: nil, radio_options: {}, - label_options: {} + label_options: {}, + &block ) - @template.content_tag( - :div, - class: 'gl-form-radio custom-control custom-radio' - ) do - @template.radio_button( - @object_name, - method, - value, - format_options(radio_options, ['custom-control-input']) - ) + generic_label(method, label, label_options, help_text: help_text, value: value) - end + Pajamas::RadioComponent.new( + form: self, + method: method, + value: value, + label: label, + help_text: help_text, + radio_options: format_options(radio_options), + label_options: format_options(label_options) + ).render_in(@template, &block) end private - def generic_label(method, label, label_options, help_text: nil, value: nil) - @template.label( - @object_name, method, format_options(label_options.merge({ value: value }), ['custom-control-label']) - ) do - if help_text - @template.content_tag( - :span, - label - ) + - @template.content_tag( - :p, - help_text, - class: 'help-text' - ) - else - label - end - end - end - - def format_options(options, classes) - classes << options[:class] - - objectify_options(options.merge({ class: classes.flatten.compact })) + def format_options(options) + objectify_options(options) end end end |